diff --git a/spec/classes/apache_spec.rb b/spec/classes/apache_spec.rb index 3fb67b3b..25c88f07 100644 --- a/spec/classes/apache_spec.rb +++ b/spec/classes/apache_spec.rb @@ -1,837 +1,828 @@ # frozen_string_literal: true require 'spec_helper' describe 'apache', type: :class do context 'on a Debian OS' do - include_examples 'Debian 6' + include_examples 'Debian 8' it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_package('httpd').with( 'notify' => 'Class[Apache::Service]', 'ensure' => 'installed', ) } it { is_expected.to contain_user('www-data') } it { is_expected.to contain_group('www-data') } it { is_expected.to contain_class('apache::service') } it { - is_expected.to contain_file('/var/www').with( + is_expected.to contain_file('/var/www/html').with( 'ensure' => 'directory', ) } it { is_expected.to contain_file('/etc/apache2/sites-enabled').with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'true' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') } it { is_expected.to contain_file('/etc/apache2/mods-enabled').with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'true' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') } it { is_expected.to contain_file('/etc/apache2/mods-available').with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'false' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') } it { is_expected.to contain_concat('/etc/apache2/ports.conf').with( 'owner' => 'root', 'group' => 'root', 'mode' => '0644' ).that_notifies('Class[Apache::Service]') } # Assert that load files are placed and symlinked for these mods, but no conf file. - ['auth_basic', 'authn_file', 'authz_default', 'authz_groupfile', 'authz_host', 'authz_user', 'dav', 'env'].each do |modname| + ['auth_basic', 'authn_file', 'authz_groupfile', 'authz_host', 'authz_user', 'dav', 'env'].each do |modname| it { is_expected.to contain_file("#{modname}.load").with( 'path' => "/etc/apache2/mods-available/#{modname}.load", 'ensure' => 'file', ) } it { is_expected.to contain_file("#{modname}.load symlink").with( 'path' => "/etc/apache2/mods-enabled/#{modname}.load", 'ensure' => 'link', 'target' => "/etc/apache2/mods-available/#{modname}.load", ) } it { is_expected.not_to contain_file("#{modname}.conf") } it { is_expected.not_to contain_file("#{modname}.conf symlink") } end context 'with Apache version < 2.4' do let :params do { apache_version: '2.2' } end it { is_expected.to contain_file('/etc/apache2/apache2.conf').with_content %r{^Include "/etc/apache2/conf\.d/\*\.conf"$} } end context 'with Apache version >= 2.4' do let :params do { apache_version: '2.4', use_optional_includes: true, } end it { is_expected.to contain_file('/etc/apache2/apache2.conf').with_content %r{^IncludeOptional "/etc/apache2/conf\.d/\*\.conf"$} } end context 'when specifying slash encoding behaviour' do let :params do { allow_encoded_slashes: 'nodecode' } end it { is_expected.to contain_file('/etc/apache2/apache2.conf').with_content %r{^AllowEncodedSlashes nodecode$} } end context 'when specifying fileETag behaviour' do let :params do { file_e_tag: 'None' } end it { is_expected.to contain_file('/etc/apache2/apache2.conf').with_content %r{^FileETag None$} } end context 'when specifying canonical name behaviour' do let :params do { use_canonical_name: 'dns' } end it { is_expected.to contain_file('/etc/apache2/apache2.conf').with_content %r{^UseCanonicalName dns$} } end context 'when specifying default character set' do let :params do { default_charset: 'none' } end it { is_expected.to contain_file('/etc/apache2/apache2.conf').with_content %r{^AddDefaultCharset none$} } end # Assert that both load files and conf files are placed and symlinked for these mods ['alias', 'autoindex', 'dav_fs', 'deflate', 'dir', 'mime', 'negotiation', 'setenvif'].each do |modname| it { is_expected.to contain_file("#{modname}.load").with( 'path' => "/etc/apache2/mods-available/#{modname}.load", 'ensure' => 'file', ) } it { is_expected.to contain_file("#{modname}.load symlink").with( 'path' => "/etc/apache2/mods-enabled/#{modname}.load", 'ensure' => 'link', 'target' => "/etc/apache2/mods-available/#{modname}.load", ) } it { is_expected.to contain_file("#{modname}.conf").with( 'path' => "/etc/apache2/mods-available/#{modname}.conf", 'ensure' => 'file', ) } it { is_expected.to contain_file("#{modname}.conf symlink").with( 'path' => "/etc/apache2/mods-enabled/#{modname}.conf", 'ensure' => 'link', 'target' => "/etc/apache2/mods-available/#{modname}.conf", ) } end describe "Check default type with Apache version < 2.2 when default_type => 'none'" do let :params do { apache_version: '2.2', default_type: 'none', } end it { is_expected.to contain_file('/etc/apache2/apache2.conf').with_content %r{^DefaultType none$} } end describe "Check default type with Apache version < 2.2 when default_type => 'text/plain'" do let :params do { apache_version: '2.2', default_type: 'text/plain', } end it { is_expected.to contain_file('/etc/apache2/apache2.conf').with_content %r{^DefaultType text/plain$} } end describe 'Check default type with Apache version >= 2.4' do let :params do { apache_version: '2.4' } end it { is_expected.to contain_file('/etc/apache2/apache2.conf').without_content %r{^DefaultType [.]*$} } end describe "Don't create user resource when parameter manage_user is false" do let :params do { manage_user: false } end it { is_expected.not_to contain_user('www-data') } it { is_expected.to contain_file('/etc/apache2/apache2.conf').with_content %r{^User www-data\n} } end describe "Don't create group resource when parameter manage_group is false" do let :params do { manage_group: false } end it { is_expected.not_to contain_group('www-data') } it { is_expected.to contain_file('/etc/apache2/apache2.conf').with_content %r{^Group www-data\n} } end describe 'Add extra LogFormats When parameter log_formats is a hash' do let :params do { log_formats: { 'vhost_common' => '%v %h %l %u %t "%r" %>s %b', 'vhost_combined' => '%v %h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"', } } end 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} } 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} } end describe 'Override existing LogFormats When parameter log_formats is a hash' do let :params do { log_formats: { 'common' => '%v %h %l %u %t "%r" %>s %b', 'combined' => '%v %h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"', } } end expected = [ %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b" common\n}, %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b" common\n}, %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%\{Referer\}i\" \"%\{User-agent\}i\"" combined\n}, ] unexpected = [ %r{^LogFormat "%h %l %u %t \"%r\" %>s %b \"%\{Referer\}i\" \"%\{User-agent\}i\"" combined\n}, %r{^LogFormat "%h %l %u %t \"%r\" %>s %b \"%\{Referer\}i\" \"%\{User-agent\}i\"" combined\n}, ] it 'Expected to contain' do expected.each do |reg| is_expected.to contain_file('/etc/apache2/apache2.conf').with_content reg end end it 'Not expected to contain' do unexpected.each do |reg| is_expected.to contain_file('/etc/apache2/apache2.conf').without_content reg end end end - context '8' do - include_examples 'Debian 8' - - it { - is_expected.to contain_file('/var/www/html').with( - 'ensure' => 'directory', - ) - } - describe 'Alternate mpm_modules when declaring mpm_module => prefork' do - let :params do - { mpm_module: 'worker' } - end - - it { is_expected.to contain_exec('/usr/sbin/a2dismod event') } - it { is_expected.to contain_exec('/usr/sbin/a2dismod prefork') } + describe 'Alternate mpm_modules when declaring mpm_module => prefork' do + let :params do + { mpm_module: 'worker' } end + + it { is_expected.to contain_exec('/usr/sbin/a2dismod event') } + it { is_expected.to contain_exec('/usr/sbin/a2dismod prefork') } end context 'on Ubuntu 14.04' do include_examples 'Ubuntu 14.04' it { is_expected.to contain_file('/var/www/html').with( 'ensure' => 'directory', ) } end end context 'on a RedHat 5 OS' do include_examples 'RedHat 5' it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_package('httpd').with( 'notify' => 'Class[Apache::Service]', 'ensure' => 'installed', ) } it { is_expected.to contain_user('apache') } it { is_expected.to contain_group('apache') } it { is_expected.to contain_class('apache::service') } it { is_expected.to contain_file('/var/www/html').with( 'ensure' => 'directory', ) } it { is_expected.to contain_file('/etc/httpd/conf.d').with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'true' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') } it { is_expected.to contain_concat('/etc/httpd/conf/ports.conf').with( 'owner' => 'root', 'group' => 'root', 'mode' => '0644' ).that_notifies('Class[Apache::Service]') } describe 'Alternate confd/mod/vhosts directory' do let :params do { vhost_dir: '/etc/httpd/site.d', confd_dir: '/etc/httpd/conf.d', mod_dir: '/etc/httpd/mod.d', } end ['mod.d', 'site.d', 'conf.d'].each do |dir| it { is_expected.to contain_file("/etc/httpd/#{dir}").with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'true' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') } end # Assert that load files are placed for these mods, but no conf file. ['auth_basic', 'authn_file', 'authz_default', 'authz_groupfile', 'authz_host', 'authz_user', 'dav', 'env'].each do |modname| it { is_expected.to contain_file("#{modname}.load").with_path( "/etc/httpd/mod.d/#{modname}.load", ) } it { is_expected.not_to contain_file("#{modname}.conf").with_path( "/etc/httpd/mod.d/#{modname}.conf", ) } end # Assert that both load files and conf files are placed for these mods ['alias', 'autoindex', 'dav_fs', 'deflate', 'dir', 'mime', 'negotiation', 'setenvif'].each do |modname| it { is_expected.to contain_file("#{modname}.load").with_path( "/etc/httpd/mod.d/#{modname}.load", ) } it { is_expected.to contain_file("#{modname}.conf").with_path( "/etc/httpd/mod.d/#{modname}.conf", ) } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^Include "/etc/httpd/site\.d/\*"$} } it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^Include "/etc/httpd/mod\.d/\*\.conf"$} } it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^Include "/etc/httpd/mod\.d/\*\.load"$} } end describe 'Alternate confd/mod/vhosts directory with Apache version < 2.4' do let :params do { vhost_dir: '/etc/httpd/site.d', confd_dir: '/etc/httpd/conf.d', mod_dir: '/etc/httpd/mod.d', apache_version: '2.2', } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^Include "/etc/httpd/conf\.d/\*\.conf"$} } end describe 'Alternate confd/mod/vhosts directory with Apache version >= 2.4' do let :params do { vhost_dir: '/etc/httpd/site.d', confd_dir: '/etc/httpd/conf.d', mod_dir: '/etc/httpd/mod.d', apache_version: '2.4', use_optional_includes: true, } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^IncludeOptional "/etc/httpd/conf\.d/\*\.conf"$} } end describe 'Alternate confd/mod/vhosts directory with Apache version < 2.4' do let :params do { vhost_dir: '/etc/httpd/site.d', confd_dir: '/etc/httpd/conf.d', mod_dir: '/etc/httpd/mod.d', apache_version: '2.2', rewrite_lock: '/var/lock/subsys/rewrite-lock', } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^RewriteLock /var/lock/subsys/rewrite-lock$} } end describe 'Alternate confd/mod/vhosts directory with Apache version < 2.4' do let :params do { vhost_dir: '/etc/httpd/site.d', confd_dir: '/etc/httpd/conf.d', mod_dir: '/etc/httpd/mod.d', apache_version: '2.2', } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').without_content %r{^RewriteLock [.]*$} } end describe 'Alternate confd/mod/vhosts directory with Apache version >= 2.4' do let :params do { vhost_dir: '/etc/httpd/site.d', confd_dir: '/etc/httpd/conf.d', mod_dir: '/etc/httpd/mod.d', apache_version: '2.4', rewrite_lock: '/var/lock/subsys/rewrite-lock', } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').without_content %r{^RewriteLock [.]*$} } end describe 'Alternate confd/mod/vhosts directory when specifying slash encoding behaviour' do let :params do { vhost_dir: '/etc/httpd/site.d', confd_dir: '/etc/httpd/conf.d', mod_dir: '/etc/httpd/mod.d', allow_encoded_slashes: 'nodecode', } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^AllowEncodedSlashes nodecode$} } end describe 'Alternate confd/mod/vhosts directory when specifying default character set' do let :params do { vhost_dir: '/etc/httpd/site.d', confd_dir: '/etc/httpd/conf.d', mod_dir: '/etc/httpd/mod.d', default_charset: 'none', } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^AddDefaultCharset none$} } end describe "Alternate confd/mod/vhosts directory with Apache version < 2.4 when default_type => 'none'" do let :params do { vhost_dir: '/etc/httpd/site.d', confd_dir: '/etc/httpd/conf.d', mod_dir: '/etc/httpd/mod.d', apache_version: '2.2', default_type: 'none', } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^DefaultType none$} } end describe "Alternate confd/mod/vhosts directory with Apache version < 2.4 when default_type => 'text/plain'" do let :params do { vhost_dir: '/etc/httpd/site.d', confd_dir: '/etc/httpd/conf.d', mod_dir: '/etc/httpd/mod.d', apache_version: '2.2', default_type: 'text/plain', } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^DefaultType text/plain$} } end describe 'Alternate confd/mod/vhosts directory with Apache version >= 2.4' do let :params do { vhost_dir: '/etc/httpd/site.d', confd_dir: '/etc/httpd/conf.d', mod_dir: '/etc/httpd/mod.d', apache_version: '2.4', } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').without_content %r{^DefaultType [.]*$} } end describe 'Alternate conf directory' do let :params do { conf_dir: '/opt/rh/root/etc/httpd/conf' } end it { is_expected.to contain_file('/opt/rh/root/etc/httpd/conf/httpd.conf').with( 'ensure' => 'file', ).that_notifies('Class[Apache::Service]').that_requires(['Package[httpd]', 'Concat[/etc/httpd/conf/ports.conf]']) } end describe 'Alternate conf.d directory' do let :params do { confd_dir: '/etc/httpd/special_conf.d' } end it { is_expected.to contain_file('/etc/httpd/special_conf.d').with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'true' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') } end describe 'Alternate mpm_modules when declaring mpm_module is false' do let :params do { mpm_module: false } end unexpected = ['apache::mod::event', 'apache::mod::itk', 'apache::mod::peruser', 'apache::mod::prefork', 'apache::mod::worker'] it 'does not declare mpm modules' do unexpected.each do |not_expect| is_expected.not_to contain_class(not_expect) end end end describe 'Alternate mpm_modules when declaring mpm_module => prefork' do let :params do { mpm_module: 'prefork' } end it { is_expected.to contain_class('apache::mod::prefork') } it { is_expected.not_to contain_class('apache::mod::event') } it { is_expected.not_to contain_class('apache::mod::itk') } it { is_expected.not_to contain_class('apache::mod::peruser') } it { is_expected.not_to contain_class('apache::mod::worker') } end describe 'Alternate mpm_modules when declaring mpm_module => worker' do let :params do { mpm_module: 'worker' } end it { is_expected.to contain_class('apache::mod::worker') } it { is_expected.not_to contain_class('apache::mod::event') } it { is_expected.not_to contain_class('apache::mod::itk') } it { is_expected.not_to contain_class('apache::mod::peruser') } it { is_expected.not_to contain_class('apache::mod::prefork') } end describe 'different templates for httpd.conf with default' do let :params do { conf_template: 'apache/httpd.conf.erb' } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^# Security\n} } end describe 'different templates for httpd.conf with non-default' do let :params do { conf_template: 'site_apache/fake.conf.erb' } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^Fake template for rspec.$} } end describe 'default mods without' do let :params do { default_mods: false } end it { is_expected.to contain_apache__mod('authz_host') } it { is_expected.not_to contain_apache__mod('env') } end describe 'default mods custom' do let :params do { default_mods: ['info', 'alias', 'mime', 'env', 'setenv', 'expires'] } end it { is_expected.to contain_apache__mod('authz_host') } it { is_expected.to contain_apache__mod('env') } it { is_expected.to contain_class('apache::mod::info') } it { is_expected.to contain_class('apache::mod::mime') } end describe "Don't create user resource when parameter manage_user is false" do let :params do { manage_user: false } end it { is_expected.not_to contain_user('apache') } it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^User apache\n} } end describe "Don't create group resource when parameter manage_group is false" do let :params do { manage_group: false } end it { is_expected.not_to contain_group('apache') } it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^Group apache\n} } end describe 'sendfile with invalid value' do let :params do { sendfile: 'foo' } end it 'fails' do expect { catalogue }.to raise_error(Puppet::PreformattedError, %r{Evaluation Error: Error while evaluating a Resource Statement, Class\[Apache\]: parameter 'sendfile' expects a match for Enum\['Off', 'On', 'off', 'on'\]}) # rubocop:disable Layout/LineLength end end describe 'sendfile On' do let :params do { sendfile: 'On' } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^EnableSendfile On\n} } end describe 'sendfile Off' do let :params do { sendfile: 'Off' } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^EnableSendfile Off\n} } end describe 'hostname lookup with invalid value' do let :params do { hostname_lookups: 'foo' } end it 'fails' do expect { catalogue }.to raise_error(Puppet::Error, %r{Evaluation Error}) end end describe 'hostname_lookups On' do let :params do { hostname_lookups: 'On' } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^HostnameLookups On\n} } end describe 'hostname_lookups Off' do let :params do { hostname_lookups: 'Off' } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^HostnameLookups Off\n} } end describe 'hostname_lookups Double' do let :params do { hostname_lookups: 'Double' } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^HostnameLookups Double\n} } end context 'on Fedora 21' do include_examples 'Fedora 21' it { is_expected.to contain_class('apache').with_apache_version('2.4') } end context 'on Fedora Rawhide' do include_examples 'Fedora Rawhide' it { is_expected.to contain_class('apache').with_apache_version('2.4') } end # kinda obsolete context 'on Fedora 17' do include_examples 'Fedora 17' it { is_expected.to contain_class('apache').with_apache_version('2.2') } end end context 'on a FreeBSD OS' do include_examples 'FreeBSD 10' it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_class('apache::package').with('ensure' => 'present') } it { is_expected.to contain_user('www') } it { is_expected.to contain_group('www') } it { is_expected.to contain_class('apache::service') } it { is_expected.to contain_file('/usr/local/www/apache24/data').with( 'ensure' => 'directory', ) } it { is_expected.to contain_file('/usr/local/etc/apache24/Vhosts').with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'true' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') } it { is_expected.to contain_file('/usr/local/etc/apache24/Modules').with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'true' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') } it { is_expected.to contain_concat('/usr/local/etc/apache24/ports.conf').with( 'owner' => 'root', 'group' => 'wheel', 'mode' => '0644' ).that_notifies('Class[Apache::Service]') } # Assert that load files are placed for these mods, but no conf file. ['auth_basic', 'authn_core', 'authn_file', 'authz_groupfile', 'authz_host', 'authz_user', 'dav', 'env'].each do |modname| it { is_expected.to contain_file("#{modname}.load").with( 'path' => "/usr/local/etc/apache24/Modules/#{modname}.load", 'ensure' => 'file', ) } it { is_expected.not_to contain_file("#{modname}.conf") } end # Assert that both load files and conf files are placed for these mods ['alias', 'autoindex', 'dav_fs', 'deflate', 'dir', 'mime', 'negotiation', 'setenvif'].each do |modname| it { is_expected.to contain_file("#{modname}.load").with( 'path' => "/usr/local/etc/apache24/Modules/#{modname}.load", 'ensure' => 'file', ) } it { is_expected.to contain_file("#{modname}.conf").with( 'path' => "/usr/local/etc/apache24/Modules/#{modname}.conf", 'ensure' => 'file', ) } end end context 'on a Gentoo OS' do include_examples 'Gentoo' it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_user('apache') } it { is_expected.to contain_group('apache') } it { is_expected.to contain_class('apache::service') } it { is_expected.to contain_file('/var/www/localhost/htdocs').with( 'ensure' => 'directory', ) } it { is_expected.to contain_file('/etc/apache2/vhosts.d').with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'true' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') } it { is_expected.to contain_file('/etc/apache2/modules.d').with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'true' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') } it { is_expected.to contain_concat('/etc/apache2/ports.conf').with( 'owner' => 'root', 'group' => 'wheel', 'mode' => '0644' ).that_notifies('Class[Apache::Service]') } end context 'on all OSes' do include_examples 'RedHat 6' context 'with a custom apache_name parameter' do let :params do { apache_name: 'httpd24-httpd', } end it { is_expected.to contain_package('httpd').with( 'ensure' => 'installed', 'name' => 'httpd24-httpd', ).that_notifies('Class[Apache::Service]') } end context 'with a custom file_mode parameter' do let :params do { file_mode: '0640', } end it { is_expected.to contain_concat('/etc/httpd/conf/ports.conf').with( 'mode' => '0640', ) } end context 'with a custom root_directory_options parameter' do let :params do { root_directory_options: ['-Indexes', '-FollowSymLinks'], } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{Options -Indexes -FollowSymLinks} } end context 'with a custom root_directory_secured parameter and Apache < 2.4' do let :params do { apache_version: '2.2', root_directory_secured: true, } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{Options FollowSymLinks\n\s+AllowOverride None\n\s+Order deny,allow\n\s+Deny from all} } end context 'with a custom root_directory_secured parameter and Apache >= 2.4' do let :params do { apache_version: '2.4', root_directory_secured: true, } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{Options FollowSymLinks\n\s+AllowOverride None\n\s+Require all denied} } end context 'default vhost defaults' do it { is_expected.to contain_apache__vhost('default').with_ensure('present') } it { is_expected.to contain_apache__vhost('default-ssl').with_ensure('absent') } it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{Options FollowSymLinks} } end context 'without default non-ssl vhost' do let :params do { default_vhost: false, } end it { is_expected.to contain_apache__vhost('default').with_ensure('absent') } it { is_expected.not_to contain_file('/var/www/html') } end context 'with default ssl vhost' do let :params do { default_ssl_vhost: true, } end it { is_expected.to contain_apache__vhost('default-ssl').with_ensure('present') } it { is_expected.to contain_file('/var/www/html') } end end context 'with unsupported osfamily' do include_examples 'Darwin' it { is_expected.to compile.and_raise_error(%r{Unsupported osfamily}) } end end diff --git a/spec/classes/mod/auth_gssapi_spec.rb b/spec/classes/mod/auth_gssapi_spec.rb index 071ed768..231450f0 100644 --- a/spec/classes/mod/auth_gssapi_spec.rb +++ b/spec/classes/mod/auth_gssapi_spec.rb @@ -1,38 +1,38 @@ # frozen_string_literal: true require 'spec_helper' describe 'apache::mod::auth_gssapi', type: :class do it_behaves_like 'a mod class, without including apache' context 'default configuration with parameters' do context 'on a Debian OS', :compile do - include_examples 'Debian 6' + include_examples 'Debian 8' it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('auth_gssapi') } it { is_expected.to contain_package('libapache2-mod-auth-gssapi') } end context 'on a RedHat OS', :compile do include_examples 'RedHat 6' it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('auth_gssapi') } it { is_expected.to contain_package('mod_auth_gssapi') } end context 'on a FreeBSD OS', :compile do include_examples 'FreeBSD 9' it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('auth_gssapi') } it { is_expected.to contain_package('www/mod_auth_gssapi') } end context 'on a Gentoo OS', :compile do include_examples 'Gentoo' it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('auth_gssapi') } it { is_expected.to contain_package('www-apache/mod_auth_gssapi') } end end end diff --git a/spec/classes/mod/auth_kerb_spec.rb b/spec/classes/mod/auth_kerb_spec.rb index ea2fe8fe..dd1dd482 100644 --- a/spec/classes/mod/auth_kerb_spec.rb +++ b/spec/classes/mod/auth_kerb_spec.rb @@ -1,57 +1,57 @@ # frozen_string_literal: true require 'spec_helper' describe 'apache::mod::auth_kerb', type: :class do it_behaves_like 'a mod class, without including apache' context 'default configuration with parameters' do context 'on a Debian OS', :compile do - include_examples 'Debian 6' + include_examples 'Debian 8' it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('auth_kerb') } it { is_expected.to contain_package('libapache2-mod-auth-kerb') } end context 'on a RedHat OS', :compile do include_examples 'RedHat 6' it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('auth_kerb') } it { is_expected.to contain_package('mod_auth_kerb') } end context 'on a FreeBSD OS', :compile do include_examples 'FreeBSD 9' it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('auth_kerb') } it { is_expected.to contain_package('www/mod_auth_kerb2') } end context 'on a Gentoo OS', :compile do include_examples 'Gentoo' it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('auth_kerb') } it { is_expected.to contain_package('www-apache/mod_auth_kerb') } end end context 'overriding mod_packages' do context 'on a RedHat OS', :compile do include_examples 'RedHat 6' let :pre_condition do <<-MANIFEST include apache::params class { 'apache': mod_packages => merge($::apache::params::mod_packages, { 'auth_kerb' => 'httpd24-mod_auth_kerb', }) } MANIFEST end it { is_expected.to contain_apache__mod('auth_kerb') } it { is_expected.to contain_package('httpd24-mod_auth_kerb') } it { is_expected.not_to contain_package('mod_auth_kerb') } end end end diff --git a/spec/classes/mod/info_spec.rb b/spec/classes/mod/info_spec.rb index 316863a9..a24d1122 100644 --- a/spec/classes/mod/info_spec.rb +++ b/spec/classes/mod/info_spec.rb @@ -1,177 +1,177 @@ # frozen_string_literal: true require 'spec_helper' # This function is called inside the OS specific contexts def general_info_specs_apache22 it { is_expected.to contain_apache__mod('info') } context 'passing no parameters' do expected = "\n"\ " SetHandler server-info\n"\ " Order deny,allow\n"\ " Deny from all\n"\ " Allow from 127.0.0.1\n"\ " Allow from ::1\n"\ "\n" it { is_expected.to contain_file('info.conf').with_content(expected) } end context 'passing restrict_access => false' do let :params do { restrict_access: false, } end it { is_expected.to contain_file('info.conf').with_content( "\n"\ " SetHandler server-info\n"\ "\n", ) } end context "passing allow_from => ['10.10.1.2', '192.168.1.2', '127.0.0.1']" do let :params do { allow_from: ['10.10.1.2', '192.168.1.2', '127.0.0.1'] } end expected = "\n"\ " SetHandler server-info\n"\ " Order deny,allow\n"\ " Deny from all\n"\ " Allow from 10.10.1.2\n"\ " Allow from 192.168.1.2\n"\ " Allow from 127.0.0.1\n"\ "\n" it { is_expected.to contain_file('info.conf').with_content(expected) } end context 'passing both restrict_access and allow_from' do let :params do { restrict_access: false, allow_from: ['10.10.1.2', '192.168.1.2', '127.0.0.1'], } end it { is_expected.to contain_file('info.conf').with_content( "\n"\ " SetHandler server-info\n"\ "\n", ) } end end def general_info_specs_apache24 it { is_expected.to contain_apache__mod('info') } context 'passing no parameters' do expected = "\n"\ " SetHandler server-info\n"\ " Require ip 127.0.0.1 ::1\n"\ "\n" it { is_expected.to contain_file('info.conf').with_content(expected) } end context 'passing restrict_access => false' do let :params do { restrict_access: false, } end it { is_expected.to contain_file('info.conf').with_content( "\n"\ " SetHandler server-info\n"\ "\n", ) } end context "passing allow_from => ['10.10.1.2', '192.168.1.2', '127.0.0.1']" do let :params do { allow_from: ['10.10.1.2', '192.168.1.2', '127.0.0.1'] } end expected = "\n"\ " SetHandler server-info\n"\ " Require ip 10.10.1.2 192.168.1.2 127.0.0.1\n"\ "\n" it { is_expected.to contain_file('info.conf').with_content(expected) } end context 'passing both restrict_access and allow_from' do let :params do { restrict_access: false, allow_from: ['10.10.1.2', '192.168.1.2', '127.0.0.1'], } end it { is_expected.to contain_file('info.conf').with_content( "\n"\ " SetHandler server-info\n"\ "\n", ) } end end describe 'apache::mod::info', type: :class do it_behaves_like 'a mod class, without including apache' context 'On a Debian OS' do - include_examples 'Debian 6' + include_examples 'Debian 8' # Load the more generic tests for this context - general_info_specs_apache22 + general_info_specs_apache24 it { is_expected.to contain_file('info.conf').with(ensure: 'file', path: '/etc/apache2/mods-available/info.conf') } it { is_expected.to contain_file('info.conf symlink').with(ensure: 'link', path: '/etc/apache2/mods-enabled/info.conf') } end context 'on a RedHat OS' do include_examples 'RedHat 6' # Load the more generic tests for this context general_info_specs_apache22 it { is_expected.to contain_file('info.conf').with(ensure: 'file', path: '/etc/httpd/conf.d/info.conf') } end context 'on a FreeBSD OS' do include_examples 'FreeBSD 10' # Load the more generic tests for this context general_info_specs_apache24 it { is_expected.to contain_file('info.conf').with(ensure: 'file', path: '/usr/local/etc/apache24/Modules/info.conf') } end context 'on a Gentoo OS' do include_examples 'Gentoo' # Load the more generic tests for this context general_info_specs_apache24 it { is_expected.to contain_file('info.conf').with(ensure: 'file', path: '/etc/apache2/modules.d/info.conf') } end end diff --git a/spec/classes/mod/mime_magic_spec.rb b/spec/classes/mod/mime_magic_spec.rb index bba4cf4e..369a34e0 100644 --- a/spec/classes/mod/mime_magic_spec.rb +++ b/spec/classes/mod/mime_magic_spec.rb @@ -1,73 +1,73 @@ # frozen_string_literal: true require 'spec_helper' # This function is called inside the OS specific contexts def general_mime_magic_specs it { is_expected.to contain_apache__mod('mime_magic') } end describe 'apache::mod::mime_magic', type: :class do it_behaves_like 'a mod class, without including apache' context 'On a Debian OS with default params' do - include_examples 'Debian 6' + include_examples 'Debian 8' general_mime_magic_specs it do is_expected.to contain_file('mime_magic.conf').with_content( "MIMEMagicFile \"/etc/apache2/magic\"\n", ) end it { is_expected.to contain_file('mime_magic.conf').with(ensure: 'file', path: '/etc/apache2/mods-available/mime_magic.conf') } it { is_expected.to contain_file('mime_magic.conf symlink').with(ensure: 'link', path: '/etc/apache2/mods-enabled/mime_magic.conf') } context 'with magic_file => /tmp/Debian_magic' do let :params do { magic_file: '/tmp/Debian_magic' } end it do is_expected.to contain_file('mime_magic.conf').with_content( "MIMEMagicFile \"/tmp/Debian_magic\"\n", ) end end end context 'on a RedHat OS with default params' do include_examples 'RedHat 6' general_mime_magic_specs it do is_expected.to contain_file('mime_magic.conf').with_content( "MIMEMagicFile \"/etc/httpd/conf/magic\"\n", ) end it { is_expected.to contain_file('mime_magic.conf').with_path('/etc/httpd/conf.d/mime_magic.conf') } end context 'with magic_file => /tmp/magic' do - include_examples 'Debian 6' + include_examples 'Debian 8' let :params do { magic_file: '/tmp/magic' } end it do is_expected.to contain_file('mime_magic.conf').with_content( "MIMEMagicFile \"/tmp/magic\"\n", ) end end end diff --git a/spec/classes/mod/status_spec.rb b/spec/classes/mod/status_spec.rb index 6fb3f690..c4d814bd 100644 --- a/spec/classes/mod/status_spec.rb +++ b/spec/classes/mod/status_spec.rb @@ -1,234 +1,234 @@ # frozen_string_literal: true require 'spec_helper' # Helper function for testing the contents of `status.conf` # Apache < 2.4 shared_examples 'status_conf_spec' do |allow_from, extended_status, status_path| expected = "\n"\ " SetHandler server-status\n"\ " Order deny,allow\n"\ " Deny from all\n"\ " Allow from #{Array(allow_from).join(' ')}\n"\ "\n"\ "ExtendedStatus #{extended_status}\n"\ "\n"\ "\n"\ " # Show Proxy LoadBalancer status in mod_status\n"\ " ProxyStatus On\n"\ "\n" it('status conf') do is_expected.to contain_file('status.conf').with_content(expected) end end # Apache >= 2.4 def require_directives(requires) if requires == :undef " Require ip 127.0.0.1 ::1\n" elsif requires.is_a?(String) if ['', 'unmanaged'].include? requires.downcase '' else " Require #{requires}\n" end elsif requires.is_a?(Array) requires.map { |req| " Require #{req}\n" }.join('') elsif requires.is_a?(Hash) if requires.key?(:enforce) \ " \n" + \ requires[:requires].map { |req| " Require #{req}\n" }.join('') + \ " \n" else requires[:requires].map { |req| " Require #{req}\n" }.join('') end end end shared_examples 'status_conf_spec_require' do |requires, extended_status, status_path| expected = "\n"\ " SetHandler server-status\n"\ "#{require_directives(requires)}"\ "\n"\ "ExtendedStatus #{extended_status}\n"\ "\n"\ "\n"\ " # Show Proxy LoadBalancer status in mod_status\n"\ " ProxyStatus On\n"\ "\n" it('status conf require') do is_expected.to contain_file('status.conf').with_content(expected) end end describe 'apache::mod::status', type: :class do it_behaves_like 'a mod class, without including apache' context 'default configuration with parameters' do - context 'on a Debian 6 OS' do - include_examples 'Debian 6' + context 'on a Debian 8 OS' do + include_examples 'Debian 8' context 'with default params' do it { is_expected.to contain_apache__mod('status') } - include_examples 'status_conf_spec', ['127.0.0.1', '::1'], 'On', '/server-status' + include_examples 'status_conf_spec_require', 'ip 127.0.0.1 ::1', 'On', '/server-status' it { is_expected.to contain_file('status.conf').with(ensure: 'file', path: '/etc/apache2/mods-available/status.conf') } it { is_expected.to contain_file('status.conf symlink').with(ensure: 'link', path: '/etc/apache2/mods-enabled/status.conf') } end context "with custom parameters $allow_from => ['10.10.10.10','11.11.11.11'], $extended_status => 'Off', $status_path => '/custom-status'" do let :params do { allow_from: ['10.10.10.10', '11.11.11.11'], extended_status: 'Off', status_path: '/custom-status', } end it { is_expected.to compile } - include_examples 'status_conf_spec', ['10.10.10.10', '11.11.11.11'], 'Off', '/custom-status' + include_examples 'status_conf_spec_require', 'ip 10.10.10.10 11.11.11.11', 'Off', '/custom-status' end context "with valid parameter type $allow_from => ['10.10.10.10']" do let :params do { allow_from: ['10.10.10.10'] } end it 'expects to succeed array validation' do is_expected.to compile end end context "with invalid parameter type $allow_from => '10.10.10.10'" do let :params do { allow_from: '10.10.10.10' } end it 'expects to fail array validation' do is_expected.to compile.and_raise_error(%r{allow_from}) end end # Only On or Off are valid options ['On', 'Off'].each do |valid_param| context "with valid value $extended_status => '#{valid_param}'" do let :params do { extended_status: valid_param } end it 'expects to succeed regular expression validation' do is_expected.to compile end end end ['Yes', 'No'].each do |invalid_param| context "with invalid value $extended_status => '#{invalid_param}'" do let :params do { extended_status: invalid_param } end it 'expects to fail regular expression validation' do is_expected.to compile.and_raise_error(%r{extended_status}) end end end end context 'on a RedHat 6 OS' do include_examples 'RedHat 6' context 'with default params' do it { is_expected.to contain_apache__mod('status') } include_examples 'status_conf_spec', ['127.0.0.1', '::1'], 'On', '/server-status' it { is_expected.to contain_file('status.conf').with_path('/etc/httpd/conf.d/status.conf') } end end valid_requires = { undef: :undef, empty: '', unmanaged: 'unmanaged', string: 'ip 127.0.0.1 192.168', array: [ 'ip 127.0.0.1', 'ip ::1', 'host localhost', ], hash: { requires: [ 'ip 10.1', 'host somehost', ], }, enforce: { enforce: 'all', requires: [ 'ip 127.0.0.1', 'host localhost', ], }, } valid_requires.each do |req_key, req_value| context "with default params and #{req_key} requires" do let :params do { requires: req_value, } end context 'on a Debian 8 OS' do include_examples 'Debian 8' it { is_expected.to contain_apache__mod('status') } include_examples 'status_conf_spec_require', req_value, 'On', '/server-status' it { is_expected.to contain_file('status.conf').with(ensure: 'file', path: '/etc/apache2/mods-available/status.conf') } it { is_expected.to contain_file('status.conf symlink').with(ensure: 'link', path: '/etc/apache2/mods-enabled/status.conf') } end context 'on a RedHat 7 OS' do include_examples 'RedHat 7' it { is_expected.to contain_apache__mod('status') } include_examples 'status_conf_spec_require', req_value, 'On', '/server-status' it { is_expected.to contain_file('status.conf').with_path('/etc/httpd/conf.modules.d/status.conf') } end context 'on a RedHat 8 OS' do include_examples 'RedHat 8' it { is_expected.to contain_apache__mod('status') } include_examples 'status_conf_spec_require', req_value, 'On', '/server-status' it { is_expected.to contain_file('status.conf').with_path('/etc/httpd/conf.modules.d/status.conf') } end end end end end diff --git a/spec/spec_helper_local.rb b/spec/spec_helper_local.rb index fa79367c..79e18630 100644 --- a/spec/spec_helper_local.rb +++ b/spec/spec_helper_local.rb @@ -1,211 +1,198 @@ # frozen_string_literal: true if ENV['COVERAGE'] == 'yes' require 'simplecov' require 'simplecov-console' require 'codecov' SimpleCov.formatters = [ SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::Console, SimpleCov::Formatter::Codecov, ] SimpleCov.start do track_files 'lib/**/*.rb' add_filter '/spec' # do not track vendored files add_filter '/vendor' add_filter '/.vendor' # do not track gitignored files # this adds about 4 seconds to the coverage check # this could definitely be optimized add_filter do |f| # system returns true if exit status is 0, which with git-check-ignore means file is ignored system("git check-ignore --quiet #{f.filename}") end end end shared_examples :compile, compile: true do it { is_expected.to compile.with_all_deps } end shared_context 'a mod class, without including apache' do let(:facts) { on_supported_os['debian-8-x86_64'] } end -shared_context 'Debian 6' do - let :facts do - { - id: 'root', - kernel: 'Linux', - osfamily: 'Debian', - operatingsystem: 'Debian', - operatingsystemrelease: '6', - path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', - } - end -end - shared_context 'Debian 8' do let(:facts) { on_supported_os['debian-8-x86_64'] } end shared_context 'Ubuntu 14.04' do let :facts do { id: 'root', kernel: 'Linux', osfamily: 'Debian', operatingsystem: 'Ubuntu', operatingsystemrelease: '14.04', lsbdistrelease: '14.04', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end end shared_context 'RedHat 5' do let :facts do { id: 'root', kernel: 'Linux', osfamily: 'RedHat', operatingsystem: 'RedHat', operatingsystemrelease: '5', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end end shared_context 'RedHat 6' do let(:facts) { on_supported_os['redhat-6-x86_64'] } end shared_context 'RedHat 7' do let(:facts) { on_supported_os['redhat-7-x86_64'] } end shared_context 'RedHat 8' do let(:facts) { on_supported_os['redhat-8-x86_64'] } end shared_context 'Fedora 17' do let :facts do { id: 'root', kernel: 'Linux', osfamily: 'RedHat', operatingsystem: 'Fedora', operatingsystemrelease: '17', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end end shared_context 'Fedora 21' do let :facts do { id: 'root', kernel: 'Linux', osfamily: 'RedHat', operatingsystem: 'Fedora', operatingsystemrelease: '21', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end end shared_context 'Fedora 28' do let :facts do { id: 'root', kernel: 'Linux', osfamily: 'RedHat', operatingsystem: 'Fedora', operatingsystemrelease: '28', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end end shared_context 'Fedora Rawhide' do let :facts do { id: 'root', kernel: 'Linux', osfamily: 'RedHat', operatingsystem: 'Fedora', operatingsystemrelease: 'Rawhide', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end end shared_context 'FreeBSD 9' do let :facts do { osfamily: 'FreeBSD', operatingsystemrelease: '9', operatingsystem: 'FreeBSD', id: 'root', kernel: 'FreeBSD', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end end shared_context 'FreeBSD 10' do let :facts do { id: 'root', kernel: 'FreeBSD', osfamily: 'FreeBSD', operatingsystem: 'FreeBSD', operatingsystemrelease: '10', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end end shared_context 'Gentoo' do let :facts do { id: 'root', kernel: 'Linux', osfamily: 'Gentoo', operatingsystem: 'Gentoo', operatingsystemrelease: '3.16.1-gentoo', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin', } end end shared_context 'Darwin' do let :facts do { osfamily: 'Darwin', operatingsystemrelease: '13.1.0', } end end shared_context 'Unsupported OS' do let :facts do { osfamily: 'Magic', operatingsystemrelease: '0', operatingsystem: 'Magic', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end end shared_context 'SLES 12' do let(:facts) { on_supported_os['sles-12-x86_64'] } end