]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/apache/spec/acceptance/apache_parameters_spec.rb
try again, with puppetforge modules, correctly included now
[dsa-puppet.git] / 3rdparty / modules / apache / spec / acceptance / apache_parameters_spec.rb
1 require 'spec_helper_acceptance'
2 require_relative './version.rb'
3
4 describe 'apache parameters', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
5
6   # Currently this test only does something on FreeBSD.
7   describe 'default_confd_files => false' do
8     it 'doesnt do anything' do
9       pp = "class { 'apache': default_confd_files => false }"
10       apply_manifest(pp, :catch_failures => true)
11     end
12
13     if fact('osfamily') == 'FreeBSD'
14       describe file("#{$confd_dir}/no-accf.conf.erb") do
15         it { is_expected.not_to be_file }
16       end
17     end
18   end
19   describe 'default_confd_files => true' do
20     it 'copies conf.d files' do
21       pp = "class { 'apache': default_confd_files => true }"
22       apply_manifest(pp, :catch_failures => true)
23     end
24
25     if fact('osfamily') == 'FreeBSD'
26       describe file("#{$confd_dir}/no-accf.conf.erb") do
27         it { is_expected.to be_file }
28       end
29     end
30   end
31
32   describe 'when set adds a listen statement' do
33     it 'applys cleanly' do
34       pp = "class { 'apache': ip => '10.1.1.1', service_ensure => stopped }"
35       apply_manifest(pp, :catch_failures => true)
36     end
37
38     describe file($ports_file) do
39       it { is_expected.to be_file }
40       it { is_expected.to contain 'Listen 10.1.1.1' }
41     end
42   end
43
44   describe 'service tests => true' do
45     it 'starts the service' do
46       pp = <<-EOS
47         class { 'apache':
48           service_enable => true,
49           service_manage => true,
50           service_ensure => running,
51         }
52       EOS
53       apply_manifest(pp, :catch_failures => true)
54     end
55
56     describe service($service_name) do
57       it { is_expected.to be_running }
58       it { is_expected.to be_enabled }
59     end
60   end
61
62   describe 'service tests => false' do
63     it 'stops the service' do
64       pp = <<-EOS
65         class { 'apache':
66           service_enable => false,
67           service_ensure => stopped,
68         }
69       EOS
70       apply_manifest(pp, :catch_failures => true)
71     end
72
73     describe service($service_name) do
74       it { is_expected.not_to be_running }
75       it { is_expected.not_to be_enabled }
76     end
77   end
78
79   describe 'service manage => false' do
80     it 'we dont manage the service, so it shouldnt start the service' do
81       pp = <<-EOS
82         class { 'apache':
83           service_enable => true,
84           service_manage => false,
85           service_ensure => true,
86         }
87       EOS
88       apply_manifest(pp, :catch_failures => true)
89     end
90
91     describe service($service_name) do
92       it { is_expected.not_to be_running }
93       it { is_expected.not_to be_enabled }
94     end
95   end
96
97   describe 'purge parameters => false' do
98     it 'applies cleanly' do
99       pp = <<-EOS
100         class { 'apache':
101           purge_configs   => false,
102           purge_vhost_dir => false,
103           vhost_dir       => "#{$confd_dir}.vhosts"
104         }
105       EOS
106       shell("touch #{$confd_dir}/test.conf")
107       shell("mkdir -p #{$confd_dir}.vhosts && touch #{$confd_dir}.vhosts/test.conf")
108       apply_manifest(pp, :catch_failures => true)
109     end
110
111     # Ensure the files didn't disappear.
112     describe file("#{$confd_dir}/test.conf") do
113       it { is_expected.to be_file }
114     end
115     describe file("#{$confd_dir}.vhosts/test.conf") do
116       it { is_expected.to be_file }
117     end
118   end
119
120   if fact('osfamily') != 'Debian'
121     describe 'purge parameters => true' do
122       it 'applies cleanly' do
123         pp = <<-EOS
124           class { 'apache':
125             purge_configs   => true,
126             purge_vhost_dir => true,
127             vhost_dir       => "#{$confd_dir}.vhosts"
128           }
129         EOS
130         shell("touch #{$confd_dir}/test.conf")
131         shell("mkdir -p #{$confd_dir}.vhosts && touch #{$confd_dir}.vhosts/test.conf")
132         apply_manifest(pp, :catch_failures => true)
133       end
134
135       # File should be gone
136       describe file("#{$confd_dir}/test.conf") do
137         it { is_expected.not_to be_file }
138       end
139       describe file("#{$confd_dir}.vhosts/test.conf") do
140         it { is_expected.not_to be_file }
141       end
142     end
143   end
144
145   describe 'serveradmin' do
146     it 'applies cleanly' do
147       pp = "class { 'apache': serveradmin => 'test@example.com' }"
148       apply_manifest(pp, :catch_failures => true)
149     end
150
151     describe file($vhost) do
152       it { is_expected.to be_file }
153       it { is_expected.to contain 'ServerAdmin test@example.com' }
154     end
155   end
156
157   describe 'sendfile' do
158     describe 'setup' do
159       it 'applies cleanly' do
160         pp = "class { 'apache': sendfile => 'On' }"
161         apply_manifest(pp, :catch_failures => true)
162       end
163     end
164
165     describe file($conf_file) do
166       it { is_expected.to be_file }
167       it { is_expected.to contain 'EnableSendfile On' }
168     end
169
170     describe 'setup' do
171       it 'applies cleanly' do
172         pp = "class { 'apache': sendfile => 'Off' }"
173         apply_manifest(pp, :catch_failures => true)
174       end
175     end
176
177     describe file($conf_file) do
178       it { is_expected.to be_file }
179       it { is_expected.to contain 'Sendfile Off' }
180     end
181   end
182
183   describe 'error_documents' do
184     describe 'setup' do
185       it 'applies cleanly' do
186         pp = "class { 'apache': error_documents => true }"
187         apply_manifest(pp, :catch_failures => true)
188       end
189     end
190
191     describe file($conf_file) do
192       it { is_expected.to be_file }
193       it { is_expected.to contain 'Alias /error/' }
194     end
195   end
196
197   describe 'timeout' do
198     describe 'setup' do
199       it 'applies cleanly' do
200         pp = "class { 'apache': timeout => '1234' }"
201         apply_manifest(pp, :catch_failures => true)
202       end
203     end
204
205     describe file($conf_file) do
206       it { is_expected.to be_file }
207       it { is_expected.to contain 'Timeout 1234' }
208     end
209   end
210
211   describe 'httpd_dir' do
212     describe 'setup' do
213       it 'applies cleanly' do
214         pp = <<-EOS
215           class { 'apache': httpd_dir => '/tmp', service_ensure => stopped }
216           include 'apache::mod::mime'
217         EOS
218         apply_manifest(pp, :catch_failures => true)
219       end
220     end
221
222     describe file("#{$mod_dir}/mime.conf") do
223       it { is_expected.to be_file }
224       it { is_expected.to contain 'AddLanguage eo .eo' }
225     end
226   end
227
228   describe 'server_root' do
229     describe 'setup' do
230       it 'applies cleanly' do
231         pp = "class { 'apache': server_root => '/tmp/root', service_ensure => stopped }"
232         apply_manifest(pp, :catch_failures => true)
233       end
234     end
235
236     describe file($conf_file) do
237       it { is_expected.to be_file }
238       it { is_expected.to contain 'ServerRoot "/tmp/root"' }
239     end
240   end
241
242   describe 'confd_dir' do
243     describe 'setup' do
244       it 'applies cleanly' do
245         pp = "class { 'apache': confd_dir => '/tmp/root', service_ensure => stopped, use_optional_includes => true }"
246         apply_manifest(pp, :catch_failures => true)
247       end
248     end
249
250     if $apache_version == '2.4'
251       describe file($conf_file) do
252         it { is_expected.to be_file }
253         it { is_expected.to contain 'IncludeOptional "/tmp/root/*.conf"' }
254       end
255     else
256       describe file($conf_file) do
257         it { is_expected.to be_file }
258         it { is_expected.to contain 'Include "/tmp/root/*.conf"' }
259       end
260     end
261   end
262
263   describe 'conf_template' do
264     describe 'setup' do
265       it 'applies cleanly' do
266         pp = "class { 'apache': conf_template => 'another/test.conf.erb', service_ensure => stopped }"
267         shell("mkdir -p #{default['distmoduledir']}/another/templates")
268         shell("echo 'testcontent' >> #{default['distmoduledir']}/another/templates/test.conf.erb")
269         apply_manifest(pp, :catch_failures => true)
270       end
271     end
272
273     describe file($conf_file) do
274       it { is_expected.to be_file }
275       it { is_expected.to contain 'testcontent' }
276     end
277   end
278
279   describe 'servername' do
280     describe 'setup' do
281       it 'applies cleanly' do
282         pp = "class { 'apache': servername => 'test.server', service_ensure => stopped }"
283         apply_manifest(pp, :catch_failures => true)
284       end
285     end
286
287     describe file($conf_file) do
288       it { is_expected.to be_file }
289       it { is_expected.to contain 'ServerName "test.server"' }
290     end
291   end
292
293   describe 'user' do
294     describe 'setup' do
295       it 'applies cleanly' do
296         pp = <<-EOS
297           class { 'apache':
298             manage_user  => true,
299             manage_group => true,
300             user         => 'testweb',
301             group        => 'testweb',
302           }
303         EOS
304         apply_manifest(pp, :catch_failures => true)
305       end
306     end
307
308     describe user('testweb') do
309       it { is_expected.to exist }
310       it { is_expected.to belong_to_group 'testweb' }
311     end
312
313     describe group('testweb') do
314       it { is_expected.to exist }
315     end
316   end
317
318   describe 'logformats' do
319     describe 'setup' do
320       it 'applies cleanly' do
321         pp = <<-EOS
322           class { 'apache':
323             log_formats => {
324               'vhost_common'   => '%v %h %l %u %t \\\"%r\\\" %>s %b',
325               'vhost_combined' => '%v %h %l %u %t \\\"%r\\\" %>s %b \\\"%{Referer}i\\\" \\\"%{User-agent}i\\\"',
326             }
327           }
328         EOS
329         apply_manifest(pp, :catch_failures => true)
330       end
331     end
332
333     describe file($conf_file) do
334       it { is_expected.to be_file }
335       it { is_expected.to contain 'LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common' }
336       it { is_expected.to contain 'LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" vhost_combined' }
337     end
338   end
339
340
341   describe 'keepalive' do
342     describe 'setup' do
343       it 'applies cleanly' do
344         pp = "class { 'apache': keepalive => 'On', keepalive_timeout => '30', max_keepalive_requests => '200' }"
345         apply_manifest(pp, :catch_failures => true)
346       end
347     end
348
349     describe file($conf_file) do
350       it { is_expected.to be_file }
351       it { is_expected.to contain 'KeepAlive On' }
352       it { is_expected.to contain 'KeepAliveTimeout 30' }
353       it { is_expected.to contain 'MaxKeepAliveRequests 200' }
354     end
355   end
356
357   describe 'logging' do
358     describe 'setup' do
359       it 'applies cleanly' do
360         pp = <<-EOS
361           if $::osfamily == 'RedHat' and $::selinux {
362             $semanage_package = $::operatingsystemmajrelease ? {
363               '5'     => 'policycoreutils',
364               default => 'policycoreutils-python',
365             }
366
367             package { $semanage_package: ensure => installed }
368             exec { 'set_apache_defaults':
369               command => 'semanage fcontext -a -t httpd_log_t "/apache_spec(/.*)?"',
370               path    => '/bin:/usr/bin/:/sbin:/usr/sbin',
371               require => Package[$semanage_package],
372             }
373             exec { 'restorecon_apache':
374               command => 'restorecon -Rv /apache_spec',
375               path    => '/bin:/usr/bin/:/sbin:/usr/sbin',
376               before  => Service['httpd'],
377               require => Class['apache'],
378             }
379           }
380           file { '/apache_spec': ensure => directory, }
381           class { 'apache': logroot => '/apache_spec' }
382         EOS
383         apply_manifest(pp, :catch_failures => true)
384       end
385     end
386
387     describe file("/apache_spec/#{$error_log}") do
388       it { is_expected.to be_file }
389     end
390   end
391
392   describe 'ports_file' do
393     it 'applys cleanly' do
394       pp = <<-EOS
395         file { '/apache_spec': ensure => directory, }
396         class { 'apache':
397           ports_file     => '/apache_spec/ports_file',
398           ip             => '10.1.1.1',
399           service_ensure => stopped
400         }
401       EOS
402       apply_manifest(pp, :catch_failures => true)
403     end
404
405     describe file('/apache_spec/ports_file') do
406       it { is_expected.to be_file }
407       it { is_expected.to contain 'Listen 10.1.1.1' }
408     end
409   end
410
411   describe 'server_tokens' do
412     it 'applys cleanly' do
413       pp = <<-EOS
414         class { 'apache':
415           server_tokens  => 'Minor',
416         }
417       EOS
418       apply_manifest(pp, :catch_failures => true)
419     end
420
421     describe file($conf_file) do
422       it { is_expected.to be_file }
423       it { is_expected.to contain 'ServerTokens Minor' }
424     end
425   end
426
427   describe 'server_signature' do
428     it 'applys cleanly' do
429       pp = <<-EOS
430         class { 'apache':
431           server_signature  => 'testsig',
432           service_ensure    => stopped,
433         }
434       EOS
435       apply_manifest(pp, :catch_failures => true)
436     end
437
438     describe file($conf_file) do
439       it { is_expected.to be_file }
440       it { is_expected.to contain 'ServerSignature testsig' }
441     end
442   end
443
444   describe 'trace_enable' do
445     it 'applys cleanly' do
446       pp = <<-EOS
447         class { 'apache':
448           trace_enable  => 'Off',
449         }
450       EOS
451       apply_manifest(pp, :catch_failures => true)
452     end
453
454     describe file($conf_file) do
455       it { is_expected.to be_file }
456       it { is_expected.to contain 'TraceEnable Off' }
457     end
458   end
459
460   describe 'package_ensure' do
461     it 'applys cleanly' do
462       pp = <<-EOS
463         class { 'apache':
464           package_ensure  => present,
465         }
466       EOS
467       apply_manifest(pp, :catch_failures => true)
468     end
469
470     describe package($package_name) do
471       it { is_expected.to be_installed }
472     end
473   end
474
475 end