-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathinit_spec.rb
362 lines (331 loc) · 18 KB
/
init_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
require 'spec_helper'
describe 'squid' do
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end
context 'with defaults for all parameters' do
it { is_expected.to contain_class('squid') }
it { is_expected.to contain_class('squid::install') }
it { is_expected.to contain_class('squid::config') }
it { is_expected.to contain_class('squid::service') }
case facts[:operatingsystem]
when 'Debian'
context 'when on Debian' do
it { is_expected.to contain_package('squid3').with_ensure('present') }
it { is_expected.to contain_service('squid3').with_ensure('running') }
it { is_expected.to contain_concat('/etc/squid3/squid.conf').with_group('root') }
it { is_expected.to contain_concat('/etc/squid3/squid.conf').with_owner('root') }
it { is_expected.to contain_concat_fragment('squid_header').with_target('/etc/squid3/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^access_log\s+daemon:/var/log/squid3/access.log\s+squid$}) }
end
when 'Ubuntu'
case facts[:operatingsystemrelease]
when '14.04'
context 'when on Ubuntu 14.04' do
it { is_expected.to contain_package('squid3').with_ensure('present') }
it { is_expected.to contain_service('squid3').with_ensure('running') }
it { is_expected.to contain_concat('/etc/squid3/squid.conf').with_group('root') }
it { is_expected.to contain_concat('/etc/squid3/squid.conf').with_owner('root') }
it { is_expected.to contain_concat_fragment('squid_header').with_target('/etc/squid3/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^access_log\s+daemon:/var/log/squid3/access.log\s+squid$}) }
end
when '16.04'
context 'when on Ubuntu 16.04' do
it { is_expected.to contain_package('squid').with_ensure('present') }
it { is_expected.to contain_service('squid').with_ensure('running') }
it { is_expected.to contain_concat('/etc/squid/squid.conf').with_group('root') }
it { is_expected.to contain_concat('/etc/squid/squid.conf').with_owner('root') }
it { is_expected.to contain_concat_fragment('squid_header').with_target('/etc/squid/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^access_log\s+daemon:/var/log/squid/access.log\s+squid$}) }
end
end
when 'FreeBSD'
context 'when on FreeBSD' do
it { is_expected.to contain_package('squid').with_ensure('present') }
it { is_expected.to contain_service('squid').with_ensure('running') }
it { is_expected.to contain_concat('/usr/local/etc/squid/squid.conf').with_group('squid') }
it { is_expected.to contain_concat('/usr/local/etc/squid/squid.conf').with_owner('root') }
it { is_expected.to contain_concat_fragment('squid_header').with_target('/usr/local/etc/squid/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^access_log\s+daemon:/var/log/squid/access.log\s+squid$}) }
end
else
context 'when on any other supported OS' do
it { is_expected.to contain_package('squid').with_ensure('present') }
it { is_expected.to contain_service('squid').with_ensure('running') }
it { is_expected.to contain_concat('/etc/squid/squid.conf').with_group('squid') }
it { is_expected.to contain_concat('/etc/squid/squid.conf').with_owner('root') }
it { is_expected.to contain_concat_fragment('squid_header').with_target('/etc/squid/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^access_log\s+daemon:/var/log/squid/access.log\s+squid$}) }
end
end
it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^cache_mem\s+256 MB$}) }
it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^maximum_object_size_in_memory\s+512 KB$}) }
it { is_expected.to contain_concat_fragment('squid_header').without_content(%r{^memory_cache_shared}) }
it { is_expected.to contain_concat_fragment('squid_header').without_content(%r{^coredump_dir}) }
it { is_expected.to contain_concat_fragment('squid_header').without_content(%r{^max_filedescriptors}) }
it { is_expected.to contain_concat_fragment('squid_header').without_content(%r{^workers}) }
end
context 'with all parameters set' do
let :params do
{
config: '/tmp/squid.conf',
cache_mem: '1024 MB',
memory_cache_shared: 'on',
logformat: 'squid %tl.%03tu %6tr %>a %Ss/%03Hs',
access_log: '/var/log/out.log',
coredump_dir: '/tmp/core',
max_filedescriptors: 1000,
workers: 8
}
end
it { is_expected.to contain_concat_fragment('squid_header').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^cache_mem\s+1024 MB$}) }
it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^memory_cache_shared\s+on$}) }
it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^logformat\s+squid %tl.%03tu %6tr %>a %Ss/%03Hs$}) }
it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^access_log\s+/var/log/out.log$}) }
it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^coredump_dir\s+/tmp/core$}) }
it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^max_filedescriptors\s+1000$}) }
it { is_expected.to contain_concat_fragment('squid_header').with_content(%r{^workers\s+8$}) }
end
context 'with one acl parameter set' do
let :params do
{
config: '/tmp/squid.conf',
acls: {
'myacl' => {
'type' => 'urlregex',
'order' => '07',
'entries' => ['http://example.org/', 'http://example.com/']
}
}
}
end
it { is_expected.to contain_concat_fragment('squid_header').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_acl_myacl').with_order('10-07-urlregex') }
it { is_expected.to contain_concat_fragment('squid_acl_myacl').with_content(%r{^acl\s+myacl\s+urlregex\shttp://example.org/$}) }
it { is_expected.to contain_concat_fragment('squid_acl_myacl').with_content(%r{^# acl fragment for myacl$}) }
end
context 'with two acl parameters set' do
let :params do
{
config: '/tmp/squid.conf',
acls: {
'myacl' => {
'type' => 'urlregex',
'order' => '07',
'entries' => ['http://example.org/', 'http://example.com/']
},
'mysecondacl' => {
'type' => 'urlregex',
'order' => '08',
'entries' => ['http://example2.org/', 'http://example2.com/']
}
}
}
end
it { is_expected.to contain_concat_fragment('squid_header').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_acl_myacl').with_order('10-07-urlregex') }
it { is_expected.to contain_concat_fragment('squid_acl_myacl').with_content(%r{^acl\s+myacl\s+urlregex\shttp://example.org/$}) }
it { is_expected.to contain_concat_fragment('squid_acl_myacl').with_content(%r{^acl\s+myacl\s+urlregex\shttp://example.com/$}) }
it { is_expected.to contain_concat_fragment('squid_acl_mysecondacl').with_order('10-08-urlregex') }
it { is_expected.to contain_concat_fragment('squid_acl_mysecondacl').with_content(%r{^acl\s+mysecondacl\s+urlregex\shttp://example2.org/$}) }
it { is_expected.to contain_concat_fragment('squid_acl_mysecondacl').with_content(%r{^acl\s+mysecondacl\s+urlregex\shttp://example2.com/$}) }
end
context 'with one http_access parameter set' do
let :params do
{
config: '/tmp/squid.conf',
http_access: {
'myrule' => {
'action' => 'deny',
'value' => 'this and that',
'order' => '08'
}
}
}
end
it { is_expected.to contain_concat_fragment('squid_header').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_http_access_this and that').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_http_access_this and that').with_order('20-08-deny') }
it { is_expected.to contain_concat_fragment('squid_http_access_this and that').with_content(%r{^http_access\s+deny\s+this and that$}) }
end
context 'with two http_access parameters set' do
let :params do
{
config: '/tmp/squid.conf',
http_access: {
'myrule' => {
'action' => 'deny',
'value' => 'this and that',
'order' => '08'
},
'secondrule' => {
'action' => 'deny',
'value' => 'this too',
'order' => '09',
'comment' => 'Deny this and too'
}
}
}
end
it { is_expected.to contain_concat_fragment('squid_header').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_http_access_this and that').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_http_access_this and that').with_order('20-08-deny') }
it { is_expected.to contain_concat_fragment('squid_http_access_this and that').with_content(%r{^http_access\s+deny\s+this and that$}) }
it { is_expected.to contain_concat_fragment('squid_http_access_this and that').with_content(%r{^# http_access fragment for this and that$}) }
it { is_expected.to contain_concat_fragment('squid_http_access_this too').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_http_access_this too').with_order('20-09-deny') }
it { is_expected.to contain_concat_fragment('squid_http_access_this too').with_content(%r{^http_access\s+deny\s+this too$}) }
it { is_expected.to contain_concat_fragment('squid_http_access_this too').with_content(%r{^# Deny this and too$}) }
end
context 'with one ssl_bump parameter set' do
let :params do
{
config: '/tmp/squid.conf',
ssl_bump: {
'myrule' => {
'action' => 'bump',
'value' => 'step1',
'order' => '08'
}
}
}
end
it { is_expected.to contain_concat_fragment('squid_header').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_ssl_bump_bump_step1').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_ssl_bump_bump_step1').with_order('25-08-bump') }
it { is_expected.to contain_concat_fragment('squid_ssl_bump_bump_step1').with_content(%r{^ssl_bump\s+bump\s+step1$}) }
end
context 'with one sslproxy_cert_error parameter set' do
let :params do
{
config: '/tmp/squid.conf',
sslproxy_cert_error: {
'myrule' => {
'action' => 'allow',
'value' => 'all',
'order' => '08'
}
}
}
end
it { is_expected.to contain_concat_fragment('squid_header').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_sslproxy_cert_error_allow_all').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_sslproxy_cert_error_allow_all').with_order('35-08-allow') }
it { is_expected.to contain_concat_fragment('squid_sslproxy_cert_error_allow_all').with_content(%r{^sslproxy_cert_error\s+allow\s+all$}) }
end
context 'with one icp_access parameter set' do
let :params do
{
config: '/tmp/squid.conf',
icp_access: {
'myrule' => {
'action' => 'deny',
'value' => 'this and that',
'order' => '08'
}
}
}
end
it { is_expected.to contain_concat_fragment('squid_header').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_icp_access_this and that').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_icp_access_this and that').with_order('30-08-deny') }
it { is_expected.to contain_concat_fragment('squid_icp_access_this and that').with_content(%r{^icp_access\s+deny\s+this and that$}) }
end
context 'with two icp_access parameters set' do
let :params do
{
config: '/tmp/squid.conf',
icp_access: {
'myrule' => {
'action' => 'deny',
'value' => 'this and that',
'order' => '08'
},
'secondrule' => {
'action' => 'deny',
'value' => 'this too',
'order' => '09'
}
}
}
end
it { is_expected.to contain_concat_fragment('squid_header').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_icp_access_this and that').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_icp_access_this and that').with_order('30-08-deny') }
it { is_expected.to contain_concat_fragment('squid_icp_access_this and that').with_content(%r{^icp_access\s+deny\s+this and that$}) }
it { is_expected.to contain_concat_fragment('squid_icp_access_this too').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_icp_access_this too').with_order('30-09-deny') }
it { is_expected.to contain_concat_fragment('squid_icp_access_this too').with_content(%r{^icp_access\s+deny\s+this too$}) }
end
context 'with http_port parameters set' do
let :params do
{ config: '/tmp/squid.conf',
http_ports: { 2000 => { 'options' => 'special for 2000' } } }
end
it { is_expected.to contain_concat_fragment('squid_header').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_http_port_2000').with_order('30-05') }
it { is_expected.to contain_concat_fragment('squid_http_port_2000').with_content(%r{^http_port\s+2000\s+special for 2000$}) }
end
context 'with https_port parameters set' do
let :params do
{ config: '/tmp/squid.conf',
https_ports: { 2001 => { 'options' => 'special for 2001' } } }
end
it { is_expected.to contain_concat_fragment('squid_header').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_https_port_2001').with_order('30-05') }
it { is_expected.to contain_concat_fragment('squid_https_port_2001').with_content(%r{^https_port\s+2001\s+special for 2001$}) }
end
context 'with snmp_port parameters set' do
let :params do
{ config: '/tmp/squid.conf',
snmp_ports: { 2000 => { 'options' => 'special for 2000',
'process_number' => 3 } } }
end
it { is_expected.to contain_concat_fragment('squid_header').with_target('/tmp/squid.conf') }
it { is_expected.to contain_concat_fragment('squid_snmp_port_2000').with_content(%r{^snmp_port\s+2000\s+special for 2000$}) }
it { is_expected.to contain_concat_fragment('squid_snmp_port_2000').with_content(%r{^if \${process_number} = 3$}) }
it { is_expected.to contain_concat_fragment('squid_snmp_port_2000').with_content(%r{^endif$}) }
end
context 'with cache_dir parameters set' do
let :params do
{ config: '/tmp/squid.conf',
cache_dirs: { '/data' => { 'type' => 'special',
'options' => 'my options for special type' } } }
end
it { is_expected.to contain_concat_fragment('squid_header').with_target('/tmp/squid.conf') }
it { is_expected.to contain_file('/data').with_ensure('directory') }
end
context 'with extra_config_sections parameter set' do
let :params do
{
config: '/tmp/squid.conf',
extra_config_sections: {
'mail settings' => {
'order' => 22,
'config_entries' => {
'mail_from' => '[email protected]',
'mail_program' => 'mail'
}
},
'other settings' => {
'order' => 42,
'config_entries' => {
'dns_timeout' => '5 seconds'
}
}
}
}
end
it { is_expected.to contain_concat_fragment('squid_header').with_target('/tmp/squid.conf') }
it { is_expected.to contain_squid__extra_config_section('mail settings') }
it { is_expected.to contain_squid__extra_config_section('other settings') }
it { is_expected.to contain_concat_fragment('squid_extra_config_section_mail settings').with_content(%r{^mail_from\s+squid@example\.com$}) }
it { is_expected.to contain_concat_fragment('squid_extra_config_section_mail settings').with_content(%r{^mail_program\s+mail$}) }
it { is_expected.to contain_concat_fragment('squid_extra_config_section_other settings').with_content(%r{^dns_timeout\s+5 seconds$}) }
end
end
end
end