|
1 | 1 | require 'spec_helper'
|
2 | 2 |
|
| 3 | +conf_options = [ |
| 4 | + 'LDAPServer', |
| 5 | + 'LDAPPort', |
| 6 | + 'LDAPBindDN', |
| 7 | + 'LDAPBindPW', |
| 8 | + 'LDAPBaseDN', |
| 9 | + 'LDAPFilter', |
| 10 | + 'LDAPHomeDir', |
| 11 | + 'LDAPVersion', |
| 12 | + 'LDAPDefaultUID', |
| 13 | + 'LDAPForceDefaultUID', |
| 14 | + 'LDAPDefaultGID', |
| 15 | + 'LDAPForceDefaultGID', |
| 16 | + 'LDAPUseTLS', |
| 17 | + 'LDAPAuthMethod', |
| 18 | +] |
| 19 | + |
3 | 20 | describe 'pureftpd::config::ldap' do
|
4 |
| - let(:facts) {{ :osfamily=> 'RedHat' }} |
5 | 21 |
|
6 |
| - describe 'with no params' do |
7 |
| - it do |
8 |
| - should contain_class('pureftpd::config::ldap') |
9 |
| - should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ |
10 |
| - .with_ensure('file').with_content('') |
11 |
| - end |
12 |
| - end |
| 22 | + shared_examples 'config' do |params, content| |
| 23 | + let(:facts) {{ :osfamily=> 'RedHat' }} |
| 24 | + let(:params) { params } |
13 | 25 |
|
14 |
| - describe 'with ldapserver' do |
15 |
| - let(:params) {{ :ldapserver => 'ldap.example.com' }} |
16 | 26 | it do
|
17 |
| - should contain_class('pureftpd::config::ldap') |
| 27 | + should include_class('pureftpd::config::ldap') |
18 | 28 | should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
|
19 | 29 | .with_ensure('file') \
|
20 |
| - .with_content(/^LDAPServer ldap.example.com/) |
| 30 | + .with_content(content) |
21 | 31 | end
|
22 | 32 | end
|
23 | 33 |
|
24 |
| - describe 'with ldapport' do |
25 |
| - let(:params) {{ :ldapport => '389' }} |
26 |
| - it do |
27 |
| - should contain_class('pureftpd::config::ldap') |
28 |
| - should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ |
29 |
| - .with_ensure('file') \ |
30 |
| - .with_content(/^LDAPPort 389/) |
31 |
| - end |
32 |
| - end |
| 34 | + all_params = {} |
| 35 | + all_content = '' |
| 36 | + value = 'xxx' |
33 | 37 |
|
34 |
| - describe 'with ldapbinddn' do |
35 |
| - let(:params) {{ :ldapbinddn => 'cn=Manager,dc=c9x,dc=org' }} |
36 |
| - it do |
37 |
| - should contain_class('pureftpd::config::ldap') |
38 |
| - should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ |
39 |
| - .with_ensure('file') \ |
40 |
| - .with_content(/^LDAPBindDN cn=Manager,dc=c9x,dc=org/) |
41 |
| - end |
42 |
| - end |
43 |
| - |
44 |
| - describe 'with ldapbindpw' do |
45 |
| - let(:params) {{ :ldapbindpw => 'r00tPaSsw0rD' }} |
46 |
| - it do |
47 |
| - should contain_class('pureftpd::config::ldap') |
48 |
| - should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ |
49 |
| - .with_ensure('file') \ |
50 |
| - .with_content(/^LDAPBindPW r00tPaSsw0rD/) |
51 |
| - end |
52 |
| - end |
| 38 | + # accumutate all of the params and content strings as we test each individual |
| 39 | + # option so we can use them for the next test |
| 40 | + context 'one option at a time' do |
| 41 | + conf_options.each do |option| |
| 42 | + params = {} |
| 43 | + params[option.downcase.to_sym] = value |
| 44 | + content = sprintf("%-19s %s\n", option, value) |
53 | 45 |
|
54 |
| - describe 'with ldapbasedn' do |
55 |
| - let(:params) {{ :ldapbasedn => 'cn=Users,dc=c9x,dc=org' }} |
56 |
| - it do |
57 |
| - should contain_class('pureftpd::config::ldap') |
58 |
| - should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ |
59 |
| - .with_ensure('file') \ |
60 |
| - .with_content(/^LDAPBaseDN cn=Users,dc=c9x,dc=org/) |
61 |
| - end |
62 |
| - end |
| 46 | + all_params.merge!(params) |
| 47 | + all_content += content |
63 | 48 |
|
64 |
| - describe 'with ldapfilter' do |
65 |
| - let(:params) {{ :ldapfilter => '(&(objectClass=posixAccount)(uid=\L))' }} |
66 |
| - it do |
67 |
| - should contain_class('pureftpd::config::ldap') |
68 |
| - should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ |
69 |
| - .with_ensure('file') \ |
70 |
| - .with_content(Regexp.new(Regexp.quote('LDAPFilter (&(objectClass=posixAccount)(uid=\L))'))) |
| 49 | + it_behaves_like 'config', params, content |
71 | 50 | end
|
72 | 51 | end
|
73 |
| - |
74 |
| - describe 'with ldaphomedir' do |
75 |
| - let(:params) {{ :ldaphomedir => 'homeDirectory' }} |
76 |
| - it do |
77 |
| - should contain_class('pureftpd::config::ldap') |
78 |
| - should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ |
79 |
| - .with_ensure('file') \ |
80 |
| - .with_content(/^LDAPHomeDir homeDirectory/) |
81 |
| - end |
| 52 | + |
| 53 | + # test all of the known options at once this works because the ordering of |
| 54 | + # options values in the output file is fixed |
| 55 | + context 'all options' do |
| 56 | + it_behaves_like 'config', all_params, all_content |
82 | 57 | end
|
83 | 58 |
|
84 |
| - describe 'with ldapversion' do |
85 |
| - let(:params) {{ :ldapversion => '3' }} |
86 |
| - it do |
87 |
| - should contain_class('pureftpd::config::ldap') |
88 |
| - should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ |
89 |
| - .with_ensure('file') \ |
90 |
| - .with_content(/^LDAPVersion 3/) |
91 |
| - end |
92 |
| - end |
| 59 | + context 'invalid param' do |
| 60 | + let(:facts) {{ :osfamily=> 'RedHat' }} |
| 61 | + let(:params) {{ :foo => 'bar' }} |
93 | 62 |
|
94 |
| - describe 'with ldapdefaultuid' do |
95 |
| - let(:params) {{ :ldapdefaultuid => '100' }} |
96 |
| - it do |
97 |
| - should contain_class('pureftpd::config::ldap') |
98 |
| - should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ |
99 |
| - .with_ensure('file') \ |
100 |
| - .with_content(/^LDAPDefaultUID 100/) |
| 63 | + it 'should fail' do |
| 64 | + expect { should include_class('pureftpd::config::ldap') }. |
| 65 | + to raise_error(Puppet::Error, /Invalid parameter foo/) |
101 | 66 | end
|
102 | 67 | end
|
103 | 68 |
|
104 |
| - describe 'with ldapforcedefaultuid' do |
105 |
| - let(:params) {{ :ldapforcedefaultuid => 'False' }} |
106 |
| - it do |
107 |
| - should contain_class('pureftpd::config::ldap') |
108 |
| - should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ |
109 |
| - .with_ensure('file') \ |
110 |
| - .with_content(/^LDAPForceDefaultUID False/) |
111 |
| - end |
112 |
| - end |
113 |
| - |
114 |
| - describe 'with ldapdefaultgid' do |
115 |
| - let(:params) {{ :ldapdefaultgid => '100' }} |
116 |
| - it do |
117 |
| - should contain_class('pureftpd::config::ldap') |
118 |
| - should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ |
119 |
| - .with_ensure('file') \ |
120 |
| - .with_content(/^LDAPDefaultGID 100/) |
121 |
| - end |
122 |
| - end |
123 |
| - |
124 |
| - describe 'with ldapdefaultgid' do |
125 |
| - let(:params) {{ :ldapdefaultgid => '100' }} |
126 |
| - it do |
127 |
| - should contain_class('pureftpd::config::ldap') |
128 |
| - should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ |
129 |
| - .with_ensure('file') \ |
130 |
| - .with_content(/^LDAPDefaultGID 100/) |
131 |
| - end |
132 |
| - end |
133 |
| - |
134 |
| - describe 'with ldapforcedefaultgid' do |
135 |
| - let(:params) {{ :ldapforcedefaultgid => 'False' }} |
136 |
| - it do |
137 |
| - should contain_class('pureftpd::config::ldap') |
138 |
| - should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ |
139 |
| - .with_ensure('file') \ |
140 |
| - .with_content(/^LDAPForceDefaultGID False/) |
141 |
| - end |
142 |
| - end |
143 |
| - |
144 |
| - describe 'with ldapusetls' do |
145 |
| - let(:params) {{ :ldapusetls => 'False' }} |
146 |
| - it do |
147 |
| - should contain_class('pureftpd::config::ldap') |
148 |
| - should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ |
149 |
| - .with_ensure('file') \ |
150 |
| - .with_content(/^LDAPUseTLS False/) |
151 |
| - end |
152 |
| - end |
153 |
| - |
154 |
| - describe 'with ldapauthmethod' do |
155 |
| - let(:params) {{ :ldapauthmethod => 'PASSWORD' }} |
156 |
| - it do |
157 |
| - should contain_class('pureftpd::config::ldap') |
158 |
| - should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ |
159 |
| - .with_ensure('file') \ |
160 |
| - .with_content(/^LDAPAuthMethod PASSWORD/) |
161 |
| - end |
162 |
| - end |
163 |
| - |
164 |
| - describe 'with everything' do |
165 |
| - let(:params) {{ |
166 |
| - :ldapserver => 'ldap.example.com', |
167 |
| - :ldapauthmethod => 'PASSWORD', |
168 |
| - :ldapport => '389', |
169 |
| - :ldapbinddn => 'cn=Manager,dc=c9x,dc=org', |
170 |
| - :ldapbindpw => 'r00tPaSsw0rD', |
171 |
| - :ldapbasedn => 'cn=Users,dc=c9x,dc=org', |
172 |
| - :ldapfilter => '(&(objectClass=posixAccount)(uid=\L))', |
173 |
| - :ldaphomedir => 'homeDirectory', |
174 |
| - :ldapversion => '3', |
175 |
| - :ldapdefaultuid => '100', |
176 |
| - :ldapforcedefaultuid => 'False', |
177 |
| - :ldapdefaultgid => '100', |
178 |
| - :ldapdefaultgid => '100', |
179 |
| - :ldapforcedefaultgid => 'False', |
180 |
| - :ldapusetls => 'False', |
181 |
| - :ldapauthmethod => 'PASSWORD', |
182 |
| - }} |
183 |
| - it do |
184 |
| - should contain_class('pureftpd::config::ldap') |
185 |
| - should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \ |
186 |
| - .with_ensure('file') \ |
187 |
| - .with_content(/^LDAPServer ldap.example.com/) \ |
188 |
| - .with_content(/^LDAPPort 389/) \ |
189 |
| - .with_content(/^LDAPBindDN cn=Manager,dc=c9x,dc=org/) \ |
190 |
| - .with_content(/^LDAPBindPW r00tPaSsw0rD/) \ |
191 |
| - .with_content(/^LDAPBaseDN cn=Users,dc=c9x,dc=org/) \ |
192 |
| - .with_content(Regexp.new(Regexp.quote('LDAPFilter (&(objectClass=posixAccount)(uid=\L))'))) \ |
193 |
| - .with_content(/^LDAPHomeDir homeDirectory/) \ |
194 |
| - .with_content(/^LDAPVersion 3/) \ |
195 |
| - .with_content(/^LDAPDefaultUID 100/) \ |
196 |
| - .with_content(/^LDAPForceDefaultUID False/) \ |
197 |
| - .with_content(/^LDAPDefaultGID 100/) \ |
198 |
| - .with_content(/^LDAPDefaultGID 100/) \ |
199 |
| - .with_content(/^LDAPForceDefaultGID False/) \ |
200 |
| - .with_content(/^LDAPUseTLS False/) \ |
201 |
| - .with_content(/^LDAPAuthMethod PASSWORD/) \ |
202 |
| - end |
203 |
| - end |
204 | 69 | end
|
0 commit comments