Skip to content

Commit

Permalink
Merge pull request #341 from Bluewind/fix-ldap-auth
Browse files Browse the repository at this point in the history
Only output ldap_tls_client_cert_file and ldap_tls_client_key_file when set
  • Loading branch information
bastelfreak authored Jul 3, 2019
2 parents 433ba31 + 80485e5 commit f70882a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
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

0 comments on commit f70882a

Please sign in to comment.