1 require 'spec_helper_acceptance'
2 require_relative './version.rb'
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
9 default_vhost => false,
10 default_ssl_vhost => false,
11 service_ensure => stopped
15 apply_manifest(pp, :catch_failures => true)
18 describe file("#{$vhost_dir}/15-default.conf") do
19 it { is_expected.not_to be_file }
22 describe file("#{$vhost_dir}/15-default-ssl.conf") do
23 it { is_expected.not_to be_file }
27 context "default vhost without ssl" do
28 it 'should create a default vhost config' do
33 apply_manifest(pp, :catch_failures => true)
36 describe file("#{$vhost_dir}/15-default.conf") do
37 it { is_expected.to contain '<VirtualHost \*:80>' }
40 describe file("#{$vhost_dir}/15-default-ssl.conf") do
41 it { is_expected.not_to be_file }
45 context 'default vhost with ssl' do
46 it 'should create default vhost configs' do
49 ensure => 'directory',
54 default_ssl_vhost => true,
55 require => File['#{$run_dir}'],
58 apply_manifest(pp, :catch_failures => true)
61 describe file("#{$vhost_dir}/15-default.conf") do
62 it { is_expected.to contain '<VirtualHost \*:80>' }
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" }
71 context 'new vhost on port 80' do
72 it 'should configure an apache vhost' do
76 ensure => 'directory',
80 apache::vhost { 'first.example.com':
82 docroot => '/var/www/first',
83 require => File['#{$run_dir}'],
86 apply_manifest(pp, :catch_failures => true)
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" }
95 context 'new proxy vhost on port 80' do
96 it 'should configure an apache proxy vhost' do
99 apache::vhost { 'proxy.example.com':
101 docroot => '/var/www/proxy',
103 { 'path' => '/foo', 'url' => 'http://backend-foo/'},
105 proxy_preserve_host => true,
106 proxy_error_override => true,
109 apply_manifest(pp, :catch_failures => true)
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 \*>" }
122 context 'new proxy vhost on port 80' do
123 it 'should configure an apache proxy vhost' do
126 apache::vhost { 'proxy.example.com':
128 docroot => '/var/www/proxy',
129 proxy_pass_match => [
130 { 'path' => '/foo', 'url' => 'http://backend-foo/'},
132 proxy_preserve_host => true,
133 proxy_error_override => true,
136 apply_manifest(pp, :catch_failures => true)
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 \*>" }
149 context 'new vhost on port 80' do
150 it 'should configure two apache vhosts' do
153 apache::vhost { 'first.example.com':
155 docroot => '/var/www/first',
157 host { 'first.example.com': ip => '127.0.0.1', }
158 file { '/var/www/first/index.html':
160 content => "Hello from first\\n",
162 apache::vhost { 'second.example.com':
164 docroot => '/var/www/second',
166 host { 'second.example.com': ip => '127.0.0.1', }
167 file { '/var/www/second/index.html':
169 content => "Hello from second\\n",
172 apply_manifest(pp, :catch_failures => true)
175 describe service($service_name) do
176 it { is_expected.to be_enabled }
177 it { is_expected.to be_running }
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")
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")
193 context 'apache_directories' do
194 describe 'readme example, adapted' do
195 it 'should configure a vhost with Files' do
199 if versioncmp($apache::apache_version, '2.4') >= 0 {
200 $_files_match_directory = { 'path' => '(\.swp|\.bak|~)$', 'provider' => 'filesmatch', 'require' => 'all denied', }
202 $_files_match_directory = { 'path' => '(\.swp|\.bak|~)$', 'provider' => 'filesmatch', 'deny' => 'from all', }
206 { 'path' => '/var/www/files', },
207 $_files_match_directory,
210 apache::vhost { 'files.example.net':
211 docroot => '/var/www/files',
212 directories => $_directories,
214 file { '/var/www/files/index.html':
216 content => "Hello World\\n",
218 file { '/var/www/files/index.html.bak':
220 content => "Hello World\\n",
222 host { 'files.example.net': ip => '127.0.0.1', }
224 apply_manifest(pp, :catch_failures => true)
227 describe service($service_name) do
228 it { is_expected.to be_enabled }
229 it { is_expected.to be_running }
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/)
238 describe 'other Directory options' do
239 it 'should configure a vhost with multiple Directory sections' do
243 if versioncmp($apache::apache_version, '2.4') >= 0 {
244 $_files_match_directory = { 'path' => 'private.html$', 'provider' => 'filesmatch', 'require' => 'all denied' }
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', ] },
253 { 'path' => '/var/www/files', },
254 { 'path' => '/foo/', 'provider' => 'location', 'directoryindex' => 'notindex.html', },
255 $_files_match_directory,
258 apache::vhost { 'files.example.net':
259 docroot => '/var/www/files',
260 directories => $_directories,
262 file { '/var/www/files/foo':
265 file { '/var/www/files/foo/notindex.html':
267 content => "Hello Foo\\n",
269 file { '/var/www/files/private.html':
271 content => "Hello World\\n",
273 file { '/var/www/files/bar':
276 file { '/var/www/files/bar/bar.html':
278 content => "Hello Bar\\n",
280 host { 'files.example.net': ip => '127.0.0.1', }
282 apply_manifest(pp, :catch_failures => true)
285 describe service($service_name) do
286 it { is_expected.to be_enabled }
287 it { is_expected.to be_running }
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")
298 describe 'SetHandler directive' do
299 it 'should configure a vhost with a SetHandler directive' do
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',
307 { path => '/var/www/files', },
308 { path => '/server-status', provider => 'location', sethandler => 'server-status', },
311 file { '/var/www/files/index.html':
313 content => "Hello World\\n",
316 apply_manifest(pp, :catch_failures => true)
319 describe service($service_name) do
320 it { is_expected.to be_enabled }
321 it { is_expected.to be_running }
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: /)
330 describe 'Satisfy and Auth directive', :unless => $apache_version == '2.4' do
331 it 'should configure a vhost with Satisfy and Auth directive' do
334 host { 'files.example.net': ip => '127.0.0.1', }
335 apache::vhost { 'files.example.net':
336 docroot => '/var/www/files',
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",
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',
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',
364 file { '/var/www/files/foo':
367 file { '/var/www/files/bar':
370 file { '/var/www/files/baz':
373 file { '/var/www/files/foo/index.html':
375 content => "Hello World\\n",
377 file { '/var/www/files/bar/index.html':
379 content => "Hello World\\n",
381 file { '/var/www/files/baz/index.html':
383 content => "Hello World\\n",
385 file { '/var/www/htpasswd':
387 content => "login:IZ7jMcLSx0oQk", # "password" as password
390 apply_manifest(pp, :catch_failures => true)
393 describe service($service_name) do
394 it { should be_enabled }
395 it { should be_running }
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")
409 case fact('lsbdistcodename')
410 when 'precise', 'wheezy'
411 context 'vhost fallbackresource example' do
412 it 'should configure a vhost with Fallbackresource' do
415 apache::vhost { 'fallback.example.net':
416 docroot => '/var/www/fallback',
417 fallbackresource => '/index.html'
419 file { '/var/www/fallback/index.html':
421 content => "Hello World\\n",
423 host { 'fallback.example.net': ip => '127.0.0.1', }
425 apply_manifest(pp, :catch_failures => true)
428 describe service($service_name) do
429 it { is_expected.to be_enabled }
430 it { is_expected.to be_running }
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")
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
448 context 'virtual_docroot hosting separate sites' do
449 it 'should configure a vhost with VirtualDocumentRoot' do
452 apache::vhost { 'virt.example.com':
454 serveraliases => '*virt.example.com',
456 docroot => '/var/www/virt',
457 virtual_docroot => '/var/www/virt/%1',
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", }
466 apply_manifest(pp, :catch_failures => true)
469 describe service($service_name) do
470 it { is_expected.to be_enabled }
471 it { is_expected.to be_running }
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")
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")
487 context 'proxy_pass for alternative vhost' do
488 it 'should configure a local vhost and a proxy vhost' do
490 class { 'apache': default_vhost => false, }
491 apache::vhost { 'localhost':
492 docroot => '/var/www/local',
496 apache::listen { '*:80': }
497 apache::vhost { 'proxy.example.com':
498 docroot => '/var/www',
503 'url' => 'http://localhost:8888/subdir/',
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':
510 content => "Hello from localhost\\n",
512 }, :catch_failures => true)
515 describe service($service_name) do
516 it { is_expected.to be_enabled }
517 it { is_expected.to be_running }
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)
528 context 'proxy_pass_match for alternative vhost' do
529 it 'should configure a local vhost and a proxy vhost' do
531 class { 'apache': default_vhost => false, }
532 apache::vhost { 'localhost':
533 docroot => '/var/www/local',
537 apache::listen { '*:80': }
538 apache::vhost { 'proxy.example.com':
539 docroot => '/var/www',
542 proxy_pass_match => {
544 'url' => 'http://localhost:8888/subdir/',
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':
551 content => "Hello from localhost\\n",
553 }, :catch_failures => true)
556 describe service($service_name) do
557 it { is_expected.to be_enabled }
558 it { is_expected.to be_running }
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)
569 describe 'ip_based' do
570 it 'applies cleanly' do
573 host { 'test.server': ip => '127.0.0.1' }
574 apache::vhost { 'test.server':
577 servername => 'test.server',
580 apply_manifest(pp, :catch_failures => true)
583 describe file($ports_file) do
584 it { is_expected.to be_file }
585 it { is_expected.not_to contain 'NameVirtualHost test.server' }
589 describe 'add_listen' do
590 it 'applies cleanly' do
592 class { 'apache': default_vhost => false }
593 host { 'testlisten.server': ip => '127.0.0.1' }
594 apache::listen { '81': }
595 apache::vhost { 'testlisten.server':
599 servername => 'testlisten.server',
602 apply_manifest(pp, :catch_failures => true)
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' }
612 describe 'docroot' do
613 it 'applies cleanly' do
615 user { 'test_owner': ensure => present, }
616 group { 'test_group': ensure => present, }
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',
626 apply_manifest(pp, :catch_failures => true)
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 }
637 describe 'default_vhost' do
638 it 'applies cleanly' do
641 host { 'test.server': ip => '127.0.0.1' }
642 apache::vhost { 'test.server':
644 default_vhost => true,
647 apply_manifest(pp, :catch_failures => true)
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' }
657 it { is_expected.to contain 'NameVirtualHost test.server' }
661 describe file("#{$vhost_dir}/10-test.server.conf") do
662 it { is_expected.to be_file }
666 describe 'options' do
667 it 'applies cleanly' do
670 host { 'test.server': ip => '127.0.0.1' }
671 apache::vhost { 'test.server':
673 options => ['Indexes','FollowSymLinks', 'ExecCGI'],
676 apply_manifest(pp, :catch_failures => true)
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' }
685 describe 'override' do
686 it 'applies cleanly' do
689 host { 'test.server': ip => '127.0.0.1' }
690 apache::vhost { 'test.server':
695 apply_manifest(pp, :catch_failures => true)
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' }
704 describe 'logroot' do
705 it 'applies cleanly' do
708 host { 'test.server': ip => '127.0.0.1' }
709 apache::vhost { 'test.server':
714 apply_manifest(pp, :catch_failures => true)
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' }
723 ['access', 'error'].each do |logtype|
726 logname = 'CustomLog'
731 describe "#{logtype}_log" do
732 it 'applies cleanly' do
735 host { 'test.server': ip => '127.0.0.1' }
736 apache::vhost { 'test.server':
739 #{logtype}_log => false,
742 apply_manifest(pp, :catch_failures => true)
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" }
751 describe "#{logtype}_log_pipe" do
752 it 'applies cleanly' do
755 host { 'test.server': ip => '127.0.0.1' }
756 apache::vhost { 'test.server':
759 #{logtype}_log_pipe => '|/bin/sh',
762 apply_manifest(pp, :catch_failures => true)
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" }
771 describe "#{logtype}_log_syslog" do
772 it 'applies cleanly' do
775 host { 'test.server': ip => '127.0.0.1' }
776 apache::vhost { 'test.server':
779 #{logtype}_log_syslog => 'syslog',
782 apply_manifest(pp, :catch_failures => true)
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\"" }
792 describe 'access_log_format' do
793 it 'applies cleanly' do
796 host { 'test.server': ip => '127.0.0.1' }
797 apache::vhost { 'test.server':
800 access_log_syslog => 'syslog',
801 access_log_format => '%h %l',
804 apply_manifest(pp, :catch_failures => true)
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"' }
813 describe 'access_log_env_var' do
814 it 'applies cleanly' do
817 host { 'test.server': ip => '127.0.0.1' }
818 apache::vhost { 'test.server':
821 access_log_syslog => 'syslog',
822 access_log_env_var => 'admin',
825 apply_manifest(pp, :catch_failures => true)
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' }
834 describe 'multiple access_logs' do
835 it 'applies cleanly' do
838 host { 'test.server': ip => '127.0.0.1' }
839 apache::vhost { 'test.server':
844 {'file' => 'log2', 'env' => 'admin' },
845 {'file' => '/var/tmp/log3', 'format' => '%h %l'},
846 {'syslog' => 'syslog' }
850 apply_manifest(pp, :catch_failures => true)
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' }
862 describe 'aliases' do
863 it 'applies cleanly' do
866 host { 'test.server': ip => '127.0.0.1' }
867 apache::vhost { 'test.server':
870 { alias => '/image' , path => '/ftp/pub/image' } ,
871 { scriptalias => '/myscript' , path => '/usr/share/myscript' }
875 apply_manifest(pp, :catch_failures => true)
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"' }
885 describe 'scriptaliases' do
886 it 'applies cleanly' do
889 host { 'test.server': ip => '127.0.0.1' }
890 apache::vhost { 'test.server':
892 scriptaliases => [{ alias => '/myscript', path => '/usr/share/myscript', }],
895 apply_manifest(pp, :catch_failures => true)
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"' }
905 it 'applies cleanly' do
907 class { 'apache': service_ensure => stopped, }
908 host { 'test.server': ip => '127.0.0.1' }
909 apache::vhost { 'test.server':
911 proxy_dest => 'test2',
914 apply_manifest(pp, :catch_failures => true)
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/' }
923 describe 'actions' do
924 it 'applies cleanly' do
927 host { 'test.server': ip => '127.0.0.1' }
928 apache::vhost { 'test.server':
930 action => 'php-fastcgi',
933 pp = pp + "\nclass { 'apache::mod::actions': }" if fact('osfamily') == 'Debian'
934 apply_manifest(pp, :catch_failures => true)
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' }
944 it 'applies cleanly' do
946 class { 'apache': service_ensure => stopped, }
947 host { 'test.server': ip => '127.0.0.1' }
948 apache::vhost { 'test.server':
950 suphp_addhandler => '#{$suphp_handler}',
951 suphp_engine => 'on',
952 suphp_configpath => '#{$suphp_configpath}',
955 apply_manifest(pp, :catch_failures => true)
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}\"" }
966 describe 'no_proxy_uris' do
967 it 'applies cleanly' do
969 class { 'apache': service_ensure => stopped, }
970 host { 'test.server': ip => '127.0.0.1' }
971 apache::vhost { 'test.server':
973 proxy_dest => 'http://test2',
974 no_proxy_uris => [ 'http://test2/test' ],
977 apply_manifest(pp, :catch_failures => true)
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 !' }
987 describe 'redirect' do
988 it 'applies cleanly' do
991 host { 'test.server': ip => '127.0.0.1' }
992 apache::vhost { 'test.server':
994 redirect_source => ['/images'],
995 redirect_dest => ['http://test.server/'],
996 redirect_status => ['permanent'],
999 apply_manifest(pp, :catch_failures => true)
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/' }
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')
1013 describe 'rack_base_uris' do
1014 if fact('osfamily') == 'RedHat'
1016 pp = "class { 'epel': }"
1017 apply_manifest(pp, :catch_failures => true)
1021 it 'applies cleanly' do
1024 host { 'test.server': ip => '127.0.0.1' }
1025 apache::vhost { 'test.server':
1027 rack_base_uris => ['/test'],
1030 apply_manifest(pp, :catch_failures => true)
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' }
1042 describe 'request_headers' do
1043 it 'applies cleanly' do
1046 host { 'test.server': ip => '127.0.0.1' }
1047 apache::vhost { 'test.server':
1049 request_headers => ['append MirrorID "mirror 12"'],
1052 apply_manifest(pp, :catch_failures => true)
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"' }
1061 describe 'rewrite rules' do
1062 it 'applies cleanly' do
1065 host { 'test.server': ip => '127.0.0.1' }
1066 apache::vhost { 'test.server':
1069 { comment => 'test',
1070 rewrite_cond => '%{HTTP_USER_AGENT} ^Lynx/ [OR]',
1071 rewrite_rule => ['^index\.html$ welcome.html'],
1072 rewrite_map => ['lc int:tolower'],
1077 apply_manifest(pp, :catch_failures => true)
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' }
1089 describe 'directory rewrite rules' do
1090 it 'applies cleanly' do
1093 host { 'test.server': ip => '127.0.0.1' }
1094 if ! defined(Class['apache::mod::rewrite']) {
1095 include ::apache::mod::rewrite
1097 apache::vhost { 'test.server':
1104 comment => 'Permalink Rewrites',
1105 rewrite_base => '/',
1107 { rewrite_rule => [ '^index\\.php$ - [L]' ] },
1109 '%{REQUEST_FILENAME} !-f',
1110 '%{REQUEST_FILENAME} !-d', ], rewrite_rule => [ '. /index.php [L]' ], }
1116 apply_manifest(pp, :catch_failures => true)
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]' }
1131 describe 'setenv/setenvif' do
1132 it 'applies cleanly' do
1135 host { 'test.server': ip => '127.0.0.1' }
1136 apache::vhost { 'test.server':
1138 setenv => ['TEST /test'],
1139 setenvif => ['Request_URI "\.gif$" object_is_image=gif']
1142 apply_manifest(pp, :catch_failures => true)
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' }
1153 it 'applies cleanly' do
1156 host { 'test.server': ip => '127.0.0.1' }
1157 apache::vhost { 'test.server':
1162 apply_manifest(pp, :catch_failures => true)
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)/.*>' }
1172 it 'import_script applies cleanly' do
1175 class { 'apache::mod::wsgi': }
1176 host { 'test.server': ip => '127.0.0.1' }
1177 apache::vhost { 'test.server':
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',
1187 apply_manifest(pp, :catch_failures => true)
1190 it 'import_script applies cleanly', :unless => (fact('lsbdistcodename') == 'lucid' or UNSUPPORTED_PLATFORMS.include?(fact('osfamily'))) do
1193 class { 'apache::mod::wsgi': }
1194 host { 'test.server': ip => '127.0.0.1' }
1195 apache::vhost { 'test.server':
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',
1208 apply_manifest(pp, :catch_failures => true)
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' }
1223 describe 'custom_fragment' do
1224 it 'applies cleanly' do
1227 host { 'test.server': ip => '127.0.0.1' }
1228 apache::vhost { 'test.server':
1230 custom_fragment => inline_template('#weird test string'),
1233 apply_manifest(pp, :catch_failures => true)
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' }
1243 it 'applies cleanly' do
1246 host { 'test.server': ip => '127.0.0.1' }
1247 apache::vhost { 'test.server':
1249 itk => { user => 'nobody', group => 'nobody' }
1252 apply_manifest(pp, :catch_failures => true)
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' }
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
1267 class { 'apache::mod::fastcgi': }
1268 host { 'test.server': ip => '127.0.0.1' }
1269 apache::vhost { 'test.server':
1271 fastcgi_server => 'localhost',
1272 fastcgi_socket => '/tmp/fast/1234',
1273 fastcgi_dir => '/tmp/fast',
1276 apply_manifest(pp, :catch_failures => true)
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">' }
1287 describe 'additional_includes' do
1288 it 'applies cleanly' do
1290 if $::osfamily == 'RedHat' and $::selinux {
1291 $semanage_package = $::operatingsystemmajrelease ? {
1292 '5' => 'policycoreutils',
1293 default => 'policycoreutils-python',
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],
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'],
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',
1317 apply_manifest(pp, :catch_failures => true)
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"' }
1326 describe 'virtualhost without priority prefix' do
1327 it 'applies cleanly' do
1330 apache::vhost { 'test.server':
1335 apply_manifest(pp, :catch_failures => true)
1338 describe file("#{$vhost_dir}/test.server.conf") do
1339 it { is_expected.to be_file }