1 require 'spec_helper_acceptance'
2 require_relative './version.rb'
4 describe 'apache parameters', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
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)
13 if fact('osfamily') == 'FreeBSD'
14 describe file("#{$confd_dir}/no-accf.conf.erb") do
15 it { is_expected.not_to be_file }
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)
25 if fact('osfamily') == 'FreeBSD'
26 describe file("#{$confd_dir}/no-accf.conf.erb") do
27 it { is_expected.to be_file }
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)
38 describe file($ports_file) do
39 it { is_expected.to be_file }
40 it { is_expected.to contain 'Listen 10.1.1.1' }
44 describe 'service tests => true' do
45 it 'starts the service' do
48 service_enable => true,
49 service_manage => true,
50 service_ensure => running,
53 apply_manifest(pp, :catch_failures => true)
56 describe service($service_name) do
57 it { is_expected.to be_running }
58 it { is_expected.to be_enabled }
62 describe 'service tests => false' do
63 it 'stops the service' do
66 service_enable => false,
67 service_ensure => stopped,
70 apply_manifest(pp, :catch_failures => true)
73 describe service($service_name) do
74 it { is_expected.not_to be_running }
75 it { is_expected.not_to be_enabled }
79 describe 'service manage => false' do
80 it 'we dont manage the service, so it shouldnt start the service' do
83 service_enable => true,
84 service_manage => false,
85 service_ensure => true,
88 apply_manifest(pp, :catch_failures => true)
91 describe service($service_name) do
92 it { is_expected.not_to be_running }
93 it { is_expected.not_to be_enabled }
97 describe 'purge parameters => false' do
98 it 'applies cleanly' do
101 purge_configs => false,
102 purge_vhost_dir => false,
103 vhost_dir => "#{$confd_dir}.vhosts"
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)
111 # Ensure the files didn't disappear.
112 describe file("#{$confd_dir}/test.conf") do
113 it { is_expected.to be_file }
115 describe file("#{$confd_dir}.vhosts/test.conf") do
116 it { is_expected.to be_file }
120 if fact('osfamily') != 'Debian'
121 describe 'purge parameters => true' do
122 it 'applies cleanly' do
125 purge_configs => true,
126 purge_vhost_dir => true,
127 vhost_dir => "#{$confd_dir}.vhosts"
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)
135 # File should be gone
136 describe file("#{$confd_dir}/test.conf") do
137 it { is_expected.not_to be_file }
139 describe file("#{$confd_dir}.vhosts/test.conf") do
140 it { is_expected.not_to be_file }
145 describe 'serveradmin' do
146 it 'applies cleanly' do
147 pp = "class { 'apache': serveradmin => 'test@example.com' }"
148 apply_manifest(pp, :catch_failures => true)
151 describe file($vhost) do
152 it { is_expected.to be_file }
153 it { is_expected.to contain 'ServerAdmin test@example.com' }
157 describe 'sendfile' do
159 it 'applies cleanly' do
160 pp = "class { 'apache': sendfile => 'On' }"
161 apply_manifest(pp, :catch_failures => true)
165 describe file($conf_file) do
166 it { is_expected.to be_file }
167 it { is_expected.to contain 'EnableSendfile On' }
171 it 'applies cleanly' do
172 pp = "class { 'apache': sendfile => 'Off' }"
173 apply_manifest(pp, :catch_failures => true)
177 describe file($conf_file) do
178 it { is_expected.to be_file }
179 it { is_expected.to contain 'Sendfile Off' }
183 describe 'error_documents' do
185 it 'applies cleanly' do
186 pp = "class { 'apache': error_documents => true }"
187 apply_manifest(pp, :catch_failures => true)
191 describe file($conf_file) do
192 it { is_expected.to be_file }
193 it { is_expected.to contain 'Alias /error/' }
197 describe 'timeout' do
199 it 'applies cleanly' do
200 pp = "class { 'apache': timeout => '1234' }"
201 apply_manifest(pp, :catch_failures => true)
205 describe file($conf_file) do
206 it { is_expected.to be_file }
207 it { is_expected.to contain 'Timeout 1234' }
211 describe 'httpd_dir' do
213 it 'applies cleanly' do
215 class { 'apache': httpd_dir => '/tmp', service_ensure => stopped }
216 include 'apache::mod::mime'
218 apply_manifest(pp, :catch_failures => true)
222 describe file("#{$mod_dir}/mime.conf") do
223 it { is_expected.to be_file }
224 it { is_expected.to contain 'AddLanguage eo .eo' }
228 describe 'server_root' do
230 it 'applies cleanly' do
231 pp = "class { 'apache': server_root => '/tmp/root', service_ensure => stopped }"
232 apply_manifest(pp, :catch_failures => true)
236 describe file($conf_file) do
237 it { is_expected.to be_file }
238 it { is_expected.to contain 'ServerRoot "/tmp/root"' }
242 describe 'confd_dir' 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)
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"' }
256 describe file($conf_file) do
257 it { is_expected.to be_file }
258 it { is_expected.to contain 'Include "/tmp/root/*.conf"' }
263 describe 'conf_template' 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)
273 describe file($conf_file) do
274 it { is_expected.to be_file }
275 it { is_expected.to contain 'testcontent' }
279 describe 'servername' do
281 it 'applies cleanly' do
282 pp = "class { 'apache': servername => 'test.server', service_ensure => stopped }"
283 apply_manifest(pp, :catch_failures => true)
287 describe file($conf_file) do
288 it { is_expected.to be_file }
289 it { is_expected.to contain 'ServerName "test.server"' }
295 it 'applies cleanly' do
299 manage_group => true,
304 apply_manifest(pp, :catch_failures => true)
308 describe user('testweb') do
309 it { is_expected.to exist }
310 it { is_expected.to belong_to_group 'testweb' }
313 describe group('testweb') do
314 it { is_expected.to exist }
318 describe 'logformats' do
320 it 'applies cleanly' do
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\\\"',
329 apply_manifest(pp, :catch_failures => true)
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' }
341 describe 'keepalive' 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)
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' }
357 describe 'logging' do
359 it 'applies cleanly' do
361 if $::osfamily == 'RedHat' and $::selinux {
362 $semanage_package = $::operatingsystemmajrelease ? {
363 '5' => 'policycoreutils',
364 default => 'policycoreutils-python',
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],
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'],
380 file { '/apache_spec': ensure => directory, }
381 class { 'apache': logroot => '/apache_spec' }
383 apply_manifest(pp, :catch_failures => true)
387 describe file("/apache_spec/#{$error_log}") do
388 it { is_expected.to be_file }
392 describe 'ports_file' do
393 it 'applys cleanly' do
395 file { '/apache_spec': ensure => directory, }
397 ports_file => '/apache_spec/ports_file',
399 service_ensure => stopped
402 apply_manifest(pp, :catch_failures => true)
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' }
411 describe 'server_tokens' do
412 it 'applys cleanly' do
415 server_tokens => 'Minor',
418 apply_manifest(pp, :catch_failures => true)
421 describe file($conf_file) do
422 it { is_expected.to be_file }
423 it { is_expected.to contain 'ServerTokens Minor' }
427 describe 'server_signature' do
428 it 'applys cleanly' do
431 server_signature => 'testsig',
432 service_ensure => stopped,
435 apply_manifest(pp, :catch_failures => true)
438 describe file($conf_file) do
439 it { is_expected.to be_file }
440 it { is_expected.to contain 'ServerSignature testsig' }
444 describe 'trace_enable' do
445 it 'applys cleanly' do
448 trace_enable => 'Off',
451 apply_manifest(pp, :catch_failures => true)
454 describe file($conf_file) do
455 it { is_expected.to be_file }
456 it { is_expected.to contain 'TraceEnable Off' }
460 describe 'package_ensure' do
461 it 'applys cleanly' do
464 package_ensure => present,
467 apply_manifest(pp, :catch_failures => true)
470 describe package($package_name) do
471 it { is_expected.to be_installed }