comparison modules/apache/spec/acceptance/vhost_spec.rb @ 0:956e484adc12

Initial public release of Puppet configs
author IBBoard <dev@ibboard.co.uk>
date Sat, 16 Aug 2014 19:47:38 +0000
parents
children 37675581a273
comparison
equal deleted inserted replaced
-1:000000000000 0:956e484adc12
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 { should_not be_file }
20 end
21
22 describe file("#{$vhost_dir}/15-default-ssl.conf") do
23 it { should_not 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 { should contain '<VirtualHost \*:80>' }
38 end
39
40 describe file("#{$vhost_dir}/15-default-ssl.conf") do
41 it { should_not 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 { should contain '<VirtualHost \*:80>' }
63 end
64
65 describe file("#{$vhost_dir}/15-default-ssl.conf") do
66 it { should contain '<VirtualHost \*:443>' }
67 it { should 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 { should contain '<VirtualHost \*:80>' }
91 it { should 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 }
106 EOS
107 apply_manifest(pp, :catch_failures => true)
108 end
109
110 describe file("#{$vhost_dir}/25-proxy.example.com.conf") do
111 it { should contain '<VirtualHost \*:80>' }
112 it { should contain "ServerName proxy.example.com" }
113 it { should contain "ProxyPass" }
114 it { should_not contain "<Proxy \*>" }
115 end
116 end
117
118 context 'new vhost on port 80' do
119 it 'should configure two apache vhosts' do
120 pp = <<-EOS
121 class { 'apache': }
122 apache::vhost { 'first.example.com':
123 port => '80',
124 docroot => '/var/www/first',
125 }
126 host { 'first.example.com': ip => '127.0.0.1', }
127 file { '/var/www/first/index.html':
128 ensure => file,
129 content => "Hello from first\\n",
130 }
131 apache::vhost { 'second.example.com':
132 port => '80',
133 docroot => '/var/www/second',
134 }
135 host { 'second.example.com': ip => '127.0.0.1', }
136 file { '/var/www/second/index.html':
137 ensure => file,
138 content => "Hello from second\\n",
139 }
140 EOS
141 apply_manifest(pp, :catch_failures => true)
142 end
143
144 describe service($service_name) do
145 it { should be_enabled }
146 it { should be_running }
147 end
148
149 it 'should answer to first.example.com' do
150 shell("/usr/bin/curl first.example.com:80", {:acceptable_exit_codes => 0}) do |r|
151 r.stdout.should == "Hello from first\n"
152 end
153 end
154
155 it 'should answer to second.example.com' do
156 shell("/usr/bin/curl second.example.com:80", {:acceptable_exit_codes => 0}) do |r|
157 r.stdout.should == "Hello from second\n"
158 end
159 end
160 end
161
162 context 'apache_directories' do
163 describe 'readme example, adapted' do
164 it 'should configure a vhost with Files' do
165 pp = <<-EOS
166 class { 'apache': }
167
168 if $apache::apache_version >= 2.4 {
169 $_files_match_directory = { 'path' => '(\.swp|\.bak|~)$', 'provider' => 'filesmatch', 'require' => 'all denied', }
170 } else {
171 $_files_match_directory = { 'path' => '(\.swp|\.bak|~)$', 'provider' => 'filesmatch', 'deny' => 'from all', }
172 }
173
174 $_directories = [
175 { 'path' => '/var/www/files', },
176 $_files_match_directory,
177 ]
178
179 apache::vhost { 'files.example.net':
180 docroot => '/var/www/files',
181 directories => $_directories,
182 }
183 file { '/var/www/files/index.html':
184 ensure => file,
185 content => "Hello World\\n",
186 }
187 file { '/var/www/files/index.html.bak':
188 ensure => file,
189 content => "Hello World\\n",
190 }
191 host { 'files.example.net': ip => '127.0.0.1', }
192 EOS
193 apply_manifest(pp, :catch_failures => true)
194 end
195
196 describe service($service_name) do
197 it { should be_enabled }
198 it { should be_running }
199 end
200
201 it 'should answer to files.example.net' do
202 shell("/usr/bin/curl -sSf files.example.net:80/index.html").stdout.should eq("Hello World\n")
203 shell("/usr/bin/curl -sSf files.example.net:80/index.html.bak", {:acceptable_exit_codes => 22}).stderr.should match(/curl: \(22\) The requested URL returned error: 403/)
204 end
205 end
206
207 describe 'other Directory options' do
208 it 'should configure a vhost with multiple Directory sections' do
209 pp = <<-EOS
210 class { 'apache': }
211
212 if $apache::apache_version >= 2.4 {
213 $_files_match_directory = { 'path' => 'private.html$', 'provider' => 'filesmatch', 'require' => 'all denied' }
214 } else {
215 $_files_match_directory = { 'path' => 'private.html$', 'provider' => 'filesmatch', 'deny' => 'from all' }
216 }
217
218 $_directories = [
219 { 'path' => '/var/www/files', },
220 { 'path' => '/foo/', 'provider' => 'location', 'directoryindex' => 'notindex.html', },
221 $_files_match_directory,
222 ]
223
224 apache::vhost { 'files.example.net':
225 docroot => '/var/www/files',
226 directories => $_directories,
227 }
228 file { '/var/www/files/foo':
229 ensure => directory,
230 }
231 file { '/var/www/files/foo/notindex.html':
232 ensure => file,
233 content => "Hello Foo\\n",
234 }
235 file { '/var/www/files/private.html':
236 ensure => file,
237 content => "Hello World\\n",
238 }
239 host { 'files.example.net': ip => '127.0.0.1', }
240 EOS
241 apply_manifest(pp, :catch_failures => true)
242 end
243
244 describe service($service_name) do
245 it { should be_enabled }
246 it { should be_running }
247 end
248
249 it 'should answer to files.example.net' do
250 shell("/usr/bin/curl -sSf files.example.net:80/").stdout.should eq("Hello World\n")
251 shell("/usr/bin/curl -sSf files.example.net:80/foo/").stdout.should eq("Hello Foo\n")
252 shell("/usr/bin/curl -sSf files.example.net:80/private.html", {:acceptable_exit_codes => 22}).stderr.should match(/curl: \(22\) The requested URL returned error: 403/)
253 end
254 end
255
256 describe 'SetHandler directive' do
257 it 'should configure a vhost with a SetHandler directive' do
258 pp = <<-EOS
259 class { 'apache': }
260 apache::mod { 'status': }
261 host { 'files.example.net': ip => '127.0.0.1', }
262 apache::vhost { 'files.example.net':
263 docroot => '/var/www/files',
264 directories => [
265 { path => '/var/www/files', },
266 { path => '/server-status', provider => 'location', sethandler => 'server-status', },
267 ],
268 }
269 file { '/var/www/files/index.html':
270 ensure => file,
271 content => "Hello World\\n",
272 }
273 EOS
274 apply_manifest(pp, :catch_failures => true)
275 end
276
277 describe service($service_name) do
278 it { should be_enabled }
279 it { should be_running }
280 end
281
282 it 'should answer to files.example.net' do
283 shell("/usr/bin/curl -sSf files.example.net:80/index.html").stdout.should eq("Hello World\n")
284 shell("/usr/bin/curl -sSf files.example.net:80/server-status?auto").stdout.should match(/Scoreboard: /)
285 end
286 end
287 end
288
289 case fact('lsbdistcodename')
290 when 'precise', 'wheezy'
291 context 'vhost fallbackresouce example' do
292 it 'should configure a vhost with Fallbackresource' do
293 pp = <<-EOS
294 class { 'apache': }
295 apache::vhost { 'fallback.example.net':
296 docroot => '/var/www/fallback',
297 fallbackresource => '/index.html'
298 }
299 file { '/var/www/fallback/index.html':
300 ensure => file,
301 content => "Hello World\\n",
302 }
303 host { 'fallback.example.net': ip => '127.0.0.1', }
304 EOS
305 apply_manifest(pp, :catch_failures => true)
306 end
307
308 describe service($service_name) do
309 it { should be_enabled }
310 it { should be_running }
311 end
312
313 it 'should answer to fallback.example.net' do
314 shell("/usr/bin/curl fallback.example.net:80/Does/Not/Exist") do |r|
315 r.stdout.should == "Hello World\n"
316 end
317 end
318
319 end
320 else
321 # The current stable RHEL release (6.4) comes with Apache httpd 2.2.15
322 # That was released March 6, 2010.
323 # FallbackResource was backported to 2.2.16, and released July 25, 2010.
324 # Ubuntu Lucid (10.04) comes with apache2 2.2.14, released October 3, 2009.
325 # https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x/STATUS
326 end
327
328 context 'virtual_docroot hosting separate sites' do
329 it 'should configure a vhost with VirtualDocumentRoot' do
330 pp = <<-EOS
331 class { 'apache': }
332 apache::vhost { 'virt.example.com':
333 vhost_name => '*',
334 serveraliases => '*virt.example.com',
335 port => '80',
336 docroot => '/var/www/virt',
337 virtual_docroot => '/var/www/virt/%1',
338 }
339 host { 'virt.example.com': ip => '127.0.0.1', }
340 host { 'a.virt.example.com': ip => '127.0.0.1', }
341 host { 'b.virt.example.com': ip => '127.0.0.1', }
342 file { [ '/var/www/virt/a', '/var/www/virt/b', ]: ensure => directory, }
343 file { '/var/www/virt/a/index.html': ensure => file, content => "Hello from a.virt\\n", }
344 file { '/var/www/virt/b/index.html': ensure => file, content => "Hello from b.virt\\n", }
345 EOS
346 apply_manifest(pp, :catch_failures => true)
347 end
348
349 describe service($service_name) do
350 it { should be_enabled }
351 it { should be_running }
352 end
353
354 it 'should answer to a.virt.example.com' do
355 shell("/usr/bin/curl a.virt.example.com:80", {:acceptable_exit_codes => 0}) do |r|
356 r.stdout.should == "Hello from a.virt\n"
357 end
358 end
359
360 it 'should answer to b.virt.example.com' do
361 shell("/usr/bin/curl b.virt.example.com:80", {:acceptable_exit_codes => 0}) do |r|
362 r.stdout.should == "Hello from b.virt\n"
363 end
364 end
365 end
366
367 context 'proxy_pass for alternative vhost' do
368 it 'should configure a local vhost and a proxy vhost' do
369 apply_manifest(%{
370 class { 'apache': default_vhost => false, }
371 apache::vhost { 'localhost':
372 docroot => '/var/www/local',
373 ip => '127.0.0.1',
374 port => '8888',
375 }
376 apache::listen { '*:80': }
377 apache::vhost { 'proxy.example.com':
378 docroot => '/var/www',
379 port => '80',
380 add_listen => false,
381 proxy_pass => {
382 'path' => '/',
383 'url' => 'http://localhost:8888/subdir/',
384 },
385 }
386 host { 'proxy.example.com': ip => '127.0.0.1', }
387 file { ['/var/www/local', '/var/www/local/subdir']: ensure => directory, }
388 file { '/var/www/local/subdir/index.html':
389 ensure => file,
390 content => "Hello from localhost\\n",
391 }
392 }, :catch_failures => true)
393 end
394
395 describe service($service_name) do
396 it { should be_enabled }
397 it { should be_running }
398 end
399
400 it 'should get a response from the back end' do
401 shell("/usr/bin/curl --max-redirs 0 proxy.example.com:80") do |r|
402 r.stdout.should == "Hello from localhost\n"
403 r.exit_code.should == 0
404 end
405 end
406 end
407
408 describe 'ip_based' do
409 it 'applies cleanly' do
410 pp = <<-EOS
411 class { 'apache': }
412 host { 'test.server': ip => '127.0.0.1' }
413 apache::vhost { 'test.server':
414 docroot => '/tmp',
415 ip_based => true,
416 servername => 'test.server',
417 }
418 EOS
419 apply_manifest(pp, :catch_failures => true)
420 end
421
422 describe file($ports_file) do
423 it { should be_file }
424 it { should_not contain 'NameVirtualHost test.server' }
425 end
426 end
427
428 describe 'add_listen' do
429 it 'applies cleanly' do
430 pp = <<-EOS
431 class { 'apache': default_vhost => false }
432 host { 'testlisten.server': ip => '127.0.0.1' }
433 apache::listen { '81': }
434 apache::vhost { 'testlisten.server':
435 docroot => '/tmp',
436 port => '80',
437 add_listen => false,
438 servername => 'testlisten.server',
439 }
440 EOS
441 apply_manifest(pp, :catch_failures => true)
442 end
443
444 describe file($ports_file) do
445 it { should be_file }
446 it { should_not contain 'Listen 80' }
447 it { should contain 'Listen 81' }
448 end
449 end
450
451 describe 'docroot' do
452 it 'applies cleanly' do
453 pp = <<-EOS
454 user { 'test_owner': ensure => present, }
455 group { 'test_group': ensure => present, }
456 class { 'apache': }
457 host { 'test.server': ip => '127.0.0.1' }
458 apache::vhost { 'test.server':
459 docroot => '/tmp/test',
460 docroot_owner => 'test_owner',
461 docroot_group => 'test_group',
462 docroot_mode => '0750',
463 }
464 EOS
465 apply_manifest(pp, :catch_failures => true)
466 end
467
468 describe file('/tmp/test') do
469 it { should be_directory }
470 it { should be_owned_by 'test_owner' }
471 it { should be_grouped_into 'test_group' }
472 it { should be_mode 750 }
473 end
474 end
475
476 describe 'default_vhost' do
477 it 'applies cleanly' do
478 pp = <<-EOS
479 class { 'apache': }
480 host { 'test.server': ip => '127.0.0.1' }
481 apache::vhost { 'test.server':
482 docroot => '/tmp',
483 default_vhost => true,
484 }
485 EOS
486 apply_manifest(pp, :catch_failures => true)
487 end
488
489 describe file($ports_file) do
490 it { should be_file }
491 if fact('osfamily') == 'RedHat' and fact('operatingsystemmajrelease') == '7'
492 it { should_not contain 'NameVirtualHost test.server' }
493 elsif fact('operatingsystem') == 'Ubuntu' and fact('operatingsystemrelease') =~ /(14\.04|13\.10)/
494 it { should_not contain 'NameVirtualHost test.server' }
495 else
496 it { should contain 'NameVirtualHost test.server' }
497 end
498 end
499
500 describe file("#{$vhost_dir}/10-test.server.conf") do
501 it { should be_file }
502 end
503 end
504
505 describe 'options' do
506 it 'applies cleanly' do
507 pp = <<-EOS
508 class { 'apache': }
509 host { 'test.server': ip => '127.0.0.1' }
510 apache::vhost { 'test.server':
511 docroot => '/tmp',
512 options => ['Indexes','FollowSymLinks', 'ExecCGI'],
513 }
514 EOS
515 apply_manifest(pp, :catch_failures => true)
516 end
517
518 describe file("#{$vhost_dir}/25-test.server.conf") do
519 it { should be_file }
520 it { should contain 'Options Indexes FollowSymLinks ExecCGI' }
521 end
522 end
523
524 describe 'override' do
525 it 'applies cleanly' do
526 pp = <<-EOS
527 class { 'apache': }
528 host { 'test.server': ip => '127.0.0.1' }
529 apache::vhost { 'test.server':
530 docroot => '/tmp',
531 override => ['All'],
532 }
533 EOS
534 apply_manifest(pp, :catch_failures => true)
535 end
536
537 describe file("#{$vhost_dir}/25-test.server.conf") do
538 it { should be_file }
539 it { should contain 'AllowOverride All' }
540 end
541 end
542
543 describe 'logroot' do
544 it 'applies cleanly' do
545 pp = <<-EOS
546 class { 'apache': }
547 host { 'test.server': ip => '127.0.0.1' }
548 apache::vhost { 'test.server':
549 docroot => '/tmp',
550 logroot => '/tmp',
551 }
552 EOS
553 apply_manifest(pp, :catch_failures => true)
554 end
555
556 describe file("#{$vhost_dir}/25-test.server.conf") do
557 it { should be_file }
558 it { should contain ' CustomLog "/tmp' }
559 end
560 end
561
562 ['access', 'error'].each do |logtype|
563 case logtype
564 when 'access'
565 logname = 'CustomLog'
566 when 'error'
567 logname = 'ErrorLog'
568 end
569
570 describe "#{logtype}_log" do
571 it 'applies cleanly' do
572 pp = <<-EOS
573 class { 'apache': }
574 host { 'test.server': ip => '127.0.0.1' }
575 apache::vhost { 'test.server':
576 docroot => '/tmp',
577 logroot => '/tmp',
578 #{logtype}_log => false,
579 }
580 EOS
581 apply_manifest(pp, :catch_failures => true)
582 end
583
584 describe file("#{$vhost_dir}/25-test.server.conf") do
585 it { should be_file }
586 it { should_not contain " #{logname} \"/tmp" }
587 end
588 end
589
590 describe "#{logtype}_log_pipe" do
591 it 'applies cleanly' do
592 pp = <<-EOS
593 class { 'apache': }
594 host { 'test.server': ip => '127.0.0.1' }
595 apache::vhost { 'test.server':
596 docroot => '/tmp',
597 logroot => '/tmp',
598 #{logtype}_log_pipe => '|/bin/sh',
599 }
600 EOS
601 apply_manifest(pp, :catch_failures => true)
602 end
603
604 describe file("#{$vhost_dir}/25-test.server.conf") do
605 it { should be_file }
606 it { should contain " #{logname} \"|/bin/sh" }
607 end
608 end
609
610 describe "#{logtype}_log_syslog" do
611 it 'applies cleanly' do
612 pp = <<-EOS
613 class { 'apache': }
614 host { 'test.server': ip => '127.0.0.1' }
615 apache::vhost { 'test.server':
616 docroot => '/tmp',
617 logroot => '/tmp',
618 #{logtype}_log_syslog => 'syslog',
619 }
620 EOS
621 apply_manifest(pp, :catch_failures => true)
622 end
623
624 describe file("#{$vhost_dir}/25-test.server.conf") do
625 it { should be_file }
626 it { should contain " #{logname} \"syslog\"" }
627 end
628 end
629 end
630
631 describe 'access_log_format' do
632 it 'applies cleanly' do
633 pp = <<-EOS
634 class { 'apache': }
635 host { 'test.server': ip => '127.0.0.1' }
636 apache::vhost { 'test.server':
637 docroot => '/tmp',
638 logroot => '/tmp',
639 access_log_syslog => 'syslog',
640 access_log_format => '%h %l',
641 }
642 EOS
643 apply_manifest(pp, :catch_failures => true)
644 end
645
646 describe file("#{$vhost_dir}/25-test.server.conf") do
647 it { should be_file }
648 it { should contain 'CustomLog "syslog" "%h %l"' }
649 end
650 end
651
652 describe 'access_log_env_var' do
653 it 'applies cleanly' do
654 pp = <<-EOS
655 class { 'apache': }
656 host { 'test.server': ip => '127.0.0.1' }
657 apache::vhost { 'test.server':
658 docroot => '/tmp',
659 logroot => '/tmp',
660 access_log_syslog => 'syslog',
661 access_log_env_var => 'admin',
662 }
663 EOS
664 apply_manifest(pp, :catch_failures => true)
665 end
666
667 describe file("#{$vhost_dir}/25-test.server.conf") do
668 it { should be_file }
669 it { should contain 'CustomLog "syslog" combined env=admin' }
670 end
671 end
672
673 describe 'aliases' do
674 it 'applies cleanly' do
675 pp = <<-EOS
676 class { 'apache': }
677 host { 'test.server': ip => '127.0.0.1' }
678 apache::vhost { 'test.server':
679 docroot => '/tmp',
680 aliases => [{ alias => '/image', path => '/ftp/pub/image' }],
681 }
682 EOS
683 apply_manifest(pp, :catch_failures => true)
684 end
685
686 describe file("#{$vhost_dir}/25-test.server.conf") do
687 it { should be_file }
688 it { should contain 'Alias /image "/ftp/pub/image"' }
689 end
690 end
691
692 describe 'scriptaliases' do
693 it 'applies cleanly' do
694 pp = <<-EOS
695 class { 'apache': }
696 host { 'test.server': ip => '127.0.0.1' }
697 apache::vhost { 'test.server':
698 docroot => '/tmp',
699 scriptaliases => [{ alias => '/myscript', path => '/usr/share/myscript', }],
700 }
701 EOS
702 apply_manifest(pp, :catch_failures => true)
703 end
704
705 describe file("#{$vhost_dir}/25-test.server.conf") do
706 it { should be_file }
707 it { should contain 'ScriptAlias /myscript "/usr/share/myscript"' }
708 end
709 end
710
711 describe 'proxy' do
712 it 'applies cleanly' do
713 pp = <<-EOS
714 class { 'apache': service_ensure => stopped, }
715 host { 'test.server': ip => '127.0.0.1' }
716 apache::vhost { 'test.server':
717 docroot => '/tmp',
718 proxy_dest => 'test2',
719 }
720 EOS
721 apply_manifest(pp, :catch_failures => true)
722 end
723
724 describe file("#{$vhost_dir}/25-test.server.conf") do
725 it { should be_file }
726 it { should contain 'ProxyPass / test2/' }
727 end
728 end
729
730 describe 'actions' do
731 it 'applies cleanly' do
732 pp = <<-EOS
733 class { 'apache': }
734 host { 'test.server': ip => '127.0.0.1' }
735 apache::vhost { 'test.server':
736 docroot => '/tmp',
737 action => 'php-fastcgi',
738 }
739 EOS
740 pp = pp + "\nclass { 'apache::mod::actions': }" if fact('osfamily') == 'Debian'
741 apply_manifest(pp, :catch_failures => true)
742 end
743
744 describe file("#{$vhost_dir}/25-test.server.conf") do
745 it { should be_file }
746 it { should contain 'Action php-fastcgi /cgi-bin virtual' }
747 end
748 end
749
750 describe 'suphp' do
751 it 'applies cleanly' do
752 pp = <<-EOS
753 class { 'apache': service_ensure => stopped, }
754 host { 'test.server': ip => '127.0.0.1' }
755 apache::vhost { 'test.server':
756 docroot => '/tmp',
757 suphp_addhandler => '#{$suphp_handler}',
758 suphp_engine => 'on',
759 suphp_configpath => '#{$suphp_configpath}',
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 { should be_file }
767 it { should contain "suPHP_AddHandler #{$suphp_handler}" }
768 it { should contain 'suPHP_Engine on' }
769 it { should contain "suPHP_ConfigPath \"#{$suphp_configpath}\"" }
770 end
771 end
772
773 describe 'no_proxy_uris' do
774 it 'applies cleanly' do
775 pp = <<-EOS
776 class { 'apache': service_ensure => stopped, }
777 host { 'test.server': ip => '127.0.0.1' }
778 apache::vhost { 'test.server':
779 docroot => '/tmp',
780 proxy_dest => 'http://test2',
781 no_proxy_uris => [ 'http://test2/test' ],
782 }
783 EOS
784 apply_manifest(pp, :catch_failures => true)
785 end
786
787 describe file("#{$vhost_dir}/25-test.server.conf") do
788 it { should be_file }
789 it { should contain 'ProxyPass / http://test2/' }
790 it { should contain 'ProxyPass http://test2/test !' }
791 end
792 end
793
794 describe 'redirect' do
795 it 'applies cleanly' do
796 pp = <<-EOS
797 class { 'apache': }
798 host { 'test.server': ip => '127.0.0.1' }
799 apache::vhost { 'test.server':
800 docroot => '/tmp',
801 redirect_source => ['/images'],
802 redirect_dest => ['http://test.server/'],
803 redirect_status => ['permanent'],
804 }
805 EOS
806 apply_manifest(pp, :catch_failures => true)
807 end
808
809 describe file("#{$vhost_dir}/25-test.server.conf") do
810 it { should be_file }
811 it { should contain 'Redirect permanent /images http://test.server/' }
812 end
813 end
814
815 # Passenger isn't even in EPEL on el-5
816 if default['platform'] !~ /^el-5/
817 if fact('osfamily') == 'RedHat' and fact('operatingsystemmajrelease') == '7'
818 pending('Since we don\'t have passenger on RHEL7 rack_base_uris tests will fail')
819 else
820 describe 'rack_base_uris' do
821 if fact('osfamily') == 'RedHat'
822 it 'adds epel' do
823 pp = "class { 'epel': }"
824 apply_manifest(pp, :catch_failures => true)
825 end
826 end
827
828 it 'applies cleanly' do
829 pp = <<-EOS
830 class { 'apache': }
831 host { 'test.server': ip => '127.0.0.1' }
832 apache::vhost { 'test.server':
833 docroot => '/tmp',
834 rack_base_uris => ['/test'],
835 }
836 EOS
837 apply_manifest(pp, :catch_failures => true)
838 end
839
840 describe file("#{$vhost_dir}/25-test.server.conf") do
841 it { should be_file }
842 it { should contain 'RackBaseURI /test' }
843 end
844 end
845 end
846 end
847
848
849 describe 'request_headers' do
850 it 'applies cleanly' do
851 pp = <<-EOS
852 class { 'apache': }
853 host { 'test.server': ip => '127.0.0.1' }
854 apache::vhost { 'test.server':
855 docroot => '/tmp',
856 request_headers => ['append MirrorID "mirror 12"'],
857 }
858 EOS
859 apply_manifest(pp, :catch_failures => true)
860 end
861
862 describe file("#{$vhost_dir}/25-test.server.conf") do
863 it { should be_file }
864 it { should contain 'append MirrorID "mirror 12"' }
865 end
866 end
867
868 describe 'rewrite rules' do
869 it 'applies cleanly' do
870 pp = <<-EOS
871 class { 'apache': }
872 host { 'test.server': ip => '127.0.0.1' }
873 apache::vhost { 'test.server':
874 docroot => '/tmp',
875 rewrites => [
876 { comment => 'test',
877 rewrite_cond => '%{HTTP_USER_AGENT} ^Lynx/ [OR]',
878 rewrite_rule => ['^index\.html$ welcome.html'],
879 }
880 ],
881 }
882 EOS
883 apply_manifest(pp, :catch_failures => true)
884 end
885
886 describe file("#{$vhost_dir}/25-test.server.conf") do
887 it { should be_file }
888 it { should contain '#test' }
889 it { should contain 'RewriteCond %{HTTP_USER_AGENT} ^Lynx/ [OR]' }
890 it { should contain 'RewriteRule ^index.html$ welcome.html' }
891 end
892 end
893
894 describe 'setenv/setenvif' do
895 it 'applies cleanly' do
896 pp = <<-EOS
897 class { 'apache': }
898 host { 'test.server': ip => '127.0.0.1' }
899 apache::vhost { 'test.server':
900 docroot => '/tmp',
901 setenv => ['TEST /test'],
902 setenvif => ['Request_URI "\.gif$" object_is_image=gif']
903 }
904 EOS
905 apply_manifest(pp, :catch_failures => true)
906 end
907
908 describe file("#{$vhost_dir}/25-test.server.conf") do
909 it { should be_file }
910 it { should contain 'SetEnv TEST /test' }
911 it { should contain 'SetEnvIf Request_URI "\.gif$" object_is_image=gif' }
912 end
913 end
914
915 describe 'block' do
916 it 'applies cleanly' do
917 pp = <<-EOS
918 class { 'apache': }
919 host { 'test.server': ip => '127.0.0.1' }
920 apache::vhost { 'test.server':
921 docroot => '/tmp',
922 block => 'scm',
923 }
924 EOS
925 apply_manifest(pp, :catch_failures => true)
926 end
927
928 describe file("#{$vhost_dir}/25-test.server.conf") do
929 it { should be_file }
930 it { should contain '<DirectoryMatch .*\.(svn|git|bzr)/.*>' }
931 end
932 end
933
934 describe 'wsgi' do
935 it 'import_script applies cleanly' do
936 pp = <<-EOS
937 class { 'apache': }
938 class { 'apache::mod::wsgi': }
939 host { 'test.server': ip => '127.0.0.1' }
940 apache::vhost { 'test.server':
941 docroot => '/tmp',
942 wsgi_application_group => '%{GLOBAL}',
943 wsgi_daemon_process => 'wsgi',
944 wsgi_daemon_process_options => {processes => '2'},
945 wsgi_process_group => 'nobody',
946 wsgi_script_aliases => { '/test' => '/test1' },
947 }
948 EOS
949 apply_manifest(pp, :catch_failures => true)
950 end
951
952 it 'import_script applies cleanly', :unless => (fact('lsbdistcodename') == 'lucid' or UNSUPPORTED_PLATFORMS.include?(fact('osfamily'))) do
953 pp = <<-EOS
954 class { 'apache': }
955 class { 'apache::mod::wsgi': }
956 host { 'test.server': ip => '127.0.0.1' }
957 apache::vhost { 'test.server':
958 docroot => '/tmp',
959 wsgi_application_group => '%{GLOBAL}',
960 wsgi_daemon_process => 'wsgi',
961 wsgi_daemon_process_options => {processes => '2'},
962 wsgi_import_script => '/test1',
963 wsgi_import_script_options => { application-group => '%{GLOBAL}', process-group => 'wsgi' },
964 wsgi_process_group => 'nobody',
965 wsgi_script_aliases => { '/test' => '/test1' },
966 }
967 EOS
968 apply_manifest(pp, :catch_failures => true)
969 end
970
971 describe file("#{$vhost_dir}/25-test.server.conf"), :unless => (fact('lsbdistcodename') == 'lucid' or UNSUPPORTED_PLATFORMS.include?(fact('osfamily'))) do
972 it { should be_file }
973 it { should contain 'WSGIApplicationGroup %{GLOBAL}' }
974 it { should contain 'WSGIDaemonProcess wsgi processes=2' }
975 it { should contain 'WSGIImportScript /test1 application-group=%{GLOBAL} process-group=wsgi' }
976 it { should contain 'WSGIProcessGroup nobody' }
977 it { should contain 'WSGIScriptAlias /test "/test1"' }
978 end
979 end
980
981 describe 'custom_fragment' do
982 it 'applies cleanly' do
983 pp = <<-EOS
984 class { 'apache': }
985 host { 'test.server': ip => '127.0.0.1' }
986 apache::vhost { 'test.server':
987 docroot => '/tmp',
988 custom_fragment => inline_template('#weird test string'),
989 }
990 EOS
991 apply_manifest(pp, :catch_failures => true)
992 end
993
994 describe file("#{$vhost_dir}/25-test.server.conf") do
995 it { should be_file }
996 it { should contain '#weird test string' }
997 end
998 end
999
1000 describe 'itk' do
1001 it 'applies cleanly' do
1002 pp = <<-EOS
1003 class { 'apache': }
1004 host { 'test.server': ip => '127.0.0.1' }
1005 apache::vhost { 'test.server':
1006 docroot => '/tmp',
1007 itk => { user => 'nobody', group => 'nobody' }
1008 }
1009 EOS
1010 apply_manifest(pp, :catch_failures => true)
1011 end
1012
1013 describe file("#{$vhost_dir}/25-test.server.conf") do
1014 it { should be_file }
1015 it { should contain 'AssignUserId nobody nobody' }
1016 end
1017 end
1018
1019 # So what does this work on?
1020 if default['platform'] !~ /^(debian-(6|7)|el-(5|6|7))/
1021 describe 'fastcgi' do
1022 it 'applies cleanly' do
1023 pp = <<-EOS
1024 class { 'apache': }
1025 class { 'apache::mod::fastcgi': }
1026 host { 'test.server': ip => '127.0.0.1' }
1027 apache::vhost { 'test.server':
1028 docroot => '/tmp',
1029 fastcgi_server => 'localhost',
1030 fastcgi_socket => '/tmp/fast/1234',
1031 fastcgi_dir => '/tmp/fast',
1032 }
1033 EOS
1034 apply_manifest(pp, :catch_failures => true)
1035 end
1036
1037 describe file("#{$vhost_dir}/25-test.server.conf") do
1038 it { should be_file }
1039 it { should contain 'FastCgiExternalServer localhost -socket /tmp/fast/1234' }
1040 it { should contain '<Directory "/tmp/fast">' }
1041 end
1042 end
1043 end
1044
1045 describe 'additional_includes' do
1046 it 'applies cleanly' do
1047 pp = <<-EOS
1048 if $::osfamily == 'RedHat' and $::selinux == 'true' {
1049 $semanage_package = $::operatingsystemmajrelease ? {
1050 '5' => 'policycoreutils',
1051 default => 'policycoreutils-python',
1052 }
1053 exec { 'set_apache_defaults':
1054 command => 'semanage fcontext -a -t httpd_sys_content_t "/apache_spec(/.*)?"',
1055 path => '/bin:/usr/bin/:/sbin:/usr/sbin',
1056 require => Package[$semanage_package],
1057 }
1058 package { $semanage_package: ensure => installed }
1059 exec { 'restorecon_apache':
1060 command => 'restorecon -Rv /apache_spec',
1061 path => '/bin:/usr/bin/:/sbin:/usr/sbin',
1062 before => Service['httpd'],
1063 require => Class['apache'],
1064 }
1065 }
1066 class { 'apache': }
1067 host { 'test.server': ip => '127.0.0.1' }
1068 file { '/apache_spec': ensure => directory, }
1069 file { '/apache_spec/include': ensure => present, content => '#additional_includes' }
1070 apache::vhost { 'test.server':
1071 docroot => '/apache_spec',
1072 additional_includes => '/apache_spec/include',
1073 }
1074 EOS
1075 apply_manifest(pp, :catch_failures => true)
1076 end
1077
1078 describe file("#{$vhost_dir}/25-test.server.conf") do
1079 it { should be_file }
1080 it { should contain 'Include "/apache_spec/include"' }
1081 end
1082 end
1083
1084 end