Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only output ldap_tls_client_cert_file and ldap_tls_client_key_file when set #341

Merged
merged 1 commit into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@
Boolean $ldap_tls_enable = false,
String $ldap_tls_ca_cert_file = '',
String $ldap_tls_ca_cert_dir = '',
String $ldap_tls_client_cert_file = '',
String $ldap_tls_client_key_file = '',
Optional[Stdlib::Absolutepath] $ldap_tls_client_cert_file = undef,
Optional[Stdlib::Absolutepath] $ldap_tls_client_key_file = undef,
Integer $ca_expire = 3650,
Integer $key_expire = 3650,
String $key_cn = '',
Expand Down
56 changes: 56 additions & 0 deletions spec/defines/openvpn_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,62 @@
end
end

case facts[:os]['family']
when 'Debian'
# ldap auth needs the ldap package and that is only defined for a few OSes (including debian)
context 'debian' do
context 'creating a server with ldap authentication enabled' do
let(:params) do
{
'country' => 'CO',
'province' => 'ST',
'city' => 'Some City',
'organization' => 'example.org',
'email' => '[email protected]',
'ldap_enabled' => true,
'ldap_binddn' => 'dn=foo,ou=foo,ou=com',
'ldap_bindpass' => 'ldappass123',
'ldap_tls_enable' => true,
'ldap_tls_ca_cert_file' => '/etc/ldap/ca.pem',
'ldap_tls_ca_cert_dir' => '/etc/ldap/certs'
}
end

it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').with_content(%r{^\s+TLSEnable\s+yes$}) }
it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').with_content(%r{^\s+TLSCACertFile\s+/etc/ldap/ca.pem$}) }
it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').with_content(%r{^\s+TLSCACertDir\s+/etc/ldap/certs$}) }
it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').without_content(%r{^\s+TLSCertFile.*$}) }
it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').without_content(%r{^\s+TLSKeyFile.*$}) }
end

context 'creating a server with ldap authentication enabled and using ldap client certificates' do
let(:params) do
{
'country' => 'CO',
'province' => 'ST',
'city' => 'Some City',
'organization' => 'example.org',
'email' => '[email protected]',
'ldap_enabled' => true,
'ldap_binddn' => 'dn=foo,ou=foo,ou=com',
'ldap_bindpass' => 'ldappass123',
'ldap_tls_enable' => true,
'ldap_tls_ca_cert_file' => '/etc/ldap/ca.pem',
'ldap_tls_ca_cert_dir' => '/etc/ldap/certs',
'ldap_tls_client_cert_file' => '/etc/ldap/client-cert.pem',
'ldap_tls_client_key_file' => '/etc/ldap/client-key.pem'
}
end

it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').with_content(%r{^\s+TLSEnable\s+yes$}) }
it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').with_content(%r{^\s+TLSCACertFile\s+/etc/ldap/ca.pem$}) }
it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').with_content(%r{^\s+TLSCACertDir\s+/etc/ldap/certs$}) }
it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').with_content(%r{^\s+TLSCertFile\s+/etc/ldap/client-cert.pem$}) }
it { is_expected.to contain_file('/etc/openvpn/test_server/auth/ldap.conf').with_content(%r{^\s+TLSKeyFile\s+/etc/ldap/client-key.pem$}) }
end
end
end

context 'creating a server setting all parameters' do
let(:params) do
{
Expand Down
2 changes: 2 additions & 0 deletions templates/ldap.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
TLSEnable yes
TLSCACertFile <%= @ldap_tls_ca_cert_file %>
TLSCACertDir <%= @ldap_tls_ca_cert_dir %>
<% if @ldap_tls_client_cert_file or @ldap_tls_client_key_file -%>
TLSCertFile <%= @ldap_tls_client_cert_file %>
TLSKeyFile <%= @ldap_tls_client_key_file %>
<% end -%>
<% else %>
TLSEnable no
<% end -%>
Expand Down