]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/apache/spec/acceptance/vhost_spec.rb
try again, with puppetforge modules, correctly included now
[dsa-puppet.git] / 3rdparty / modules / apache / spec / acceptance / vhost_spec.rb
1 require 'spec_helper_acceptance'
2 require_relative './version.rb'
3
4 describe 'apache::vhost define', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
5   context 'no default vhosts' do
6     it 'should create no default vhosts' do
7       pp = <<-EOS
8         class { 'apache':
9           default_vhost => false,
10           default_ssl_vhost => false,
11           service_ensure => stopped
12         }
13       EOS
14
15       apply_manifest(pp, :catch_failures => true)
16     end
17
18     describe file("#{$vhost_dir}/15-default.conf") do
19       it { is_expected.not_to be_file }
20     end
21
22     describe file("#{$vhost_dir}/15-default-ssl.conf") do
23       it { is_expected.not_to be_file }
24     end
25   end
26
27   context "default vhost without ssl" do
28     it 'should create a default vhost config' do
29       pp = <<-EOS
30         class { 'apache': }
31       EOS
32
33       apply_manifest(pp, :catch_failures => true)
34     end
35
36     describe file("#{$vhost_dir}/15-default.conf") do
37       it { is_expected.to contain '<VirtualHost \*:80>' }
38     end
39
40     describe file("#{$vhost_dir}/15-default-ssl.conf") do
41       it { is_expected.not_to be_file }
42     end
43   end
44
45   context 'default vhost with ssl' do
46     it 'should create default vhost configs' do
47       pp = <<-EOS
48         file { '#{$run_dir}':
49           ensure  => 'directory',
50           recurse => true,
51         }
52
53         class { 'apache':
54           default_ssl_vhost => true,
55           require => File['#{$run_dir}'],
56         }
57       EOS
58       apply_manifest(pp, :catch_failures => true)
59     end
60
61     describe file("#{$vhost_dir}/15-default.conf") do
62       it { is_expected.to contain '<VirtualHost \*:80>' }
63     end
64
65     describe file("#{$vhost_dir}/15-default-ssl.conf") do
66       it { is_expected.to contain '<VirtualHost \*:443>' }
67       it { is_expected.to contain "SSLEngine on" }
68     end
69   end
70
71   context 'new vhost on port 80' do
72     it 'should configure an apache vhost' do
73       pp = <<-EOS
74         class { 'apache': }
75         file { '#{$run_dir}':
76           ensure  => 'directory',
77           recurse => true,
78         }
79
80         apache::vhost { 'first.example.com':
81           port    => '80',
82           docroot => '/var/www/first',
83           require => File['#{$run_dir}'],
84         }
85       EOS
86       apply_manifest(pp, :catch_failures => true)
87     end
88
89     describe file("#{$vhost_dir}/25-first.example.com.conf") do
90       it { is_expected.to contain '<VirtualHost \*:80>' }
91       it { is_expected.to contain "ServerName first.example.com" }
92     end
93   end
94
95   context 'new proxy vhost on port 80' do
96     it 'should configure an apache proxy vhost' do
97       pp = <<-EOS
98         class { 'apache': }
99         apache::vhost { 'proxy.example.com':
100           port    => '80',
101           docroot => '/var/www/proxy',
102           proxy_pass => [
103             { 'path' => '/foo', 'url' => 'http://backend-foo/'},
104           ],
105         proxy_preserve_host   => true,
106         proxy_error_override  => true,
107         }
108       EOS
109       apply_manifest(pp, :catch_failures => true)
110     end
111
112     describe file("#{$vhost_dir}/25-proxy.example.com.conf") do
113       it { is_expected.to contain '<VirtualHost \*:80>' }
114       it { is_expected.to contain "ServerName proxy.example.com" }
115       it { is_expected.to contain "ProxyPass" }
116       it { is_expected.to contain "ProxyPreserveHost On" }
117       it { is_expected.to contain "ProxyErrorOverride On" }
118       it { is_expected.not_to contain "<Proxy \*>" }
119     end
120   end
121
122   context 'new proxy vhost on port 80' do
123     it 'should configure an apache proxy vhost' do
124       pp = <<-EOS
125         class { 'apache': }
126         apache::vhost { 'proxy.example.com':
127           port    => '80',
128           docroot => '/var/www/proxy',
129           proxy_pass_match => [
130             { 'path' => '/foo', 'url' => 'http://backend-foo/'},
131           ],
132         proxy_preserve_host   => true,
133         proxy_error_override  => true,
134         }
135       EOS
136       apply_manifest(pp, :catch_failures => true)
137     end
138
139     describe file("#{$vhost_dir}/25-proxy.example.com.conf") do
140       it { is_expected.to contain '<VirtualHost \*:80>' }
141       it { is_expected.to contain "ServerName proxy.example.com" }
142       it { is_expected.to contain "ProxyPassMatch /foo http://backend-foo/" }
143       it { is_expected.to contain "ProxyPreserveHost On" }
144       it { is_expected.to contain "ProxyErrorOverride On" }
145       it { is_expected.not_to contain "<Proxy \*>" }
146     end
147   end
148
149   context 'new vhost on port 80' do
150     it 'should configure two apache vhosts' do
151       pp = <<-EOS
152         class { 'apache': }
153         apache::vhost { 'first.example.com':
154           port    => '80',
155           docroot => '/var/www/first',
156         }
157         host { 'first.example.com': ip => '127.0.0.1', }
158         file { '/var/www/first/index.html':
159           ensure  => file,
160           content => "Hello from first\\n",
161         }
162         apache::vhost { 'second.example.com':
163           port    => '80',
164           docroot => '/var/www/second',
165         }
166         host { 'second.example.com': ip => '127.0.0.1', }
167         file { '/var/www/second/index.html':
168           ensure  => file,
169           content => "Hello from second\\n",
170         }
171       EOS
172       apply_manifest(pp, :catch_failures => true)
173     end
174
175     describe service($service_name) do
176       it { is_expected.to be_enabled }
177       it { is_expected.to be_running }
178     end
179
180     it 'should answer to first.example.com' do
181       shell("/usr/bin/curl first.example.com:80", {:acceptable_exit_codes => 0}) do |r|
182         expect(r.stdout).to eq("Hello from first\n")
183       end
184     end
185
186     it 'should answer to second.example.com' do
187       shell("/usr/bin/curl second.example.com:80", {:acceptable_exit_codes => 0}) do |r|
188         expect(r.stdout).to eq("Hello from second\n")
189       end
190     end
191   end
192
193   context 'apache_directories' do
194     describe 'readme example, adapted' do
195       it 'should configure a vhost with Files' do
196         pp = <<-EOS
197           class { 'apache': }
198
199           if versioncmp($apache::apache_version, '2.4') >= 0 {
200             $_files_match_directory = { 'path' => '(\.swp|\.bak|~)$', 'provider' => 'filesmatch', 'require' => 'all denied', }
201           } else {
202             $_files_match_directory = { 'path' => '(\.swp|\.bak|~)$', 'provider' => 'filesmatch', 'deny' => 'from all', }
203           }
204
205           $_directories = [
206             { 'path' => '/var/www/files', },
207             $_files_match_directory,
208           ]
209
210           apache::vhost { 'files.example.net':
211             docroot     => '/var/www/files',
212             directories => $_directories,
213           }
214           file { '/var/www/files/index.html':
215             ensure  => file,
216             content => "Hello World\\n",
217           }
218           file { '/var/www/files/index.html.bak':
219             ensure  => file,
220             content => "Hello World\\n",
221           }
222           host { 'files.example.net': ip => '127.0.0.1', }
223         EOS
224         apply_manifest(pp, :catch_failures => true)
225       end
226
227       describe service($service_name) do
228         it { is_expected.to be_enabled }
229         it { is_expected.to be_running }
230       end
231
232       it 'should answer to files.example.net' do
233         expect(shell("/usr/bin/curl -sSf files.example.net:80/index.html").stdout).to eq("Hello World\n")
234         expect(shell("/usr/bin/curl -sSf files.example.net:80/index.html.bak", {:acceptable_exit_codes => 22}).stderr).to match(/curl: \(22\) The requested URL returned error: 403/)
235       end
236     end
237
238     describe 'other Directory options' do
239       it 'should configure a vhost with multiple Directory sections' do
240         pp = <<-EOS
241           class { 'apache': }
242
243           if versioncmp($apache::apache_version, '2.4') >= 0 {
244             $_files_match_directory = { 'path' => 'private.html$', 'provider' => 'filesmatch', 'require' => 'all denied' }
245           } else {
246             $_files_match_directory = [
247               { 'path' => 'private.html$', 'provider' => 'filesmatch', 'deny' => 'from all' },
248               { 'path' => '/bar/bar.html', 'provider' => 'location', allow => [ 'from 127.0.0.1', ] },
249             ]
250           }
251
252           $_directories = [
253             { 'path' => '/var/www/files', },
254             { 'path' => '/foo/', 'provider' => 'location', 'directoryindex' => 'notindex.html', },
255             $_files_match_directory,
256           ]
257
258           apache::vhost { 'files.example.net':
259             docroot     => '/var/www/files',
260             directories => $_directories,
261           }
262           file { '/var/www/files/foo':
263             ensure => directory,
264           }
265           file { '/var/www/files/foo/notindex.html':
266             ensure  => file,
267             content => "Hello Foo\\n",
268           }
269           file { '/var/www/files/private.html':
270             ensure  => file,
271             content => "Hello World\\n",
272           }
273           file { '/var/www/files/bar':
274             ensure => directory,
275           }
276           file { '/var/www/files/bar/bar.html':
277             ensure  => file,
278             content => "Hello Bar\\n",
279           }
280           host { 'files.example.net': ip => '127.0.0.1', }
281         EOS
282         apply_manifest(pp, :catch_failures => true)
283       end
284
285       describe service($service_name) do
286         it { is_expected.to be_enabled }
287         it { is_expected.to be_running }
288       end
289
290       it 'should answer to files.example.net' do
291         expect(shell("/usr/bin/curl -sSf files.example.net:80/").stdout).to eq("Hello World\n")
292         expect(shell("/usr/bin/curl -sSf files.example.net:80/foo/").stdout).to eq("Hello Foo\n")
293         expect(shell("/usr/bin/curl -sSf files.example.net:80/private.html", {:acceptable_exit_codes => 22}).stderr).to match(/curl: \(22\) The requested URL returned error: 403/)
294         expect(shell("/usr/bin/curl -sSf files.example.net:80/bar/bar.html").stdout).to eq("Hello Bar\n")
295       end
296     end
297
298     describe 'SetHandler directive' do
299       it 'should configure a vhost with a SetHandler directive' do
300         pp = <<-EOS
301           class { 'apache': }
302           apache::mod { 'status': }
303           host { 'files.example.net': ip => '127.0.0.1', }
304           apache::vhost { 'files.example.net':
305             docroot     => '/var/www/files',
306             directories => [
307               { path => '/var/www/files', },
308               { path => '/server-status', provider => 'location', sethandler => 'server-status', },
309             ],
310           }
311           file { '/var/www/files/index.html':
312             ensure  => file,
313             content => "Hello World\\n",
314           }
315         EOS
316         apply_manifest(pp, :catch_failures => true)
317       end
318
319       describe service($service_name) do
320         it { is_expected.to be_enabled }
321         it { is_expected.to be_running }
322       end
323
324       it 'should answer to files.example.net' do
325         expect(shell("/usr/bin/curl -sSf files.example.net:80/index.html").stdout).to eq("Hello World\n")
326         expect(shell("/usr/bin/curl -sSf files.example.net:80/server-status?auto").stdout).to match(/Scoreboard: /)
327       end
328     end
329
330     describe 'Satisfy and Auth directive', :unless => $apache_version == '2.4' do
331       it 'should configure a vhost with Satisfy and Auth directive' do
332         pp = <<-EOS
333           class { 'apache': }
334           host { 'files.example.net': ip => '127.0.0.1', }
335           apache::vhost { 'files.example.net':
336             docroot     => '/var/www/files',
337             directories => [
338               {
339                 path => '/var/www/files/foo',
340                 auth_type => 'Basic',
341                 auth_name => 'Basic Auth',
342                 auth_user_file => '/var/www/htpasswd',
343                 auth_require => "valid-user",
344               },
345               {
346                 path => '/var/www/files/bar',
347                 auth_type => 'Basic',
348                 auth_name => 'Basic Auth',
349                 auth_user_file => '/var/www/htpasswd',
350                 auth_require => 'valid-user',
351                 satisfy => 'Any',
352               },
353               {
354                 path => '/var/www/files/baz',
355                 allow => 'from 10.10.10.10',
356                 auth_type => 'Basic',
357                 auth_name => 'Basic Auth',
358                 auth_user_file => '/var/www/htpasswd',
359                 auth_require => 'valid-user',
360                 satisfy => 'Any',
361               },
362             ],
363           }
364           file { '/var/www/files/foo':
365             ensure => directory,
366           }
367           file { '/var/www/files/bar':
368             ensure => directory,
369           }
370           file { '/var/www/files/baz':
371             ensure => directory,
372           }
373           file { '/var/www/files/foo/index.html':
374             ensure  => file,
375             content => "Hello World\\n",
376           }
377           file { '/var/www/files/bar/index.html':
378             ensure  => file,
379             content => "Hello World\\n",
380           }
381           file { '/var/www/files/baz/index.html':
382             ensure  => file,
383             content => "Hello World\\n",
384           }
385           file { '/var/www/htpasswd':
386             ensure  => file,
387             content => "login:IZ7jMcLSx0oQk", # "password" as password
388           }
389         EOS
390         apply_manifest(pp, :catch_failures => true)
391       end
392
393       describe service($service_name) do
394         it { should be_enabled }
395         it { should be_running }
396       end
397
398       it 'should answer to files.example.net' do
399         shell("/usr/bin/curl -sSf files.example.net:80/foo/index.html", {:acceptable_exit_codes => 22}).stderr.should match(/curl: \(22\) The requested URL returned error: 401/)
400         shell("/usr/bin/curl -sSf -u login:password files.example.net:80/foo/index.html").stdout.should eq("Hello World\n")
401         shell("/usr/bin/curl -sSf files.example.net:80/bar/index.html").stdout.should eq("Hello World\n")
402         shell("/usr/bin/curl -sSf -u login:password files.example.net:80/bar/index.html").stdout.should eq("Hello World\n")
403         shell("/usr/bin/curl -sSf files.example.net:80/baz/index.html", {:acceptable_exit_codes => 22}).stderr.should match(/curl: \(22\) The requested URL returned error: 401/)
404         shell("/usr/bin/curl -sSf -u login:password files.example.net:80/baz/index.html").stdout.should eq("Hello World\n")
405       end
406     end
407   end
408
409   case fact('lsbdistcodename')
410   when 'precise', 'wheezy'
411     context 'vhost fallbackresource example' do
412       it 'should configure a vhost with Fallbackresource' do
413         pp = <<-EOS
414         class { 'apache': }
415         apache::vhost { 'fallback.example.net':
416           docroot         => '/var/www/fallback',
417           fallbackresource => '/index.html'
418         }
419         file { '/var/www/fallback/index.html':
420           ensure  => file,
421           content => "Hello World\\n",
422         }
423         host { 'fallback.example.net': ip => '127.0.0.1', }
424         EOS
425         apply_manifest(pp, :catch_failures => true)
426       end
427
428       describe service($service_name) do
429         it { is_expected.to be_enabled }
430         it { is_expected.to be_running }
431       end
432
433       it 'should answer to fallback.example.net' do
434         shell("/usr/bin/curl fallback.example.net:80/Does/Not/Exist") do |r|
435           expect(r.stdout).to eq("Hello World\n")
436         end
437       end
438
439     end
440   else
441     # The current stable RHEL release (6.4) comes with Apache httpd 2.2.15
442     # That was released March 6, 2010.
443     # FallbackResource was backported to 2.2.16, and released July 25, 2010.
444     # Ubuntu Lucid (10.04) comes with apache2 2.2.14, released October 3, 2009.
445     # https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x/STATUS
446   end
447
448   context 'virtual_docroot hosting separate sites' do
449     it 'should configure a vhost with VirtualDocumentRoot' do
450       pp = <<-EOS
451         class { 'apache': }
452         apache::vhost { 'virt.example.com':
453           vhost_name      => '*',
454           serveraliases   => '*virt.example.com',
455           port            => '80',
456           docroot         => '/var/www/virt',
457           virtual_docroot => '/var/www/virt/%1',
458         }
459         host { 'virt.example.com': ip => '127.0.0.1', }
460         host { 'a.virt.example.com': ip => '127.0.0.1', }
461         host { 'b.virt.example.com': ip => '127.0.0.1', }
462         file { [ '/var/www/virt/a', '/var/www/virt/b', ]: ensure => directory, }
463         file { '/var/www/virt/a/index.html': ensure  => file, content => "Hello from a.virt\\n", }
464         file { '/var/www/virt/b/index.html': ensure  => file, content => "Hello from b.virt\\n", }
465       EOS
466       apply_manifest(pp, :catch_failures => true)
467     end
468
469     describe service($service_name) do
470       it { is_expected.to be_enabled }
471       it { is_expected.to be_running }
472     end
473
474     it 'should answer to a.virt.example.com' do
475       shell("/usr/bin/curl a.virt.example.com:80", {:acceptable_exit_codes => 0}) do |r|
476         expect(r.stdout).to eq("Hello from a.virt\n")
477       end
478     end
479
480     it 'should answer to b.virt.example.com' do
481       shell("/usr/bin/curl b.virt.example.com:80", {:acceptable_exit_codes => 0}) do |r|
482         expect(r.stdout).to eq("Hello from b.virt\n")
483       end
484     end
485   end
486
487   context 'proxy_pass for alternative vhost' do
488     it 'should configure a local vhost and a proxy vhost' do
489       apply_manifest(%{
490         class { 'apache': default_vhost => false, }
491         apache::vhost { 'localhost':
492           docroot => '/var/www/local',
493           ip      => '127.0.0.1',
494           port    => '8888',
495         }
496         apache::listen { '*:80': }
497         apache::vhost { 'proxy.example.com':
498           docroot    => '/var/www',
499           port       => '80',
500           add_listen => false,
501           proxy_pass => {
502             'path' => '/',
503             'url'  => 'http://localhost:8888/subdir/',
504           },
505         }
506         host { 'proxy.example.com': ip => '127.0.0.1', }
507         file { ['/var/www/local', '/var/www/local/subdir']: ensure => directory, }
508         file { '/var/www/local/subdir/index.html':
509           ensure  => file,
510           content => "Hello from localhost\\n",
511         }
512                      }, :catch_failures => true)
513     end
514
515     describe service($service_name) do
516       it { is_expected.to be_enabled }
517       it { is_expected.to be_running }
518     end
519
520     it 'should get a response from the back end' do
521       shell("/usr/bin/curl --max-redirs 0 proxy.example.com:80") do |r|
522         expect(r.stdout).to eq("Hello from localhost\n")
523         expect(r.exit_code).to eq(0)
524       end
525     end
526   end
527
528   context 'proxy_pass_match for alternative vhost' do
529     it 'should configure a local vhost and a proxy vhost' do
530       apply_manifest(%{
531         class { 'apache': default_vhost => false, }
532         apache::vhost { 'localhost':
533           docroot => '/var/www/local',
534           ip      => '127.0.0.1',
535           port    => '8888',
536         }
537         apache::listen { '*:80': }
538         apache::vhost { 'proxy.example.com':
539           docroot    => '/var/www',
540           port       => '80',
541           add_listen => false,
542           proxy_pass_match => {
543             'path' => '/',
544             'url'  => 'http://localhost:8888/subdir/',
545           },
546         }
547         host { 'proxy.example.com': ip => '127.0.0.1', }
548         file { ['/var/www/local', '/var/www/local/subdir']: ensure => directory, }
549         file { '/var/www/local/subdir/index.html':
550           ensure  => file,
551           content => "Hello from localhost\\n",
552         }
553                      }, :catch_failures => true)
554     end
555
556     describe service($service_name) do
557       it { is_expected.to be_enabled }
558       it { is_expected.to be_running }
559     end
560
561     it 'should get a response from the back end' do
562       shell("/usr/bin/curl --max-redirs 0 proxy.example.com:80") do |r|
563         expect(r.stdout).to eq("Hello from localhost\n")
564         expect(r.exit_code).to eq(0)
565       end
566     end
567   end
568
569   describe 'ip_based' do
570     it 'applies cleanly' do
571       pp = <<-EOS
572         class { 'apache': }
573         host { 'test.server': ip => '127.0.0.1' }
574         apache::vhost { 'test.server':
575           docroot    => '/tmp',
576           ip_based   => true,
577           servername => 'test.server',
578         }
579       EOS
580       apply_manifest(pp, :catch_failures => true)
581     end
582
583     describe file($ports_file) do
584       it { is_expected.to be_file }
585       it { is_expected.not_to contain 'NameVirtualHost test.server' }
586     end
587   end
588
589   describe 'add_listen' do
590     it 'applies cleanly' do
591       pp = <<-EOS
592         class { 'apache': default_vhost => false }
593         host { 'testlisten.server': ip => '127.0.0.1' }
594         apache::listen { '81': }
595         apache::vhost { 'testlisten.server':
596           docroot    => '/tmp',
597           port       => '80',
598           add_listen => false,
599           servername => 'testlisten.server',
600         }
601       EOS
602       apply_manifest(pp, :catch_failures => true)
603     end
604
605     describe file($ports_file) do
606       it { is_expected.to be_file }
607       it { is_expected.not_to contain 'Listen 80' }
608       it { is_expected.to contain 'Listen 81' }
609     end
610   end
611
612   describe 'docroot' do
613     it 'applies cleanly' do
614       pp = <<-EOS
615         user { 'test_owner': ensure => present, }
616         group { 'test_group': ensure => present, }
617         class { 'apache': }
618         host { 'test.server': ip => '127.0.0.1' }
619         apache::vhost { 'test.server':
620           docroot       => '/tmp/test',
621           docroot_owner => 'test_owner',
622           docroot_group => 'test_group',
623           docroot_mode  => '0750',
624         }
625       EOS
626       apply_manifest(pp, :catch_failures => true)
627     end
628
629     describe file('/tmp/test') do
630       it { is_expected.to be_directory }
631       it { is_expected.to be_owned_by 'test_owner' }
632       it { is_expected.to be_grouped_into 'test_group' }
633       it { is_expected.to be_mode 750 }
634     end
635   end
636
637   describe 'default_vhost' do
638     it 'applies cleanly' do
639       pp = <<-EOS
640         class { 'apache': }
641         host { 'test.server': ip => '127.0.0.1' }
642         apache::vhost { 'test.server':
643           docroot    => '/tmp',
644           default_vhost => true,
645         }
646       EOS
647       apply_manifest(pp, :catch_failures => true)
648     end
649
650     describe file($ports_file) do
651       it { is_expected.to be_file }
652       if fact('osfamily') == 'RedHat' and fact('operatingsystemmajrelease') == '7'
653         it { is_expected.not_to contain 'NameVirtualHost test.server' }
654       elsif fact('operatingsystem') == 'Ubuntu' and fact('operatingsystemrelease') =~ /(14\.04|13\.10)/
655         it { is_expected.not_to contain 'NameVirtualHost test.server' }
656       else
657         it { is_expected.to contain 'NameVirtualHost test.server' }
658       end
659     end
660
661     describe file("#{$vhost_dir}/10-test.server.conf") do
662       it { is_expected.to be_file }
663     end
664   end
665
666   describe 'options' do
667     it 'applies cleanly' do
668       pp = <<-EOS
669         class { 'apache': }
670         host { 'test.server': ip => '127.0.0.1' }
671         apache::vhost { 'test.server':
672           docroot    => '/tmp',
673           options    => ['Indexes','FollowSymLinks', 'ExecCGI'],
674         }
675       EOS
676       apply_manifest(pp, :catch_failures => true)
677     end
678
679     describe file("#{$vhost_dir}/25-test.server.conf") do
680       it { is_expected.to be_file }
681       it { is_expected.to contain 'Options Indexes FollowSymLinks ExecCGI' }
682     end
683   end
684
685   describe 'override' do
686     it 'applies cleanly' do
687       pp = <<-EOS
688         class { 'apache': }
689         host { 'test.server': ip => '127.0.0.1' }
690         apache::vhost { 'test.server':
691           docroot    => '/tmp',
692           override   => ['All'],
693         }
694       EOS
695       apply_manifest(pp, :catch_failures => true)
696     end
697
698     describe file("#{$vhost_dir}/25-test.server.conf") do
699       it { is_expected.to be_file }
700       it { is_expected.to contain 'AllowOverride All' }
701     end
702   end
703
704   describe 'logroot' do
705     it 'applies cleanly' do
706       pp = <<-EOS
707         class { 'apache': }
708         host { 'test.server': ip => '127.0.0.1' }
709         apache::vhost { 'test.server':
710           docroot    => '/tmp',
711           logroot    => '/tmp',
712         }
713       EOS
714       apply_manifest(pp, :catch_failures => true)
715     end
716
717     describe file("#{$vhost_dir}/25-test.server.conf") do
718       it { is_expected.to be_file }
719       it { is_expected.to contain '  CustomLog "/tmp' }
720     end
721   end
722
723   ['access', 'error'].each do |logtype|
724     case logtype
725     when 'access'
726       logname = 'CustomLog'
727     when 'error'
728       logname = 'ErrorLog'
729     end
730
731     describe "#{logtype}_log" do
732       it 'applies cleanly' do
733         pp = <<-EOS
734           class { 'apache': }
735           host { 'test.server': ip => '127.0.0.1' }
736           apache::vhost { 'test.server':
737             docroot    => '/tmp',
738             logroot    => '/tmp',
739         #{logtype}_log => false,
740           }
741         EOS
742         apply_manifest(pp, :catch_failures => true)
743       end
744
745       describe file("#{$vhost_dir}/25-test.server.conf") do
746         it { is_expected.to be_file }
747         it { is_expected.not_to contain "  #{logname} \"/tmp" }
748       end
749     end
750
751     describe "#{logtype}_log_pipe" do
752       it 'applies cleanly' do
753         pp = <<-EOS
754           class { 'apache': }
755           host { 'test.server': ip => '127.0.0.1' }
756           apache::vhost { 'test.server':
757             docroot    => '/tmp',
758             logroot    => '/tmp',
759         #{logtype}_log_pipe => '|/bin/sh',
760           }
761         EOS
762         apply_manifest(pp, :catch_failures => true)
763       end
764
765       describe file("#{$vhost_dir}/25-test.server.conf") do
766         it { is_expected.to be_file }
767         it { is_expected.to contain "  #{logname} \"|/bin/sh" }
768       end
769     end
770
771     describe "#{logtype}_log_syslog" do
772       it 'applies cleanly' do
773         pp = <<-EOS
774           class { 'apache': }
775           host { 'test.server': ip => '127.0.0.1' }
776           apache::vhost { 'test.server':
777             docroot    => '/tmp',
778             logroot    => '/tmp',
779         #{logtype}_log_syslog => 'syslog',
780           }
781         EOS
782         apply_manifest(pp, :catch_failures => true)
783       end
784
785       describe file("#{$vhost_dir}/25-test.server.conf") do
786         it { is_expected.to be_file }
787         it { is_expected.to contain "  #{logname} \"syslog\"" }
788       end
789     end
790   end
791
792   describe 'access_log_format' do
793     it 'applies cleanly' do
794       pp = <<-EOS
795         class { 'apache': }
796         host { 'test.server': ip => '127.0.0.1' }
797         apache::vhost { 'test.server':
798           docroot    => '/tmp',
799           logroot    => '/tmp',
800           access_log_syslog => 'syslog',
801           access_log_format => '%h %l',
802         }
803       EOS
804       apply_manifest(pp, :catch_failures => true)
805     end
806
807     describe file("#{$vhost_dir}/25-test.server.conf") do
808       it { is_expected.to be_file }
809       it { is_expected.to contain 'CustomLog "syslog" "%h %l"' }
810     end
811   end
812
813   describe 'access_log_env_var' do
814     it 'applies cleanly' do
815       pp = <<-EOS
816         class { 'apache': }
817         host { 'test.server': ip => '127.0.0.1' }
818         apache::vhost { 'test.server':
819           docroot            => '/tmp',
820           logroot            => '/tmp',
821           access_log_syslog  => 'syslog',
822           access_log_env_var => 'admin',
823         }
824       EOS
825       apply_manifest(pp, :catch_failures => true)
826     end
827
828     describe file("#{$vhost_dir}/25-test.server.conf") do
829       it { is_expected.to be_file }
830       it { is_expected.to contain 'CustomLog "syslog" combined env=admin' }
831     end
832   end
833
834   describe 'multiple access_logs' do
835     it 'applies cleanly' do
836       pp = <<-EOS
837         class { 'apache': }
838         host { 'test.server': ip => '127.0.0.1' }
839         apache::vhost { 'test.server':
840           docroot            => '/tmp',
841           logroot            => '/tmp',
842           access_logs => [
843             {'file' => 'log1'},
844             {'file' => 'log2', 'env' => 'admin' },
845             {'file' => '/var/tmp/log3', 'format' => '%h %l'},
846             {'syslog' => 'syslog' }
847           ]
848         }
849       EOS
850       apply_manifest(pp, :catch_failures => true)
851     end
852
853     describe file("#{$vhost_dir}/25-test.server.conf") do
854       it { is_expected.to be_file }
855       it { is_expected.to contain 'CustomLog "/tmp/log1" combined' }
856       it { is_expected.to contain 'CustomLog "/tmp/log2" combined env=admin' }
857       it { is_expected.to contain 'CustomLog "/var/tmp/log3" "%h %l"' }
858       it { is_expected.to contain 'CustomLog "syslog" combined' }
859     end
860   end
861
862   describe 'aliases' do
863     it 'applies cleanly' do
864       pp = <<-EOS
865         class { 'apache': }
866         host { 'test.server': ip => '127.0.0.1' }
867         apache::vhost { 'test.server':
868           docroot    => '/tmp',
869           aliases => [
870             { alias       => '/image'    , path => '/ftp/pub/image' }   ,
871             { scriptalias => '/myscript' , path => '/usr/share/myscript' }
872           ],
873         }
874       EOS
875       apply_manifest(pp, :catch_failures => true)
876     end
877
878     describe file("#{$vhost_dir}/25-test.server.conf") do
879       it { is_expected.to be_file }
880       it { is_expected.to contain 'Alias /image "/ftp/pub/image"' }
881       it { is_expected.to contain 'ScriptAlias /myscript "/usr/share/myscript"' }
882     end
883   end
884
885   describe 'scriptaliases' do
886     it 'applies cleanly' do
887       pp = <<-EOS
888         class { 'apache': }
889         host { 'test.server': ip => '127.0.0.1' }
890         apache::vhost { 'test.server':
891           docroot    => '/tmp',
892           scriptaliases => [{ alias => '/myscript', path  => '/usr/share/myscript', }],
893         }
894       EOS
895       apply_manifest(pp, :catch_failures => true)
896     end
897
898     describe file("#{$vhost_dir}/25-test.server.conf") do
899       it { is_expected.to be_file }
900       it { is_expected.to contain 'ScriptAlias /myscript "/usr/share/myscript"' }
901     end
902   end
903
904   describe 'proxy' do
905     it 'applies cleanly' do
906       pp = <<-EOS
907         class { 'apache': service_ensure => stopped, }
908         host { 'test.server': ip => '127.0.0.1' }
909         apache::vhost { 'test.server':
910           docroot    => '/tmp',
911           proxy_dest => 'test2',
912         }
913       EOS
914       apply_manifest(pp, :catch_failures => true)
915     end
916
917     describe file("#{$vhost_dir}/25-test.server.conf") do
918       it { is_expected.to be_file }
919       it { is_expected.to contain 'ProxyPass          / test2/' }
920     end
921   end
922
923   describe 'actions' do
924     it 'applies cleanly' do
925       pp = <<-EOS
926         class { 'apache': }
927         host { 'test.server': ip => '127.0.0.1' }
928         apache::vhost { 'test.server':
929           docroot => '/tmp',
930           action  => 'php-fastcgi',
931         }
932       EOS
933       pp = pp + "\nclass { 'apache::mod::actions': }" if fact('osfamily') == 'Debian'
934       apply_manifest(pp, :catch_failures => true)
935     end
936
937     describe file("#{$vhost_dir}/25-test.server.conf") do
938       it { is_expected.to be_file }
939       it { is_expected.to contain 'Action php-fastcgi /cgi-bin virtual' }
940     end
941   end
942
943   describe 'suphp' do
944     it 'applies cleanly' do
945       pp = <<-EOS
946         class { 'apache': service_ensure => stopped, }
947         host { 'test.server': ip => '127.0.0.1' }
948         apache::vhost { 'test.server':
949           docroot          => '/tmp',
950           suphp_addhandler => '#{$suphp_handler}',
951           suphp_engine     => 'on',
952           suphp_configpath => '#{$suphp_configpath}',
953         }
954       EOS
955       apply_manifest(pp, :catch_failures => true)
956     end
957
958     describe file("#{$vhost_dir}/25-test.server.conf") do
959       it { is_expected.to be_file }
960       it { is_expected.to contain "suPHP_AddHandler #{$suphp_handler}" }
961       it { is_expected.to contain 'suPHP_Engine on' }
962       it { is_expected.to contain "suPHP_ConfigPath \"#{$suphp_configpath}\"" }
963     end
964   end
965
966   describe 'no_proxy_uris' do
967     it 'applies cleanly' do
968       pp = <<-EOS
969         class { 'apache': service_ensure => stopped, }
970         host { 'test.server': ip => '127.0.0.1' }
971         apache::vhost { 'test.server':
972           docroot          => '/tmp',
973           proxy_dest       => 'http://test2',
974           no_proxy_uris    => [ 'http://test2/test' ],
975         }
976       EOS
977       apply_manifest(pp, :catch_failures => true)
978     end
979
980     describe file("#{$vhost_dir}/25-test.server.conf") do
981       it { is_expected.to be_file }
982       it { is_expected.to contain 'ProxyPass          / http://test2/' }
983       it { is_expected.to contain 'ProxyPass        http://test2/test !' }
984     end
985   end
986
987   describe 'redirect' do
988     it 'applies cleanly' do
989       pp = <<-EOS
990         class { 'apache': }
991         host { 'test.server': ip => '127.0.0.1' }
992         apache::vhost { 'test.server':
993           docroot          => '/tmp',
994           redirect_source  => ['/images'],
995           redirect_dest    => ['http://test.server/'],
996           redirect_status  => ['permanent'],
997         }
998       EOS
999       apply_manifest(pp, :catch_failures => true)
1000     end
1001
1002     describe file("#{$vhost_dir}/25-test.server.conf") do
1003       it { is_expected.to be_file }
1004       it { is_expected.to contain 'Redirect permanent /images http://test.server/' }
1005     end
1006   end
1007
1008   # Passenger isn't even in EPEL on el-5
1009   if default['platform'] !~ /^el-5/
1010     if fact('osfamily') == 'RedHat' and fact('operatingsystemmajrelease') == '7'
1011       pending('Since we don\'t have passenger on RHEL7 rack_base_uris tests will fail')
1012     else
1013       describe 'rack_base_uris' do
1014         if fact('osfamily') == 'RedHat'
1015           it 'adds epel' do
1016             pp = "class { 'epel': }"
1017             apply_manifest(pp, :catch_failures => true)
1018           end
1019         end
1020
1021         it 'applies cleanly' do
1022           pp = <<-EOS
1023             class { 'apache': }
1024             host { 'test.server': ip => '127.0.0.1' }
1025             apache::vhost { 'test.server':
1026               docroot          => '/tmp',
1027               rack_base_uris  => ['/test'],
1028             }
1029           EOS
1030           apply_manifest(pp, :catch_failures => true)
1031         end
1032
1033         describe file("#{$vhost_dir}/25-test.server.conf") do
1034           it { is_expected.to be_file }
1035           it { is_expected.to contain 'RackBaseURI /test' }
1036         end
1037       end
1038     end
1039   end
1040
1041
1042   describe 'request_headers' do
1043     it 'applies cleanly' do
1044       pp = <<-EOS
1045         class { 'apache': }
1046         host { 'test.server': ip => '127.0.0.1' }
1047         apache::vhost { 'test.server':
1048           docroot          => '/tmp',
1049           request_headers  => ['append MirrorID "mirror 12"'],
1050         }
1051       EOS
1052       apply_manifest(pp, :catch_failures => true)
1053     end
1054
1055     describe file("#{$vhost_dir}/25-test.server.conf") do
1056       it { is_expected.to be_file }
1057       it { is_expected.to contain 'append MirrorID "mirror 12"' }
1058     end
1059   end
1060
1061   describe 'rewrite rules' do
1062     it 'applies cleanly' do
1063       pp = <<-EOS
1064         class { 'apache': }
1065         host { 'test.server': ip => '127.0.0.1' }
1066         apache::vhost { 'test.server':
1067           docroot          => '/tmp',
1068           rewrites => [
1069             { comment => 'test',
1070               rewrite_cond => '%{HTTP_USER_AGENT} ^Lynx/ [OR]',
1071               rewrite_rule => ['^index\.html$ welcome.html'],
1072               rewrite_map  => ['lc int:tolower'],
1073             }
1074           ],
1075         }
1076       EOS
1077       apply_manifest(pp, :catch_failures => true)
1078     end
1079
1080     describe file("#{$vhost_dir}/25-test.server.conf") do
1081       it { is_expected.to be_file }
1082       it { is_expected.to contain '#test' }
1083       it { is_expected.to contain 'RewriteCond %{HTTP_USER_AGENT} ^Lynx/ [OR]' }
1084       it { is_expected.to contain 'RewriteRule ^index.html$ welcome.html' }
1085       it { is_expected.to contain 'RewriteMap lc int:tolower' }
1086     end
1087   end
1088
1089   describe 'directory rewrite rules' do
1090     it 'applies cleanly' do
1091       pp = <<-EOS
1092         class { 'apache': }
1093         host { 'test.server': ip => '127.0.0.1' }
1094         if ! defined(Class['apache::mod::rewrite']) {
1095           include ::apache::mod::rewrite
1096         }
1097         apache::vhost { 'test.server':
1098           docroot      => '/tmp',
1099           directories  => [
1100             {
1101             path => '/tmp',
1102             rewrites => [
1103               {
1104               comment => 'Permalink Rewrites',
1105               rewrite_base => '/',
1106               },
1107               { rewrite_rule => [ '^index\\.php$ - [L]' ] },
1108               { rewrite_cond => [
1109                 '%{REQUEST_FILENAME} !-f',
1110                 '%{REQUEST_FILENAME} !-d',                                                                                             ],                                                                                                                     rewrite_rule => [ '. /index.php [L]' ],                                                                              }
1111               ],
1112             },
1113             ],
1114         }
1115       EOS
1116       apply_manifest(pp, :catch_failures => true)
1117     end
1118
1119     describe file("#{$vhost_dir}/25-test.server.conf") do
1120       it { should be_file }
1121       it { should contain '#Permalink Rewrites' }
1122       it { should contain 'RewriteEngine On' }
1123       it { should contain 'RewriteBase /' }
1124       it { should contain 'RewriteRule ^index\.php$ - [L]' }
1125       it { should contain 'RewriteCond %{REQUEST_FILENAME} !-f' }
1126       it { should contain 'RewriteCond %{REQUEST_FILENAME} !-d' }
1127       it { should contain 'RewriteRule . /index.php [L]' }
1128     end
1129   end
1130
1131   describe 'setenv/setenvif' do
1132     it 'applies cleanly' do
1133       pp = <<-EOS
1134         class { 'apache': }
1135         host { 'test.server': ip => '127.0.0.1' }
1136         apache::vhost { 'test.server':
1137           docroot  => '/tmp',
1138           setenv   => ['TEST /test'],
1139           setenvif => ['Request_URI "\.gif$" object_is_image=gif']
1140         }
1141       EOS
1142       apply_manifest(pp, :catch_failures => true)
1143     end
1144
1145     describe file("#{$vhost_dir}/25-test.server.conf") do
1146       it { is_expected.to be_file }
1147       it { is_expected.to contain 'SetEnv TEST /test' }
1148       it { is_expected.to contain 'SetEnvIf Request_URI "\.gif$" object_is_image=gif' }
1149     end
1150   end
1151
1152   describe 'block' do
1153     it 'applies cleanly' do
1154       pp = <<-EOS
1155         class { 'apache': }
1156         host { 'test.server': ip => '127.0.0.1' }
1157         apache::vhost { 'test.server':
1158           docroot  => '/tmp',
1159           block    => 'scm',
1160         }
1161       EOS
1162       apply_manifest(pp, :catch_failures => true)
1163     end
1164
1165     describe file("#{$vhost_dir}/25-test.server.conf") do
1166       it { is_expected.to be_file }
1167       it { is_expected.to contain '<DirectoryMatch .*\.(svn|git|bzr)/.*>' }
1168     end
1169   end
1170
1171   describe 'wsgi' do
1172     it 'import_script applies cleanly' do
1173       pp = <<-EOS
1174         class { 'apache': }
1175         class { 'apache::mod::wsgi': }
1176         host { 'test.server': ip => '127.0.0.1' }
1177         apache::vhost { 'test.server':
1178           docroot                     => '/tmp',
1179           wsgi_application_group      => '%{GLOBAL}',
1180           wsgi_daemon_process         => 'wsgi',
1181           wsgi_daemon_process_options => {processes => '2'},
1182           wsgi_process_group          => 'nobody',
1183           wsgi_script_aliases         => { '/test' => '/test1' },
1184           wsgi_pass_authorization     => 'On',
1185         }
1186       EOS
1187       apply_manifest(pp, :catch_failures => true)
1188     end
1189
1190     it 'import_script applies cleanly', :unless => (fact('lsbdistcodename') == 'lucid' or UNSUPPORTED_PLATFORMS.include?(fact('osfamily'))) do
1191       pp = <<-EOS
1192         class { 'apache': }
1193         class { 'apache::mod::wsgi': }
1194         host { 'test.server': ip => '127.0.0.1' }
1195         apache::vhost { 'test.server':
1196           docroot                     => '/tmp',
1197           wsgi_application_group      => '%{GLOBAL}',
1198           wsgi_daemon_process         => 'wsgi',
1199           wsgi_daemon_process_options => {processes => '2'},
1200           wsgi_import_script          => '/test1',
1201           wsgi_import_script_options  => { application-group => '%{GLOBAL}', process-group => 'wsgi' },
1202           wsgi_process_group          => 'nobody',
1203           wsgi_script_aliases         => { '/test' => '/test1' },
1204           wsgi_pass_authorization     => 'On',
1205           wsgi_chunked_request        => 'On',
1206         }
1207       EOS
1208       apply_manifest(pp, :catch_failures => true)
1209     end
1210
1211     describe file("#{$vhost_dir}/25-test.server.conf"), :unless => (fact('lsbdistcodename') == 'lucid' or UNSUPPORTED_PLATFORMS.include?(fact('osfamily'))) do
1212       it { is_expected.to be_file }
1213       it { is_expected.to contain 'WSGIApplicationGroup %{GLOBAL}' }
1214       it { is_expected.to contain 'WSGIDaemonProcess wsgi processes=2' }
1215       it { is_expected.to contain 'WSGIImportScript /test1 application-group=%{GLOBAL} process-group=wsgi' }
1216       it { is_expected.to contain 'WSGIProcessGroup nobody' }
1217       it { is_expected.to contain 'WSGIScriptAlias /test "/test1"' }
1218       it { is_expected.to contain 'WSGIPassAuthorization On' }
1219       it { is_expected.to contain 'WSGIChunkedRequest On' }
1220     end
1221   end
1222
1223   describe 'custom_fragment' do
1224     it 'applies cleanly' do
1225       pp = <<-EOS
1226         class { 'apache': }
1227         host { 'test.server': ip => '127.0.0.1' }
1228         apache::vhost { 'test.server':
1229           docroot  => '/tmp',
1230           custom_fragment => inline_template('#weird test string'),
1231         }
1232       EOS
1233       apply_manifest(pp, :catch_failures => true)
1234     end
1235
1236     describe file("#{$vhost_dir}/25-test.server.conf") do
1237       it { is_expected.to be_file }
1238       it { is_expected.to contain '#weird test string' }
1239     end
1240   end
1241
1242   describe 'itk' do
1243     it 'applies cleanly' do
1244       pp = <<-EOS
1245         class { 'apache': }
1246         host { 'test.server': ip => '127.0.0.1' }
1247         apache::vhost { 'test.server':
1248           docroot  => '/tmp',
1249           itk      => { user => 'nobody', group => 'nobody' }
1250         }
1251       EOS
1252       apply_manifest(pp, :catch_failures => true)
1253     end
1254
1255     describe file("#{$vhost_dir}/25-test.server.conf") do
1256       it { is_expected.to be_file }
1257       it { is_expected.to contain 'AssignUserId nobody nobody' }
1258     end
1259   end
1260
1261   # So what does this work on?
1262   if default['platform'] !~ /^(debian-(6|7)|el-(5|6|7))/
1263     describe 'fastcgi' do
1264       it 'applies cleanly' do
1265         pp = <<-EOS
1266           class { 'apache': }
1267           class { 'apache::mod::fastcgi': }
1268           host { 'test.server': ip => '127.0.0.1' }
1269           apache::vhost { 'test.server':
1270             docroot        => '/tmp',
1271             fastcgi_server => 'localhost',
1272             fastcgi_socket => '/tmp/fast/1234',
1273             fastcgi_dir    => '/tmp/fast',
1274           }
1275         EOS
1276         apply_manifest(pp, :catch_failures => true)
1277       end
1278
1279       describe file("#{$vhost_dir}/25-test.server.conf") do
1280         it { is_expected.to be_file }
1281         it { is_expected.to contain 'FastCgiExternalServer localhost -socket /tmp/fast/1234' }
1282         it { is_expected.to contain '<Directory "/tmp/fast">' }
1283       end
1284     end
1285   end
1286
1287   describe 'additional_includes' do
1288     it 'applies cleanly' do
1289       pp = <<-EOS
1290         if $::osfamily == 'RedHat' and $::selinux {
1291           $semanage_package = $::operatingsystemmajrelease ? {
1292             '5'     => 'policycoreutils',
1293             default => 'policycoreutils-python',
1294           }
1295           exec { 'set_apache_defaults':
1296             command => 'semanage fcontext -a -t httpd_sys_content_t "/apache_spec(/.*)?"',
1297             path    => '/bin:/usr/bin/:/sbin:/usr/sbin',
1298             require => Package[$semanage_package],
1299           }
1300           package { $semanage_package: ensure => installed }
1301           exec { 'restorecon_apache':
1302             command => 'restorecon -Rv /apache_spec',
1303             path    => '/bin:/usr/bin/:/sbin:/usr/sbin',
1304             before  => Service['httpd'],
1305             require => Class['apache'],
1306           }
1307         }
1308         class { 'apache': }
1309         host { 'test.server': ip => '127.0.0.1' }
1310         file { '/apache_spec': ensure => directory, }
1311         file { '/apache_spec/include': ensure => present, content => '#additional_includes' }
1312         apache::vhost { 'test.server':
1313           docroot             => '/apache_spec',
1314           additional_includes => '/apache_spec/include',
1315         }
1316       EOS
1317       apply_manifest(pp, :catch_failures => true)
1318     end
1319
1320     describe file("#{$vhost_dir}/25-test.server.conf") do
1321       it { is_expected.to be_file }
1322       it { is_expected.to contain 'Include "/apache_spec/include"' }
1323     end
1324   end
1325
1326   describe 'virtualhost without priority prefix' do
1327     it 'applies cleanly' do
1328       pp = <<-EOS
1329         class { 'apache': }
1330         apache::vhost { 'test.server':
1331           priority => false,
1332           docroot => '/tmp'
1333         }
1334       EOS
1335       apply_manifest(pp, :catch_failures => true)
1336     end
1337
1338     describe file("#{$vhost_dir}/test.server.conf") do
1339       it { is_expected.to be_file }
1340     end
1341   end
1342 end