-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve consistency of class pureftpd::config* tests
- Loading branch information
Joshua Hoblitt
committed
Sep 9, 2013
1 parent
b3191a3
commit 888dd0c
Showing
4 changed files
with
183 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,204 +1,69 @@ | ||
require 'spec_helper' | ||
|
||
conf_options = [ | ||
'LDAPServer', | ||
'LDAPPort', | ||
'LDAPBindDN', | ||
'LDAPBindPW', | ||
'LDAPBaseDN', | ||
'LDAPFilter', | ||
'LDAPHomeDir', | ||
'LDAPVersion', | ||
'LDAPDefaultUID', | ||
'LDAPForceDefaultUID', | ||
'LDAPDefaultGID', | ||
'LDAPForceDefaultGID', | ||
'LDAPUseTLS', | ||
'LDAPAuthMethod', | ||
] | ||
|
||
describe 'pureftpd::config::ldap' do | ||
let(:facts) {{ :osfamily=> 'RedHat' }} | ||
|
||
describe 'with no params' do | ||
it do | ||
should contain_class('pureftpd::config::ldap') | ||
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ | ||
.with_ensure('file').with_content('') | ||
end | ||
end | ||
shared_examples 'config' do |params, content| | ||
let(:facts) {{ :osfamily=> 'RedHat' }} | ||
let(:params) { params } | ||
|
||
describe 'with ldapserver' do | ||
let(:params) {{ :ldapserver => 'ldap.example.com' }} | ||
it do | ||
should contain_class('pureftpd::config::ldap') | ||
should include_class('pureftpd::config::ldap') | ||
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ | ||
.with_ensure('file') \ | ||
.with_content(/^LDAPServer ldap.example.com/) | ||
.with_content(content) | ||
end | ||
end | ||
|
||
describe 'with ldapport' do | ||
let(:params) {{ :ldapport => '389' }} | ||
it do | ||
should contain_class('pureftpd::config::ldap') | ||
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ | ||
.with_ensure('file') \ | ||
.with_content(/^LDAPPort 389/) | ||
end | ||
end | ||
all_params = {} | ||
all_content = '' | ||
value = 'xxx' | ||
|
||
describe 'with ldapbinddn' do | ||
let(:params) {{ :ldapbinddn => 'cn=Manager,dc=c9x,dc=org' }} | ||
it do | ||
should contain_class('pureftpd::config::ldap') | ||
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ | ||
.with_ensure('file') \ | ||
.with_content(/^LDAPBindDN cn=Manager,dc=c9x,dc=org/) | ||
end | ||
end | ||
|
||
describe 'with ldapbindpw' do | ||
let(:params) {{ :ldapbindpw => 'r00tPaSsw0rD' }} | ||
it do | ||
should contain_class('pureftpd::config::ldap') | ||
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ | ||
.with_ensure('file') \ | ||
.with_content(/^LDAPBindPW r00tPaSsw0rD/) | ||
end | ||
end | ||
# accumutate all of the params and content strings as we test each individual | ||
# option so we can use them for the next test | ||
context 'one option at a time' do | ||
conf_options.each do |option| | ||
params = {} | ||
params[option.downcase.to_sym] = value | ||
content = sprintf("%-19s %s\n", option, value) | ||
|
||
describe 'with ldapbasedn' do | ||
let(:params) {{ :ldapbasedn => 'cn=Users,dc=c9x,dc=org' }} | ||
it do | ||
should contain_class('pureftpd::config::ldap') | ||
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ | ||
.with_ensure('file') \ | ||
.with_content(/^LDAPBaseDN cn=Users,dc=c9x,dc=org/) | ||
end | ||
end | ||
all_params.merge!(params) | ||
all_content += content | ||
|
||
describe 'with ldapfilter' do | ||
let(:params) {{ :ldapfilter => '(&(objectClass=posixAccount)(uid=\L))' }} | ||
it do | ||
should contain_class('pureftpd::config::ldap') | ||
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ | ||
.with_ensure('file') \ | ||
.with_content(Regexp.new(Regexp.quote('LDAPFilter (&(objectClass=posixAccount)(uid=\L))'))) | ||
it_behaves_like 'config', params, content | ||
end | ||
end | ||
|
||
describe 'with ldaphomedir' do | ||
let(:params) {{ :ldaphomedir => 'homeDirectory' }} | ||
it do | ||
should contain_class('pureftpd::config::ldap') | ||
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ | ||
.with_ensure('file') \ | ||
.with_content(/^LDAPHomeDir homeDirectory/) | ||
end | ||
|
||
# test all of the known options at once this works because the ordering of | ||
# options values in the output file is fixed | ||
context 'all options' do | ||
it_behaves_like 'config', all_params, all_content | ||
end | ||
|
||
describe 'with ldapversion' do | ||
let(:params) {{ :ldapversion => '3' }} | ||
it do | ||
should contain_class('pureftpd::config::ldap') | ||
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ | ||
.with_ensure('file') \ | ||
.with_content(/^LDAPVersion 3/) | ||
end | ||
end | ||
context 'invalid param' do | ||
let(:facts) {{ :osfamily=> 'RedHat' }} | ||
let(:params) {{ :foo => 'bar' }} | ||
|
||
describe 'with ldapdefaultuid' do | ||
let(:params) {{ :ldapdefaultuid => '100' }} | ||
it do | ||
should contain_class('pureftpd::config::ldap') | ||
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ | ||
.with_ensure('file') \ | ||
.with_content(/^LDAPDefaultUID 100/) | ||
it 'should fail' do | ||
expect { should include_class('pureftpd::config::ldap') }. | ||
to raise_error(Puppet::Error, /Invalid parameter foo/) | ||
end | ||
end | ||
|
||
describe 'with ldapforcedefaultuid' do | ||
let(:params) {{ :ldapforcedefaultuid => 'False' }} | ||
it do | ||
should contain_class('pureftpd::config::ldap') | ||
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ | ||
.with_ensure('file') \ | ||
.with_content(/^LDAPForceDefaultUID False/) | ||
end | ||
end | ||
|
||
describe 'with ldapdefaultgid' do | ||
let(:params) {{ :ldapdefaultgid => '100' }} | ||
it do | ||
should contain_class('pureftpd::config::ldap') | ||
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ | ||
.with_ensure('file') \ | ||
.with_content(/^LDAPDefaultGID 100/) | ||
end | ||
end | ||
|
||
describe 'with ldapdefaultgid' do | ||
let(:params) {{ :ldapdefaultgid => '100' }} | ||
it do | ||
should contain_class('pureftpd::config::ldap') | ||
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ | ||
.with_ensure('file') \ | ||
.with_content(/^LDAPDefaultGID 100/) | ||
end | ||
end | ||
|
||
describe 'with ldapforcedefaultgid' do | ||
let(:params) {{ :ldapforcedefaultgid => 'False' }} | ||
it do | ||
should contain_class('pureftpd::config::ldap') | ||
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ | ||
.with_ensure('file') \ | ||
.with_content(/^LDAPForceDefaultGID False/) | ||
end | ||
end | ||
|
||
describe 'with ldapusetls' do | ||
let(:params) {{ :ldapusetls => 'False' }} | ||
it do | ||
should contain_class('pureftpd::config::ldap') | ||
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ | ||
.with_ensure('file') \ | ||
.with_content(/^LDAPUseTLS False/) | ||
end | ||
end | ||
|
||
describe 'with ldapauthmethod' do | ||
let(:params) {{ :ldapauthmethod => 'PASSWORD' }} | ||
it do | ||
should contain_class('pureftpd::config::ldap') | ||
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ | ||
.with_ensure('file') \ | ||
.with_content(/^LDAPAuthMethod PASSWORD/) | ||
end | ||
end | ||
|
||
describe 'with everything' do | ||
let(:params) {{ | ||
:ldapserver => 'ldap.example.com', | ||
:ldapauthmethod => 'PASSWORD', | ||
:ldapport => '389', | ||
:ldapbinddn => 'cn=Manager,dc=c9x,dc=org', | ||
:ldapbindpw => 'r00tPaSsw0rD', | ||
:ldapbasedn => 'cn=Users,dc=c9x,dc=org', | ||
:ldapfilter => '(&(objectClass=posixAccount)(uid=\L))', | ||
:ldaphomedir => 'homeDirectory', | ||
:ldapversion => '3', | ||
:ldapdefaultuid => '100', | ||
:ldapforcedefaultuid => 'False', | ||
:ldapdefaultgid => '100', | ||
:ldapdefaultgid => '100', | ||
:ldapforcedefaultgid => 'False', | ||
:ldapusetls => 'False', | ||
:ldapauthmethod => 'PASSWORD', | ||
}} | ||
it do | ||
should contain_class('pureftpd::config::ldap') | ||
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ | ||
.with_ensure('file') \ | ||
.with_content(/^LDAPServer ldap.example.com/) \ | ||
.with_content(/^LDAPPort 389/) \ | ||
.with_content(/^LDAPBindDN cn=Manager,dc=c9x,dc=org/) \ | ||
.with_content(/^LDAPBindPW r00tPaSsw0rD/) \ | ||
.with_content(/^LDAPBaseDN cn=Users,dc=c9x,dc=org/) \ | ||
.with_content(Regexp.new(Regexp.quote('LDAPFilter (&(objectClass=posixAccount)(uid=\L))'))) \ | ||
.with_content(/^LDAPHomeDir homeDirectory/) \ | ||
.with_content(/^LDAPVersion 3/) \ | ||
.with_content(/^LDAPDefaultUID 100/) \ | ||
.with_content(/^LDAPForceDefaultUID False/) \ | ||
.with_content(/^LDAPDefaultGID 100/) \ | ||
.with_content(/^LDAPDefaultGID 100/) \ | ||
.with_content(/^LDAPForceDefaultGID False/) \ | ||
.with_content(/^LDAPUseTLS False/) \ | ||
.with_content(/^LDAPAuthMethod PASSWORD/) \ | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.