3 describe 'apache', :type => :class do
4 context "on a Debian OS" do
9 :lsbdistcodename => 'squeeze',
10 :osfamily => 'Debian',
11 :operatingsystem => 'Debian',
12 :operatingsystemrelease => '6',
13 :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
14 :concat_basedir => '/dne',
18 it { is_expected.to contain_class("apache::params") }
19 it { is_expected.to contain_package("httpd").with(
20 'notify' => 'Class[Apache::Service]',
21 'ensure' => 'installed'
24 it { is_expected.to contain_user("www-data") }
25 it { is_expected.to contain_group("www-data") }
26 it { is_expected.to contain_class("apache::service") }
27 it { is_expected.to contain_file("/var/www").with(
28 'ensure' => 'directory'
31 it { is_expected.to contain_file("/etc/apache2/sites-enabled").with(
32 'ensure' => 'directory',
35 'notify' => 'Class[Apache::Service]',
36 'require' => 'Package[httpd]'
39 it { is_expected.to contain_file("/etc/apache2/mods-enabled").with(
40 'ensure' => 'directory',
43 'notify' => 'Class[Apache::Service]',
44 'require' => 'Package[httpd]'
47 it { is_expected.to contain_file("/etc/apache2/mods-available").with(
48 'ensure' => 'directory',
51 'notify' => 'Class[Apache::Service]',
52 'require' => 'Package[httpd]'
55 it { is_expected.to contain_concat("/etc/apache2/ports.conf").with(
59 'notify' => 'Class[Apache::Service]'
62 # Assert that load files are placed and symlinked for these mods, but no conf file.
73 it { is_expected.to contain_file("#{modname}.load").with(
74 'path' => "/etc/apache2/mods-available/#{modname}.load",
77 it { is_expected.to contain_file("#{modname}.load symlink").with(
78 'path' => "/etc/apache2/mods-enabled/#{modname}.load",
80 'target' => "/etc/apache2/mods-available/#{modname}.load"
82 it { is_expected.not_to contain_file("#{modname}.conf") }
83 it { is_expected.not_to contain_file("#{modname}.conf symlink") }
86 context "with Apache version < 2.4" do
88 { :apache_version => '2.2' }
91 it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^Include "/etc/apache2/conf\.d/\*\.conf"$} }
94 context "with Apache version >= 2.4" do
97 :apache_version => '2.4',
98 :use_optional_includes => true
102 it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^IncludeOptional "/etc/apache2/conf\.d/\*\.conf"$} }
105 context "when specifying slash encoding behaviour" do
107 { :allow_encoded_slashes => 'nodecode' }
110 it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^AllowEncodedSlashes nodecode$} }
113 context "when specifying default character set" do
115 { :default_charset => 'none' }
118 it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^AddDefaultCharset none$} }
121 # Assert that both load files and conf files are placed and symlinked for these mods
132 it { is_expected.to contain_file("#{modname}.load").with(
133 'path' => "/etc/apache2/mods-available/#{modname}.load",
136 it { is_expected.to contain_file("#{modname}.load symlink").with(
137 'path' => "/etc/apache2/mods-enabled/#{modname}.load",
139 'target' => "/etc/apache2/mods-available/#{modname}.load"
141 it { is_expected.to contain_file("#{modname}.conf").with(
142 'path' => "/etc/apache2/mods-available/#{modname}.conf",
145 it { is_expected.to contain_file("#{modname}.conf symlink").with(
146 'path' => "/etc/apache2/mods-enabled/#{modname}.conf",
148 'target' => "/etc/apache2/mods-available/#{modname}.conf"
152 describe "Check default type" do
153 context "with Apache version < 2.4" do
156 :apache_version => '2.2',
160 context "when default_type => 'none'" do
162 { :default_type => 'none' }
165 it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^DefaultType none$} }
167 context "when default_type => 'text/plain'" do
169 { :default_type => 'text/plain' }
172 it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^DefaultType text/plain$} }
176 context "with Apache version >= 2.4" do
179 :apache_version => '2.4',
182 it { is_expected.to contain_file("/etc/apache2/apache2.conf").without_content %r{^DefaultType [.]*$} }
186 describe "Don't create user resource" do
187 context "when parameter manage_user is false" do
189 { :manage_user => false }
192 it { is_expected.not_to contain_user('www-data') }
193 it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^User www-data\n} }
196 describe "Don't create group resource" do
197 context "when parameter manage_group is false" do
199 { :manage_group => false }
202 it { is_expected.not_to contain_group('www-data') }
203 it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^Group www-data\n} }
207 describe "Add extra LogFormats" do
208 context "When parameter log_formats is a hash" do
211 'vhost_common' => "%v %h %l %u %t \"%r\" %>s %b",
212 'vhost_combined' => "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
216 it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common\n} }
217 it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%\{Referer\}i\" \"%\{User-agent\}i\"" vhost_combined\n} }
221 describe "Override existing LogFormats" do
222 context "When parameter log_formats is a hash" do
225 'common' => "%v %h %l %u %t \"%r\" %>s %b",
226 'combined' => "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
230 it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b" common\n} }
231 it { is_expected.to contain_file("/etc/apache2/apache2.conf").without_content %r{^LogFormat "%h %l %u %t \"%r\" %>s %b \"%\{Referer\}i\" \"%\{User-agent\}i\"" combined\n} }
232 it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b" common\n} }
233 it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%\{Referer\}i\" \"%\{User-agent\}i\"" combined\n} }
234 it { is_expected.to contain_file("/etc/apache2/apache2.conf").without_content %r{^LogFormat "%h %l %u %t \"%r\" %>s %b \"%\{Referer\}i\" \"%\{User-agent\}i\"" combined\n} }
238 context "on Ubuntu" do
241 :operatingsystem => 'Ubuntu'
248 :lsbdistrelease => '13.10',
249 :operatingsystemrelease => '13.10'
252 it { is_expected.to contain_class('apache').with_apache_version('2.4') }
257 :lsbdistrelease => '12.04',
258 :operatingsystemrelease => '12.04'
261 it { is_expected.to contain_class('apache').with_apache_version('2.2') }
266 :lsbdistrelease => '13.04',
267 :operatingsystemrelease => '13.04'
270 it { is_expected.to contain_class('apache').with_apache_version('2.2') }
274 context "on a RedHat 5 OS" do
279 :osfamily => 'RedHat',
280 :operatingsystem => 'RedHat',
281 :operatingsystemrelease => '5',
282 :concat_basedir => '/dne',
283 :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
287 it { is_expected.to contain_class("apache::params") }
288 it { is_expected.to contain_package("httpd").with(
289 'notify' => 'Class[Apache::Service]',
290 'ensure' => 'installed'
293 it { is_expected.to contain_user("apache") }
294 it { is_expected.to contain_group("apache") }
295 it { is_expected.to contain_class("apache::service") }
296 it { is_expected.to contain_file("/var/www/html").with(
297 'ensure' => 'directory'
300 it { is_expected.to contain_file("/etc/httpd/conf.d").with(
301 'ensure' => 'directory',
304 'notify' => 'Class[Apache::Service]',
305 'require' => 'Package[httpd]'
308 it { is_expected.to contain_concat("/etc/httpd/conf/ports.conf").with(
312 'notify' => 'Class[Apache::Service]'
315 describe "Alternate confd/mod/vhosts directory" do
318 :vhost_dir => '/etc/httpd/site.d',
319 :confd_dir => '/etc/httpd/conf.d',
320 :mod_dir => '/etc/httpd/mod.d',
324 ['mod.d','site.d','conf.d'].each do |dir|
325 it { is_expected.to contain_file("/etc/httpd/#{dir}").with(
326 'ensure' => 'directory',
329 'notify' => 'Class[Apache::Service]',
330 'require' => 'Package[httpd]'
334 # Assert that load files are placed for these mods, but no conf file.
345 it { is_expected.to contain_file("#{modname}.load").with_path(
346 "/etc/httpd/mod.d/#{modname}.load"
348 it { is_expected.not_to contain_file("#{modname}.conf").with_path(
349 "/etc/httpd/mod.d/#{modname}.conf"
353 # Assert that both load files and conf files are placed for these mods
364 it { is_expected.to contain_file("#{modname}.load").with_path(
365 "/etc/httpd/mod.d/#{modname}.load"
367 it { is_expected.to contain_file("#{modname}.conf").with_path(
368 "/etc/httpd/mod.d/#{modname}.conf"
372 context "with Apache version < 2.4" do
374 { :apache_version => '2.2' }
377 it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Include "/etc/httpd/conf\.d/\*\.conf"$} }
380 context "with Apache version >= 2.4" do
383 :apache_version => '2.4',
384 :use_optional_includes => true
388 it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^IncludeOptional "/etc/httpd/conf\.d/\*\.conf"$} }
391 context "when specifying slash encoding behaviour" do
393 { :allow_encoded_slashes => 'nodecode' }
396 it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^AllowEncodedSlashes nodecode$} }
399 context "when specifying default character set" do
401 { :default_charset => 'none' }
404 it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^AddDefaultCharset none$} }
407 context "with Apache version < 2.4" do
410 :apache_version => '2.2',
414 context "when default_type => 'none'" do
416 { :default_type => 'none' }
419 it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^DefaultType none$} }
421 context "when default_type => 'text/plain'" do
423 { :default_type => 'text/plain' }
426 it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^DefaultType text/plain$} }
430 context "with Apache version >= 2.4" do
433 :apache_version => '2.4',
436 it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").without_content %r{^DefaultType [.]*$} }
439 it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Include "/etc/httpd/site\.d/\*"$} }
440 it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Include "/etc/httpd/mod\.d/\*\.conf"$} }
441 it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Include "/etc/httpd/mod\.d/\*\.load"$} }
444 describe "Alternate conf directory" do
446 { :conf_dir => '/opt/rh/root/etc/httpd/conf' }
449 it { is_expected.to contain_file("/opt/rh/root/etc/httpd/conf/httpd.conf").with(
451 'notify' => 'Class[Apache::Service]',
452 'require' => 'Package[httpd]'
456 describe "Alternate conf.d directory" do
458 { :confd_dir => '/etc/httpd/special_conf.d' }
461 it { is_expected.to contain_file("/etc/httpd/special_conf.d").with(
462 'ensure' => 'directory',
465 'notify' => 'Class[Apache::Service]',
466 'require' => 'Package[httpd]'
470 describe "Alternate mpm_modules" do
471 context "when declaring mpm_module is false" do
473 { :mpm_module => false }
475 it 'should not declare mpm modules' do
476 is_expected.not_to contain_class('apache::mod::event')
477 is_expected.not_to contain_class('apache::mod::itk')
478 is_expected.not_to contain_class('apache::mod::peruser')
479 is_expected.not_to contain_class('apache::mod::prefork')
480 is_expected.not_to contain_class('apache::mod::worker')
483 context "when declaring mpm_module => prefork" do
485 { :mpm_module => 'prefork' }
487 it { is_expected.to contain_class('apache::mod::prefork') }
488 it { is_expected.not_to contain_class('apache::mod::event') }
489 it { is_expected.not_to contain_class('apache::mod::itk') }
490 it { is_expected.not_to contain_class('apache::mod::peruser') }
491 it { is_expected.not_to contain_class('apache::mod::worker') }
493 context "when declaring mpm_module => worker" do
495 { :mpm_module => 'worker' }
497 it { is_expected.to contain_class('apache::mod::worker') }
498 it { is_expected.not_to contain_class('apache::mod::event') }
499 it { is_expected.not_to contain_class('apache::mod::itk') }
500 it { is_expected.not_to contain_class('apache::mod::peruser') }
501 it { is_expected.not_to contain_class('apache::mod::prefork') }
503 context "when declaring mpm_module => breakme" do
505 { :mpm_module => 'breakme' }
507 it { expect { catalogue }.to raise_error Puppet::Error, /does not match/ }
511 describe "different templates for httpd.conf" do
512 context "with default" do
514 { :conf_template => 'apache/httpd.conf.erb' }
516 it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^# Security\n} }
518 context "with non-default" do
520 { :conf_template => 'site_apache/fake.conf.erb' }
522 it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Fake template for rspec.$} }
526 describe "default mods" do
529 { :default_mods => false }
532 it { is_expected.to contain_apache__mod('authz_host') }
533 it { is_expected.not_to contain_apache__mod('env') }
547 it { is_expected.to contain_apache__mod('authz_host') }
548 it { is_expected.to contain_apache__mod('env') }
549 it { is_expected.to contain_class('apache::mod::info') }
550 it { is_expected.to contain_class('apache::mod::mime') }
553 describe "Don't create user resource" do
554 context "when parameter manage_user is false" do
556 { :manage_user => false }
559 it { is_expected.not_to contain_user('apache') }
560 it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^User apache\n} }
563 describe "Don't create group resource" do
564 context "when parameter manage_group is false" do
566 { :manage_group => false }
569 it { is_expected.not_to contain_group('apache') }
570 it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Group apache\n} }
574 describe "sendfile" do
575 context "with invalid value" do
577 { :sendfile => 'foo' }
582 end.to raise_error(Puppet::Error, /"foo" does not match/)
587 { :sendfile => 'On' }
589 it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^EnableSendfile On\n} }
593 { :sendfile => 'Off' }
595 it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^EnableSendfile Off\n} }
598 context "on Fedora" do
601 :operatingsystem => 'Fedora'
608 :lsbdistrelease => '21',
609 :operatingsystemrelease => '21'
612 it { is_expected.to contain_class('apache').with_apache_version('2.4') }
617 :lsbdistrelease => 'Rawhide',
618 :operatingsystemrelease => 'Rawhide'
621 it { is_expected.to contain_class('apache').with_apache_version('2.4') }
627 :lsbdistrelease => '17',
628 :operatingsystemrelease => '17'
631 it { is_expected.to contain_class('apache').with_apache_version('2.2') }
635 context "on a FreeBSD OS" do
639 :kernel => 'FreeBSD',
640 :osfamily => 'FreeBSD',
641 :operatingsystem => 'FreeBSD',
642 :operatingsystemrelease => '10',
643 :concat_basedir => '/dne',
644 :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
648 it { is_expected.to contain_class("apache::params") }
649 it { is_expected.to contain_class("apache::package").with({'ensure' => 'present'}) }
650 it { is_expected.to contain_user("www") }
651 it { is_expected.to contain_group("www") }
652 it { is_expected.to contain_class("apache::service") }
653 it { is_expected.to contain_file("/usr/local/www/apache24/data").with(
654 'ensure' => 'directory'
657 it { is_expected.to contain_file("/usr/local/etc/apache24/Vhosts").with(
658 'ensure' => 'directory',
661 'notify' => 'Class[Apache::Service]',
662 'require' => 'Package[httpd]'
664 it { is_expected.to contain_file("/usr/local/etc/apache24/Modules").with(
665 'ensure' => 'directory',
668 'notify' => 'Class[Apache::Service]',
669 'require' => 'Package[httpd]'
671 it { is_expected.to contain_concat("/usr/local/etc/apache24/ports.conf").with(
675 'notify' => 'Class[Apache::Service]'
677 # Assert that load files are placed for these mods, but no conf file.
688 it { is_expected.to contain_file("#{modname}.load").with(
689 'path' => "/usr/local/etc/apache24/Modules/#{modname}.load",
692 it { is_expected.not_to contain_file("#{modname}.conf") }
695 # Assert that both load files and conf files are placed for these mods
706 it { is_expected.to contain_file("#{modname}.load").with(
707 'path' => "/usr/local/etc/apache24/Modules/#{modname}.load",
710 it { is_expected.to contain_file("#{modname}.conf").with(
711 'path' => "/usr/local/etc/apache24/Modules/#{modname}.conf",
716 context "on a Gentoo OS" do
721 :osfamily => 'Gentoo',
722 :operatingsystem => 'Gentoo',
723 :operatingsystemrelease => '3.16.1-gentoo',
724 :concat_basedir => '/dne',
725 :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin',
729 it { is_expected.to contain_class("apache::params") }
730 it { is_expected.to contain_user("apache") }
731 it { is_expected.to contain_group("apache") }
732 it { is_expected.to contain_class("apache::service") }
733 it { is_expected.to contain_file("/var/www/localhost/htdocs").with(
734 'ensure' => 'directory'
737 it { is_expected.to contain_file("/etc/apache2/vhosts.d").with(
738 'ensure' => 'directory',
741 'notify' => 'Class[Apache::Service]',
742 'require' => 'Package[httpd]'
744 it { is_expected.to contain_file("/etc/apache2/modules.d").with(
745 'ensure' => 'directory',
748 'notify' => 'Class[Apache::Service]',
749 'require' => 'Package[httpd]'
751 it { is_expected.to contain_concat("/etc/apache2/ports.conf").with(
755 'notify' => 'Class[Apache::Service]'
758 context 'on all OSes' do
763 :osfamily => 'RedHat',
764 :operatingsystem => 'RedHat',
765 :operatingsystemrelease => '6',
766 :concat_basedir => '/dne',
767 :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
771 context 'with a custom apache_name parameter' do
773 :apache_name => 'httpd24-httpd'
776 it { is_expected.to contain_package("httpd").with(
777 'notify' => 'Class[Apache::Service]',
778 'ensure' => 'installed',
779 'name' => 'httpd24-httpd'
783 context 'default vhost defaults' do
784 it { is_expected.to contain_apache__vhost('default').with_ensure('present') }
785 it { is_expected.to contain_apache__vhost('default-ssl').with_ensure('absent') }
787 context 'without default non-ssl vhost' do
789 :default_vhost => false
792 it { is_expected.to contain_apache__vhost('default').with_ensure('absent') }
793 it { is_expected.not_to contain_file('/var/www/html') }
795 context 'with default ssl vhost' do
797 :default_ssl_vhost => true
800 it { is_expected.to contain_apache__vhost('default-ssl').with_ensure('present') }
801 it { is_expected.to contain_file('/var/www/html') }
804 context 'with unsupported osfamily' do
806 { :osfamily => 'Darwin',
807 :operatingsystemrelease => '13.1.0',
808 :concat_basedir => '/dne',
816 }.to raise_error(Puppet::Error, /Unsupported osfamily/)