diff --git a/spec/classes/apache_spec.rb b/spec/classes/apache_spec.rb index 11865838..ba858ae0 100644 --- a/spec/classes/apache_spec.rb +++ b/spec/classes/apache_spec.rb @@ -1,928 +1,911 @@ # frozen_string_literal: true require 'spec_helper' describe 'apache', type: :class do context 'on a Debian OS' do let :facts do { id: 'root', kernel: 'Linux', lsbdistcodename: 'squeeze', osfamily: 'Debian', operatingsystem: 'Debian', operatingsystemrelease: '6', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end 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( 'ensure' => 'directory', ) } it { is_expected.to contain_file('/etc/apache2/sites-enabled').with( 'ensure' => 'directory', 'recurse' => 'true', - 'purge' => 'true', 'notify' => 'Class[Apache::Service]', - 'require' => 'Package[httpd]' - ) + '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', 'notify' => 'Class[Apache::Service]', - 'require' => 'Package[httpd]' - ) + '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', 'notify' => 'Class[Apache::Service]', - 'require' => 'Package[httpd]' - ) + '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', 'notify' => 'Class[Apache::Service]' - ) + '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| 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 let :facts do super().merge(lsbdistcodename: 'jessie', operatingsystemrelease: '8.0.0') end 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') } end end context 'on Ubuntu 14.04' do let :facts do super().merge(operatingsystem: 'Ubuntu', lsbdistrelease: '14.04', operatingsystemrelease: '14.04') end it { is_expected.to contain_file('/var/www/html').with( 'ensure' => 'directory', ) } end end context 'on a RedHat 5 OS' 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', is_pe: false, } end 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', 'notify' => 'Class[Apache::Service]', - 'require' => 'Package[httpd]' - ) + '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', 'notify' => 'Class[Apache::Service]' - ) + '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', 'notify' => 'Class[Apache::Service]', - 'require' => 'Package[httpd]' - ) + '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', - 'notify' => 'Class[Apache::Service]', - 'require' => ['Package[httpd]', 'Concat[/etc/httpd/conf/ports.conf]'], - ) + ).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', 'notify' => 'Class[Apache::Service]', - 'require' => 'Package[httpd]' - ) + '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 let :facts do super().merge(operatingsystem: 'Fedora', lsbdistrelease: '21', operatingsystemrelease: '21') end it { is_expected.to contain_class('apache').with_apache_version('2.4') } end context 'on Fedora Rawhide' do let :facts do super().merge(operatingsystem: 'Fedora', lsbdistrelease: 'Rawhide', operatingsystemrelease: 'Rawhide') end it { is_expected.to contain_class('apache').with_apache_version('2.4') } end # kinda obsolete context 'on Fedora 17' do let :facts do super().merge(operatingsystem: 'Fedora', lsbdistrelease: '17', operatingsystemrelease: '17') end it { is_expected.to contain_class('apache').with_apache_version('2.2') } end end context 'on a FreeBSD OS' 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', is_pe: false, } end 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', 'notify' => 'Class[Apache::Service]', - 'require' => 'Package[httpd]' - ) + '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', 'notify' => 'Class[Apache::Service]', - 'require' => 'Package[httpd]' - ) + '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', 'notify' => 'Class[Apache::Service]' - ) + '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 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', is_pe: false, } end 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', 'notify' => 'Class[Apache::Service]', - 'require' => 'Package[httpd]' - ) + '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', 'notify' => 'Class[Apache::Service]', - 'require' => 'Package[httpd]' - ) + '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', 'notify' => 'Class[Apache::Service]' - ) + 'mode' => '0644', + ).that_notifies('Class[Apache::Service]') } end context 'on all OSes' do let :facts do { id: 'root', kernel: 'Linux', osfamily: 'RedHat', operatingsystem: 'RedHat', operatingsystemrelease: '6', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end context 'with a custom apache_name parameter' do let :params do { apache_name: 'httpd24-httpd', } end it { is_expected.to contain_package('httpd').with( - 'notify' => 'Class[Apache::Service]', '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 let :facts do { osfamily: 'Darwin', operatingsystemrelease: '13.1.0', is_pe: false } end - it do - expect { - catalogue - }.to raise_error(Puppet::Error, %r{Unsupported osfamily}) - end + it { is_expected.to compile.and_raise_error(%r{Unsupported osfamily}) } end end diff --git a/spec/classes/mod/authnz_ldap_spec.rb b/spec/classes/mod/authnz_ldap_spec.rb index 307b16d7..e6ecc50f 100644 --- a/spec/classes/mod/authnz_ldap_spec.rb +++ b/spec/classes/mod/authnz_ldap_spec.rb @@ -1,95 +1,95 @@ # frozen_string_literal: true require 'spec_helper' describe 'apache::mod::authnz_ldap', type: :class do it_behaves_like 'a mod class, without including apache' context 'default configuration with parameters on a Debian OS' do let :facts do { lsbdistcodename: 'jessie', osfamily: 'Debian', operatingsystemrelease: '8', id: 'root', kernel: 'Linux', operatingsystem: 'Debian', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_class('apache::mod::ldap') } it { is_expected.to contain_apache__mod('authnz_ldap') } context 'default verify_server_cert' do it { is_expected.to contain_file('authnz_ldap.conf').with_content(%r{^LDAPVerifyServerCert On$}) } end context 'verify_server_cert = false' do let(:params) { { verify_server_cert: false } } it { is_expected.to contain_file('authnz_ldap.conf').with_content(%r{^LDAPVerifyServerCert Off$}) } end context 'verify_server_cert = wrong' do let(:params) { { verify_server_cert: 'wrong' } } it 'raises an error' do - expect { is_expected.to raise_error Puppet::Error } + is_expected.to compile.and_raise_error(%r{parameter 'verify_server_cert' expects a Boolean value, got String}) end end end # Debian context 'default configuration with parameters on a RedHat OS' do on_supported_os.each do |os, os_facts| next unless os.start_with?('redhat') context "On #{os}" do let :facts do os_facts end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_class('apache::mod::ldap') } it { is_expected.to contain_apache__mod('authnz_ldap') } if os_facts[:operatingsystemmajrelease].to_i >= 7 it { is_expected.to contain_package('mod_ldap') } else it { is_expected.to contain_package('mod_authz_ldap') } end context 'default verify_server_cert' do it { is_expected.to contain_file('authnz_ldap.conf').with_content(%r{^LDAPVerifyServerCert On$}) } end context 'verify_server_cert = false' do let(:params) { { verify_server_cert: false } } it { is_expected.to contain_file('authnz_ldap.conf').with_content(%r{^LDAPVerifyServerCert Off$}) } end context 'verify_server_cert = wrong' do let(:params) { { verify_server_cert: 'wrong' } } it 'raises an error' do - expect { is_expected.to raise_error Puppet::Error } + is_expected.to compile.and_raise_error(%r{parameter 'verify_server_cert' expects a Boolean value, got String}) end end context 'SCL', if: (os_facts[:operatingsystemmajrelease].to_i >= 6 && os_facts[:operatingsystemmajrelease].to_i < 8) do let(:pre_condition) do "class { 'apache::version': scl_httpd_version => '2.4', scl_php_version => '7.0', } include apache" end it { is_expected.to contain_package('httpd24-mod_ldap') } end end end end # Redhat end diff --git a/spec/classes/mod/data_spec.rb b/spec/classes/mod/data_spec.rb index 226918d7..4511996f 100644 --- a/spec/classes/mod/data_spec.rb +++ b/spec/classes/mod/data_spec.rb @@ -1,34 +1,32 @@ # frozen_string_literal: true require 'spec_helper' describe 'apache::mod::data', type: :class do context 'on a Debian OS' do let :facts do { osfamily: 'Debian', operatingsystemrelease: '8', lsbdistcodename: 'jessie', operatingsystem: 'Debian', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let :params do { apache_version: '2.4' } end it { is_expected.to contain_apache__mod('data') } describe 'with Apache version < 2.3' do let :params do { apache_version: '2.2' } end - it 'fails' do - expect { catalogue }.to raise_error(Puppet::Error, %r{mod_data is only available in Apache 2.3 and later}) - end + it { is_expected.to compile.and_raise_error(%r{mod_data is only available in Apache 2.3 and later}) } end end end diff --git a/spec/classes/mod/peruser_spec.rb b/spec/classes/mod/peruser_spec.rb index d5f2a93a..2533a28b 100644 --- a/spec/classes/mod/peruser_spec.rb +++ b/spec/classes/mod/peruser_spec.rb @@ -1,46 +1,42 @@ # frozen_string_literal: true require 'spec_helper' describe 'apache::mod::peruser', type: :class do let :pre_condition do 'class { "apache": mpm_module => false, }' end context 'on a FreeBSD OS' do let :facts do { osfamily: 'FreeBSD', operatingsystemrelease: '10', operatingsystem: 'FreeBSD', id: 'root', kernel: 'FreeBSD', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end - it do - expect { - catalogue - }.to raise_error(Puppet::Error, %r{Unsupported osfamily FreeBSD}) - end + it { is_expected.to compile.and_raise_error(%r{Unsupported osfamily FreeBSD}) } end context 'on a Gentoo OS' do let :facts do { osfamily: 'Gentoo', operatingsystem: 'Gentoo', operatingsystemrelease: '3.16.1-gentoo', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin', is_pe: false, } end it { is_expected.to contain_class('apache::params') } it { is_expected.not_to contain_apache__mod('peruser') } it { is_expected.to contain_file('/etc/apache2/modules.d/peruser.conf').with_ensure('file') } end end diff --git a/spec/classes/mod/php_spec.rb b/spec/classes/mod/php_spec.rb index a7d6fe88..05a6de02 100644 --- a/spec/classes/mod/php_spec.rb +++ b/spec/classes/mod/php_spec.rb @@ -1,301 +1,301 @@ # frozen_string_literal: true require 'spec_helper' describe 'apache::mod::php', type: :class do on_supported_os.each do |os, facts| context "on #{os} " do let :facts do facts end let :pre_condition do 'class { "apache": mpm_module => prefork, }' end case facts[:os]['family'] when 'Debian' describe 'on a Debian OS' do context 'with mpm_module => prefork' do it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_class('apache::mod::prefork') } end case facts[:os]['release']['major'] when '8' context 'on jessie' do it { is_expected.to contain_file('php5.load').with( content: "LoadModule php5_module /usr/lib/apache2/modules/libphp5.so\n", ) } context 'with mpm_module => itk on jessie' do let :pre_condition do 'class { "apache": mpm_module => itk, }' end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_class('apache::mod::itk') } it { is_expected.to contain_apache__mod('php5') } it { is_expected.to contain_package('libapache2-mod-php5') } it { is_expected.to contain_file('php5.load').with( content: "LoadModule php5_module /usr/lib/apache2/modules/libphp5.so\n", ) } end end when '9' context 'on stretch' do it { is_expected.to contain_apache__mod('php7.0') } it { is_expected.to contain_package('libapache2-mod-php7.0') } it { is_expected.to contain_file('php7.0.load').with( content: "LoadModule php7_module /usr/lib/apache2/modules/libphp7.0.so\n", ) } end when '16.04' context 'on stretch' do let :params do { content: 'somecontent' } end it { is_expected.to contain_file('php7.0.conf').with( content: 'somecontent', ) } end when '18.04' context 'on stretch' do let :params do { content: 'somecontent' } end it { is_expected.to contain_file('php7.2.conf').with( content: 'somecontent', ) } end end end when 'RedHat' describe 'on a RedHat OS' do context 'with default params' do let :pre_condition do 'class { "apache": }' end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('php5') } if facts[:os]['release']['major'].to_i < 8 it { is_expected.to contain_package('php') } if facts[:os]['release']['major'].to_i > 5 it { is_expected.to contain_file('php5.load').with(content: "LoadModule php5_module modules/libphp5.so\n") } if facts[:os]['release']['major'].to_i < 8 it { is_expected.to contain_file('php7.load').with(content: "LoadModule php7_module modules/libphp7.so\n") } if facts[:os]['release']['major'].to_i >= 8 end context 'with alternative package name' do let :pre_condition do 'class { "apache": }' end let :params do { package_name: 'php54' } end it { is_expected.to contain_package('php54') } end context 'with alternative path' do let :pre_condition do 'class { "apache": }' end let :params do { path: 'alternative-path' } end it { is_expected.to contain_file('php5.load').with(content: "LoadModule php5_module alternative-path\n") } if facts[:os]['release']['major'].to_i < 8 it { is_expected.to contain_file('php7.load').with(content: "LoadModule php7_module alternative-path\n") } if facts[:os]['release']['major'].to_i >= 8 end context 'with alternative extensions' do let :pre_condition do 'class { "apache": }' end let :params do { extensions: ['.php', '.php5'], } end it { is_expected.to contain_file('php5.conf').with_content(Regexp.new(Regexp.escape(''))) } if facts[:os]['release']['major'].to_i < 8 end if facts[:os]['release']['major'].to_i > 5 context 'with specific version' do let :pre_condition do 'class { "apache": }' end let :params do { package_ensure: '5.3.13' } end it { is_expected.to contain_package('php').with( ensure: '5.3.13', ) } end end context 'with mpm_module => prefork' do it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_class('apache::mod::prefork') } it { is_expected.to contain_apache__mod('php5') } if facts[:os]['release']['major'].to_i < 8 it { is_expected.to contain_package('php') } if facts[:os]['release']['major'].to_i > 5 it { is_expected.to contain_file('php5.load').with(content: "LoadModule php5_module modules/libphp5.so\n") } if facts[:os]['release']['major'].to_i < 8 it { is_expected.to contain_file('php7.load').with(content: "LoadModule php7_module modules/libphp7.so\n") } if facts[:os]['release']['major'].to_i >= 8 end context 'with mpm_module => itk' do let :pre_condition do 'class { "apache": mpm_module => itk, }' end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_class('apache::mod::itk') } it { is_expected.to contain_apache__mod('php5') } if facts[:os]['release']['major'].to_i < 8 it { is_expected.to contain_package('php') } if facts[:os]['release']['major'].to_i > 5 it { is_expected.to contain_file('php5.load').with(content: "LoadModule php5_module modules/libphp5.so\n") } if facts[:os]['release']['major'].to_i < 8 it { is_expected.to contain_file('php7.load').with(content: "LoadModule php7_module modules/libphp7.so\n") } if facts[:os]['release']['major'].to_i >= 8 end end when 'FreeBSD' describe 'on a FreeBSD OS' do context 'with mpm_module => prefork' do it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('php5') } it { is_expected.to contain_package('www/mod_php5') } it { is_expected.to contain_file('php5.load') } end context 'with mpm_module => itk' do let :pre_condition do 'class { "apache": mpm_module => itk, }' end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_class('apache::mod::itk') } it { is_expected.to contain_apache__mod('php5') } it { is_expected.to contain_package('www/mod_php5') } it { is_expected.to contain_file('php5.load') } end end when 'Gentoo' describe 'on a Gentoo OS' do context 'with mpm_module => prefork' do it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('php5') } it { is_expected.to contain_package('dev-lang/php') } it { is_expected.to contain_file('php5.load') } end context 'with mpm_module => itk' do let :pre_condition do 'class { "apache": mpm_module => itk, }' end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_class('apache::mod::itk') } it { is_expected.to contain_apache__mod('php5') } it { is_expected.to contain_package('dev-lang/php') } it { is_expected.to contain_file('php5.load') } end end end # all the following tests are for legacy php/apache versions. They don't work on modern ubuntu and redhat 8 next if (facts[:os]['release']['major'].to_i > 15 && facts[:os]['name'] == 'Ubuntu') || (facts[:os]['release']['major'].to_i >= 9 && facts[:os]['name'] == 'Debian') || (facts[:os]['release']['major'].to_i >= 8 && (facts[:os]['name'] == 'RedHat' || facts[:os]['name'] == 'CentOS')) describe 'OS independent tests' do context 'with content param' do let :params do { content: 'somecontent' } end it { is_expected.to contain_file('php5.conf').with( content: 'somecontent', ) } end context 'with template param' do let :params do { template: 'apache/mod/php.conf.erb' } end it { is_expected.to contain_file('php5.conf').with( content: %r{^# PHP is an HTML-embedded scripting language which attempts to make it}, ) } end context 'with source param' do let :params do { source: 'some-path' } end it { is_expected.to contain_file('php5.conf').with( source: 'some-path', ) } end context 'content has priority over template' do let :params do { template: 'apache/mod/php5.conf.erb', content: 'somecontent', } end it { is_expected.to contain_file('php5.conf').with( content: 'somecontent', ) } end context 'source has priority over template' do let :params do { template: 'apache/mod/php5.conf.erb', source: 'some-path', } end it { is_expected.to contain_file('php5.conf').with( source: 'some-path', ) } end context 'source has priority over content' do let :params do { content: 'somecontent', source: 'some-path', } end it { is_expected.to contain_file('php5.conf').with( source: 'some-path', ) } end context 'with mpm_module => worker' do let :pre_condition do 'class { "apache": mpm_module => worker, }' end it 'raises an error' do - expect { expect(subject).to contain_apache__mod('php5') }.to raise_error Puppet::Error, %r{mpm_module => 'prefork' or mpm_module => 'itk'} + is_expected.to compile.and_raise_error(%r{mpm_module => 'prefork' or mpm_module => 'itk'}) end end end end end end diff --git a/spec/classes/mod/remoteip_spec.rb b/spec/classes/mod/remoteip_spec.rb index d9cc055e..3de472cb 100644 --- a/spec/classes/mod/remoteip_spec.rb +++ b/spec/classes/mod/remoteip_spec.rb @@ -1,125 +1,125 @@ # frozen_string_literal: true require 'spec_helper' describe 'apache::mod::remoteip', type: :class do context 'on a Debian OS' do let :facts do { osfamily: 'Debian', operatingsystemrelease: '8', lsbdistcodename: 'jessie', operatingsystem: 'Debian', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let :params do { apache_version: '2.4' } end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('remoteip') } it { is_expected.to contain_file('remoteip.conf').with('path' => '/etc/apache2/mods-available/remoteip.conf') } describe 'with header X-Forwarded-For' do let :params do { header: 'X-Forwarded-For' } end it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPHeader X-Forwarded-For$}) } end describe 'with internal_proxy => [ 10.42.17.8, 10.42.18.99 ]' do let :params do { internal_proxy: ['10.42.17.8', '10.42.18.99'] } end it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPInternalProxy 10.42.17.8$}) } it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPInternalProxy 10.42.18.99$}) } end describe 'with IPv4 CIDR in internal_proxy => [ 192.168.1.0/24 ]' do let :params do { internal_proxy: ['192.168.1.0/24'] } end it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPInternalProxy 192.168.1.0/24$}) } end describe 'with IPv6 CIDR in internal_proxy => [ fd00:fd00:fd00:2000::/64 ]' do let :params do { internal_proxy: ['fd00:fd00:fd00:2000::/64'] } end it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPInternalProxy fd00:fd00:fd00:2000::/64$}) } end describe 'with proxy_ips => [ 10.42.17.8, 10.42.18.99 ]' do let :params do { proxy_ips: ['10.42.17.8', '10.42.18.99'] } end it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPInternalProxy 10.42.17.8$}) } it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPInternalProxy 10.42.18.99$}) } end describe 'with IPv4 CIDR in proxy_ips => [ 192.168.1.0/24 ]' do let :params do { proxy_ips: ['192.168.1.0/24'] } end it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPInternalProxy 192.168.1.0/24$}) } end describe 'with IPv6 CIDR in proxy_ips => [ fd00:fd00:fd00:2000::/64 ]' do let :params do { proxy_ips: ['fd00:fd00:fd00:2000::/64'] } end it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPInternalProxy fd00:fd00:fd00:2000::/64$}) } end describe 'with trusted_proxy => [ 10.42.17.8, 10.42.18.99 ]' do let :params do { trusted_proxy: ['10.42.17.8', '10.42.18.99'] } end it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPTrustedProxy 10.42.17.8$}) } it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPTrustedProxy 10.42.18.99$}) } end describe 'with trusted_proxy_ips => [ 10.42.17.8, 10.42.18.99 ]' do let :params do { trusted_proxy: ['10.42.17.8', '10.42.18.99'] } end it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPTrustedProxy 10.42.17.8$}) } it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPTrustedProxy 10.42.18.99$}) } end describe 'with proxy_protocol_exceptions => [ 10.42.17.8, 10.42.18.99 ]' do let :params do { proxy_protocol_exceptions: ['10.42.17.8', '10.42.18.99'] } end it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPProxyProtocolExceptions 10.42.17.8$}) } it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPProxyProtocolExceptions 10.42.18.99$}) } end describe 'with IPv4 CIDR in proxy_protocol_exceptions => [ 192.168.1.0/24 ]' do let :params do { proxy_protocol_exceptions: ['192.168.1.0/24'] } end it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPProxyProtocolExceptions 192.168.1.0/24$}) } end describe 'with IPv6 CIDR in proxy_protocol_exceptions => [ fd00:fd00:fd00:2000::/64 ]' do let :params do { proxy_protocol_exceptions: ['fd00:fd00:fd00:2000::/64'] } end it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPProxyProtocolExceptions fd00:fd00:fd00:2000::/64$}) } end describe 'with Apache version < 2.4' do let :params do { apache_version: '2.2' } end - it { expect { catalogue }.to raise_error(Puppet::Error, %r{mod_remoteip is only available in Apache 2.4}) } + it { is_expected.to compile.and_raise_error(%r{mod_remoteip is only available in Apache 2.4}) } end end end diff --git a/spec/classes/mod/ssl_spec.rb b/spec/classes/mod/ssl_spec.rb index 48f4683f..36972364 100644 --- a/spec/classes/mod/ssl_spec.rb +++ b/spec/classes/mod/ssl_spec.rb @@ -1,390 +1,390 @@ # frozen_string_literal: true require 'spec_helper' describe 'apache::mod::ssl', type: :class do it_behaves_like 'a mod class, without including apache' context 'on an 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', is_pe: false, } end - it { expect { catalogue }.to raise_error(Puppet::Error, %r{Unsupported osfamily:}) } + it { is_expected.to compile.and_raise_error(%r{Unsupported osfamily:}) } end context 'on a RedHat' do context '6 OS' do let :facts do { osfamily: 'RedHat', operatingsystemrelease: '6', operatingsystem: 'RedHat', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('ssl') } it { is_expected.to contain_package('mod_ssl') } it { is_expected.to contain_file('ssl.conf').with_path('/etc/httpd/conf.d/ssl.conf') } it { is_expected.to contain_file('ssl.conf').with_content(%r{SSLProtocol all -SSLv2 -SSLv3}) } end context '8 OS' do let :facts do { osfamily: 'RedHat', operatingsystemrelease: '8', operatingsystem: 'RedHat', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('ssl') } it { is_expected.to contain_package('mod_ssl') } it { is_expected.to contain_file('ssl.conf').with_path('/etc/httpd/conf.modules.d/ssl.conf') } it { is_expected.to contain_file('ssl.conf').with_content(%r{SSLProtocol all}) } end context '6 OS with a custom package_name parameter' do let :facts do { osfamily: 'RedHat', operatingsystemrelease: '6', operatingsystem: 'RedHat', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end let :params do { package_name: 'httpd24-mod_ssl' } end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('ssl') } it { is_expected.to contain_package('httpd24-mod_ssl') } it { is_expected.not_to contain_package('mod_ssl') } it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLSessionCache "shmcb:/var/cache/mod_ssl/scache\(512000\)"$}) } end context '7 OS with custom directories for PR#1635' do let :facts do { osfamily: 'RedHat', operatingsystemrelease: '7', operatingsystem: 'RedHat', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end let :pre_condition do "class { 'apache': confd_dir => '/etc/httpd/conf.puppet.d', default_mods => false, default_vhost => false, mod_dir => '/etc/httpd/conf.modules.puppet.d', vhost_dir => '/etc/httpd/conf.puppet.d', }" end it { is_expected.to contain_package('mod_ssl') } it { is_expected.to contain_file('ssl.conf').with_path('/etc/httpd/conf.puppet.d/ssl.conf') } end end context 'on a Debian OS' do let :facts do { osfamily: 'Debian', operatingsystemrelease: '8', lsbdistcodename: 'jessie', operatingsystem: 'Debian', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('ssl') } it { is_expected.not_to contain_package('libapache2-mod-ssl') } it { is_expected.to contain_file('ssl.conf').with_content(%r{SSLProtocol all -SSLv2 -SSLv3}) } end context 'on a FreeBSD OS' 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', is_pe: false, } end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('ssl') } end context 'on a Gentoo OS' do let :facts do { osfamily: 'Gentoo', operatingsystem: 'Gentoo', operatingsystemrelease: '3.16.1-gentoo', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin', is_pe: false, } end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('ssl') } it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLSessionCache "shmcb:/var/run/ssl_scache\(512000\)"$}) } end context 'on a Suse OS' do let :facts do { osfamily: 'Suse', operatingsystem: 'SLES', operatingsystemrelease: '12', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin', is_pe: false, } end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('ssl') } it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLSessionCache "shmcb:/var/lib/apache2/ssl_scache\(512000\)"$}) } end # Template config doesn't vary by distro context 'on all distros' do let :facts do { osfamily: 'RedHat', operatingsystem: 'CentOS', operatingsystemrelease: '6', kernel: 'Linux', id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end context 'not setting ssl_pass_phrase_dialog' do it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLPassPhraseDialog builtin$}) } end context 'setting ssl_cert' do let :params do { ssl_cert: '/etc/pki/some/path/localhost.crt', } end it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLCertificateFile}) } end context 'setting ssl_key' do let :params do { ssl_key: '/etc/pki/some/path/localhost.key', } end it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLCertificateKeyFile}) } end context 'setting ssl_ca to a path' do let :params do { ssl_ca: '/etc/pki/some/path/ca.crt', } end it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLCACertificateFile}) } end context 'with Apache version < 2.4 - ssl_compression with default value' do let :params do { apache_version: '2.2', } end it { is_expected.not_to contain_file('ssl.conf').with_content(%r{^ SSLCompression Off$}) } end context 'with Apache version < 2.4 - setting ssl_compression to true' do let :params do { apache_version: '2.2', ssl_compression: true, } end it { is_expected.not_to contain_file('ssl.conf').with_content(%r{^ SSLCompression On$}) } end context 'with Apache version < 2.4 - setting ssl_stapling to true' do let :params do { apache_version: '2.2', ssl_stapling: true, } end it { is_expected.not_to contain_file('ssl.conf').with_content(%r{^ SSLUseStapling}) } end context 'with Apache version >= 2.4 - ssl_compression with default value' do let :params do { apache_version: '2.4', } end it { is_expected.not_to contain_file('ssl.conf').with_content(%r{^ SSLCompression Off$}) } end context 'with Apache version >= 2.4' do let :params do { apache_version: '2.4', ssl_compression: true, } end it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLCompression On$}) } end context 'with Apache version >= 2.4 - ssl_sessiontickets with default value' do let :params do { apache_version: '2.4', } end it { is_expected.not_to contain_file('ssl.conf').with_content(%r{^ SSLSessionTickets (Off|On)$}) } end context 'with Apache version >= 2.4 - setting ssl_sessiontickets to false' do let :params do { apache_version: '2.4', ssl_sessiontickets: false, } end it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLSessionTickets Off$}) } end context 'with Apache version >= 2.4 - setting ssl_stapling to true' do let :params do { apache_version: '2.4', ssl_stapling: true, } end it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLUseStapling On$}) } end context 'with Apache version >= 2.4 - setting ssl_stapling_return_errors to true' do let :params do { apache_version: '2.4', ssl_stapling_return_errors: true, } end it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLStaplingReturnResponderErrors On$}) } end context 'with Apache version >= 2.4 - setting stapling_cache' do let :params do { apache_version: '2.4', stapling_cache: '/tmp/customstaplingcache(51200)', } end it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLStaplingCache "shmcb:/tmp/customstaplingcache\(51200\)"$}) } end context 'setting ssl_pass_phrase_dialog' do let :params do { ssl_pass_phrase_dialog: 'exec:/path/to/program', } end it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLPassPhraseDialog exec:\/path\/to\/program$}) } end context 'setting ssl_random_seed_bytes' do let :params do { ssl_random_seed_bytes: '1024', } end it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLRandomSeed startup file:/dev/urandom 1024$}) } end context 'setting ssl_openssl_conf_cmd' do let :params do { ssl_openssl_conf_cmd: 'DHParameters "foo.pem"', } end it { is_expected.to contain_file('ssl.conf').with_content(%r{^\s+SSLOpenSSLConfCmd DHParameters "foo.pem"$}) } end context 'setting ssl_mutex' do let :params do { ssl_mutex: 'posixsem', } end it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLMutex posixsem$}) } end context 'setting ssl_sessioncache' do let :params do { ssl_sessioncache: '/tmp/customsessioncache(51200)', } end it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLSessionCache "shmcb:/tmp/customsessioncache\(51200\)"$}) } end context 'setting ssl_proxy_protocol' do let :params do { ssl_proxy_protocol: ['-ALL', '+TLSv1'], } end it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLProxyProtocol -ALL \+TLSv1$}) } end end end diff --git a/spec/classes/mod/status_spec.rb b/spec/classes/mod/status_spec.rb index f4741a99..11fb4599 100644 --- a/spec/classes/mod/status_spec.rb +++ b/spec/classes/mod/status_spec.rb @@ -1,358 +1,350 @@ # frozen_string_literal: true require 'spec_helper' # Helper function for testing the contents of `status.conf` # Apache < 2.4 def status_conf_spec(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 def status_conf_spec_require(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 with default params' do let :facts do { osfamily: 'Debian', operatingsystemrelease: '6', lsbdistcodename: 'squeeze', operatingsystem: 'Debian', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end it { is_expected.to contain_apache__mod('status') } status_conf_spec(['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 'on a RedHat 6 OS with default params' do let :facts do { osfamily: 'RedHat', operatingsystemrelease: '6', operatingsystem: 'RedHat', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end it { is_expected.to contain_apache__mod('status') } 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 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 "on a Debian 8 OS with default params and #{req_key} requires" do let :facts do { osfamily: 'Debian', operatingsystemrelease: '8', lsbdistcodename: 'squeeze', operatingsystem: 'Debian', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end let :params do { requires: req_value, } end it { is_expected.to contain_apache__mod('status') } 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 with default params and #{req_key} requires" do let :facts do { osfamily: 'RedHat', operatingsystemrelease: '7', operatingsystem: 'RedHat', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end let :params do { requires: req_value, } end it { is_expected.to contain_apache__mod('status') } 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 with default params and #{req_key} requires" do let :facts do { osfamily: 'RedHat', operatingsystemrelease: '8', operatingsystem: 'RedHat', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end let :params do { requires: req_value, } end it { is_expected.to contain_apache__mod('status') } 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 context "with custom parameters $allow_from => ['10.10.10.10','11.11.11.11'], $extended_status => 'Off', $status_path => '/custom-status'" do let :facts do { osfamily: 'Debian', operatingsystemrelease: '6', lsbdistcodename: 'squeeze', operatingsystem: 'Debian', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end 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 } status_conf_spec(['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 :facts do { osfamily: 'Debian', operatingsystemrelease: '6', lsbdistcodename: 'squeeze', operatingsystem: 'Debian', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end let :params do { allow_from: ['10.10.10.10'] } end it 'expects to succeed array validation' do - expect { - is_expected.to contain_file('status.conf') - }.not_to raise_error + is_expected.to compile end end context "with invalid parameter type $allow_from => '10.10.10.10'" do let :facts do { osfamily: 'Debian', operatingsystemrelease: '6', operatingsystem: 'Debian', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end let :params do { allow_from: '10.10.10.10' } end it 'expects to fail array validation' do - expect { - is_expected.to contain_file('status.conf') - }.to raise_error(Puppet::Error) + is_expected.to compile.and_raise_error(/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 :facts do { osfamily: 'Debian', operatingsystemrelease: '6', lsbdistcodename: 'squeeze', operatingsystem: 'Debian', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end let :params do { extended_status: valid_param } end it 'expects to succeed regular expression validation' do - expect { - is_expected.to contain_file('status.conf') - }.not_to raise_error + is_expected.to compile end end end ['Yes', 'No'].each do |invalid_param| context "with invalid value $extended_status => '#{invalid_param}'" do let :facts do { osfamily: 'Debian', operatingsystemrelease: '6', operatingsystem: 'Debian', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end let :params do { extended_status: invalid_param } end it 'expects to fail regular expression validation' do - expect { - is_expected.to contain_file('status.conf') - }.to raise_error(Puppet::Error) + is_expected.to compile.and_raise_error(/extended_status/) end end end end end diff --git a/spec/classes/mod/wsgi_spec.rb b/spec/classes/mod/wsgi_spec.rb index ba1314eb..fb018099 100644 --- a/spec/classes/mod/wsgi_spec.rb +++ b/spec/classes/mod/wsgi_spec.rb @@ -1,217 +1,217 @@ # frozen_string_literal: true require 'spec_helper' describe 'apache::mod::wsgi', type: :class do it_behaves_like 'a mod class, without including apache' context 'on a Debian OS' do let :facts do { osfamily: 'Debian', operatingsystemrelease: '8', lsbdistcodename: 'jessie', operatingsystem: 'Debian', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_class('apache::mod::wsgi').with( 'wsgi_socket_prefix' => nil, ) } it { is_expected.to contain_package('libapache2-mod-wsgi') } end context 'on a RedHat OS' do let :facts do { osfamily: 'RedHat', operatingsystemrelease: '6', operatingsystem: 'RedHat', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', is_pe: false, } end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_class('apache::mod::wsgi').with( 'wsgi_socket_prefix' => '/var/run/wsgi', ) } it { is_expected.to contain_package('mod_wsgi') } context 'on RHEL8' do let(:facts) do super().merge(operatingsystemrelease: '8') end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_file('wsgi.load').with_content(%r{LoadModule wsgi_module modules/mod_wsgi_python3.so}) } it { is_expected.to contain_package('python3-mod_wsgi') } end describe 'with WSGIRestrictEmbedded enabled' do let :params do { wsgi_restrict_embedded: 'On' } end it { is_expected.to contain_file('wsgi.conf').with_content(%r{^ WSGIRestrictEmbedded On$}) } end describe 'with custom WSGISocketPrefix' do let :params do { wsgi_socket_prefix: 'run/wsgi' } end it { is_expected.to contain_file('wsgi.conf').with_content(%r{^ WSGISocketPrefix run\/wsgi$}) } end describe 'with custom WSGIPythonHome' do let :params do { wsgi_python_home: '/path/to/virtenv' } end it { is_expected.to contain_file('wsgi.conf').with_content(%r{^ WSGIPythonHome "\/path\/to\/virtenv"$}) } end describe 'with custom WSGIApplicationGroup' do let :params do { wsgi_application_group: '%{GLOBAL}' } end it { is_expected.to contain_file('wsgi.conf').with_content(%r{^ WSGIApplicationGroup "%{GLOBAL}"$}) } end describe 'with custom WSGIPythonOptimize' do let :params do { wsgi_python_optimize: 1 } end it { is_expected.to contain_file('wsgi.conf').with_content(%r{^ WSGIPythonOptimize 1$}) } end describe 'with custom package_name and mod_path' do let :params do { package_name: 'mod_wsgi_package', mod_path: '/foo/bar/baz', } end it { is_expected.to contain_apache__mod('wsgi').with('package' => 'mod_wsgi_package', 'path' => '/foo/bar/baz') } it { is_expected.to contain_package('mod_wsgi_package') } it { is_expected.to contain_file('wsgi.load').with_content(%r{LoadModule wsgi_module /foo/bar/baz}) } end describe 'with custom mod_path not containing /' do let :params do { package_name: 'mod_wsgi_package', mod_path: 'wsgi_mod_name.so', } end it { is_expected.to contain_apache__mod('wsgi').with('path' => 'modules/wsgi_mod_name.so', 'package' => 'mod_wsgi_package') } it { is_expected.to contain_file('wsgi.load').with_content(%r{LoadModule wsgi_module modules/wsgi_mod_name.so}) } end describe 'with package_name but no mod_path' do let :params do { mod_path: '/foo/bar/baz', } end - it { expect { catalogue }.to raise_error Puppet::Error, %r{apache::mod::wsgi - both package_name and mod_path must be specified!} } + it { is_expected.to compile.and_raise_error(%r{apache::mod::wsgi - both package_name and mod_path must be specified!}) } end describe 'with mod_path but no package_name' do let :params do { package_name: '/foo/bar/baz', } end - it { expect { catalogue }.to raise_error Puppet::Error, %r{apache::mod::wsgi - both package_name and mod_path must be specified!} } + it { is_expected.to compile.and_raise_error(%r{apache::mod::wsgi - both package_name and mod_path must be specified!}) } end end context 'on a FreeBSD OS' 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', is_pe: false, } end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_class('apache::mod::wsgi').with( 'wsgi_socket_prefix' => nil, ) } it { is_expected.to contain_package('www/mod_wsgi') } end context 'on a Gentoo OS' do let :facts do { osfamily: 'Gentoo', operatingsystem: 'Gentoo', operatingsystemrelease: '3.16.1-gentoo', id: 'root', kernel: 'Linux', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin', is_pe: false, } end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_class('apache::mod::wsgi').with( 'wsgi_socket_prefix' => nil, ) } it { is_expected.to contain_package('www-apache/mod_wsgi') } end context 'overriding mod_libs' do context 'on a RedHat OS', :compile 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', is_pe: false, } end let :pre_condition do <<-MANIFEST include apache::params class { 'apache': mod_packages => merge($::apache::params::mod_packages, { 'wsgi' => 'python3-mod_wsgi', }), mod_libs => merge($::apache::params::mod_libs, { 'wsgi' => 'mod_wsgi_python3.so', }) } MANIFEST end it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_file('wsgi.load').with_content(%r{LoadModule wsgi_module modules/mod_wsgi_python3.so}) } it { is_expected.to contain_package('python3-mod_wsgi') } end end end