mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
Upgrade php from 5.4.* to 5.5.*
This commit is contained in:
@@ -0,0 +1,324 @@
|
||||
require 'spec_helper'
|
||||
describe 'nginx::config' do
|
||||
|
||||
describe 'with defaults' do
|
||||
[
|
||||
{ :osfamily => 'debian', :operatingsystem => 'debian', },
|
||||
{ :osfamily => 'debian', :operatingsystem => 'ubuntu', },
|
||||
{ :osfamily => 'redhat', :operatingsystem => 'fedora', },
|
||||
{ :osfamily => 'redhat', :operatingsystem => 'rhel', },
|
||||
{ :osfamily => 'redhat', :operatingsystem => 'redhat', },
|
||||
{ :osfamily => 'redhat', :operatingsystem => 'centos', },
|
||||
{ :osfamily => 'redhat', :operatingsystem => 'scientific', },
|
||||
{ :osfamily => 'redhat', :operatingsystem => 'amazon', },
|
||||
{ :osfamily => 'suse', :operatingsystem => 'suse', },
|
||||
{ :osfamily => 'suse', :operatingsystem => 'opensuse', },
|
||||
{ :osfamily => 'gentoo', :operatingsystem => 'gentoo', },
|
||||
{ :osfamily => 'linux', :operatingsystem => 'gentoo', },
|
||||
].each do |facts|
|
||||
|
||||
context "when osfamily/operatingsystem is #{facts[:osfamily]}/#{facts[:operatingsystem]}" do
|
||||
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => facts[:osfamily],
|
||||
:operatingsystem => facts[:operatingsystem],
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_class("nginx::params") }
|
||||
|
||||
it { should contain_file("/etc/nginx").only_with(
|
||||
:path => "/etc/nginx",
|
||||
:ensure => 'directory',
|
||||
:owner => 'root',
|
||||
:group => 'root',
|
||||
:mode => '0644'
|
||||
)}
|
||||
it { should contain_file("/etc/nginx/conf.d").only_with(
|
||||
:path => '/etc/nginx/conf.d',
|
||||
:ensure => 'directory',
|
||||
:owner => 'root',
|
||||
:group => 'root',
|
||||
:mode => '0644'
|
||||
)}
|
||||
it { should contain_file("/etc/nginx/conf.mail.d").only_with(
|
||||
:path => '/etc/nginx/conf.mail.d',
|
||||
:ensure => 'directory',
|
||||
:owner => 'root',
|
||||
:group => 'root',
|
||||
:mode => '0644'
|
||||
)}
|
||||
it { should contain_file("/etc/nginx/conf.d/vhost_autogen.conf").with_ensure('absent') }
|
||||
it { should contain_file("/etc/nginx/conf.mail.d/vhost_autogen.conf").with_ensure('absent') }
|
||||
it { should contain_file("/var/nginx").with(
|
||||
:ensure => 'directory',
|
||||
:owner => 'root',
|
||||
:group => 'root',
|
||||
:mode => '0644'
|
||||
)}
|
||||
it { should contain_file("/var/nginx/client_body_temp").with(
|
||||
:ensure => 'directory',
|
||||
:group => 'root',
|
||||
:mode => '0644'
|
||||
)}
|
||||
it { should contain_file("/var/nginx/proxy_temp").with(
|
||||
:ensure => 'directory',
|
||||
:group => 'root',
|
||||
:mode => '0644'
|
||||
)}
|
||||
it { should contain_file('/etc/nginx/sites-enabled/default').with_ensure('absent') }
|
||||
it { should contain_file("/etc/nginx/nginx.conf").with(
|
||||
:ensure => 'file',
|
||||
:owner => 'root',
|
||||
:group => 'root',
|
||||
:mode => '0644'
|
||||
)}
|
||||
it { should contain_file("/etc/nginx/conf.d/proxy.conf").with(
|
||||
:ensure => 'file',
|
||||
:owner => 'root',
|
||||
:group => 'root',
|
||||
:mode => '0644'
|
||||
)}
|
||||
it { should contain_file("/tmp/nginx.d").with(
|
||||
:ensure => 'absent',
|
||||
:purge => true,
|
||||
:recurse => true
|
||||
)}
|
||||
it { should contain_file("/tmp/nginx.mail.d").with(
|
||||
:ensure => 'absent',
|
||||
:purge => true,
|
||||
:recurse => true
|
||||
)}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with defaults' do
|
||||
[
|
||||
{ :osfamily => 'debian', :operatingsystem => 'debian', },
|
||||
{ :osfamily => 'debian', :operatingsystem => 'ubuntu', },
|
||||
].each do |facts|
|
||||
|
||||
context "when osfamily/operatingsystem is #{facts[:osfamily]}/#{facts[:operatingsystem]}" do
|
||||
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => facts[:osfamily],
|
||||
:operatingsystem => facts[:operatingsystem],
|
||||
}
|
||||
end
|
||||
it { should contain_file("/var/nginx/client_body_temp").with(:owner => 'www-data')}
|
||||
it { should contain_file("/var/nginx/proxy_temp").with(:owner => 'www-data')}
|
||||
it { should contain_file("/etc/nginx/nginx.conf").with_content %r{^user www-data;}}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with defaults' do
|
||||
[
|
||||
{ :osfamily => 'redhat', :operatingsystem => 'fedora', },
|
||||
{ :osfamily => 'redhat', :operatingsystem => 'rhel', },
|
||||
{ :osfamily => 'redhat', :operatingsystem => 'redhat', },
|
||||
{ :osfamily => 'redhat', :operatingsystem => 'centos', },
|
||||
{ :osfamily => 'redhat', :operatingsystem => 'scientific', },
|
||||
{ :osfamily => 'redhat', :operatingsystem => 'amazon', },
|
||||
{ :osfamily => 'suse', :operatingsystem => 'suse', },
|
||||
{ :osfamily => 'suse', :operatingsystem => 'opensuse', },
|
||||
{ :osfamily => 'gentoo', :operatingsystem => 'gentoo', },
|
||||
{ :osfamily => 'linux', :operatingsystem => 'gentoo', },
|
||||
].each do |facts|
|
||||
|
||||
context "when osfamily/operatingsystem is #{facts[:osfamily]}/#{facts[:operatingsystem]}" do
|
||||
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => facts[:osfamily],
|
||||
:operatingsystem => facts[:operatingsystem],
|
||||
}
|
||||
end
|
||||
it { should contain_file("/var/nginx/client_body_temp").with(:owner => 'nginx')}
|
||||
it { should contain_file("/var/nginx/proxy_temp").with(:owner => 'nginx')}
|
||||
it { should contain_file("/etc/nginx/nginx.conf").with_content %r{^user nginx;}}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'os-independent items' do
|
||||
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'debian',
|
||||
:operatingsystem => 'debian',
|
||||
}
|
||||
end
|
||||
|
||||
describe "nginx.conf template content" do
|
||||
[
|
||||
{
|
||||
:title => 'should set worker_processes',
|
||||
:attr => 'worker_processes',
|
||||
:value => '4',
|
||||
:match => 'worker_processes 4;',
|
||||
},
|
||||
{
|
||||
:title => 'should set worker_rlimit_nofile',
|
||||
:attr => 'worker_rlimit_nofile',
|
||||
:value => '10000',
|
||||
:match => 'worker_rlimit_nofile 10000;',
|
||||
},
|
||||
{
|
||||
:title => 'should set error_log',
|
||||
:attr => 'nginx_error_log',
|
||||
:value => '/path/to/error.log',
|
||||
:match => 'error_log /path/to/error.log;',
|
||||
},
|
||||
{
|
||||
:title => 'should set worker_connections',
|
||||
:attr => 'worker_connections',
|
||||
:value => '100',
|
||||
:match => ' worker_connections 100;',
|
||||
},
|
||||
{
|
||||
:title => 'should set access_log',
|
||||
:attr => 'http_access_log',
|
||||
:value => '/path/to/access.log',
|
||||
:match => ' access_log /path/to/access.log;',
|
||||
},
|
||||
{
|
||||
:title => 'should set server_tokens',
|
||||
:attr => 'server_tokens',
|
||||
:value => 'on',
|
||||
:match => ' server_tokens on;',
|
||||
},
|
||||
{
|
||||
:title => 'should set proxy_cache_path',
|
||||
:attr => 'proxy_cache_path',
|
||||
:value => '/path/to/proxy.cache',
|
||||
:match => ' proxy_cache_path /path/to/proxy.cache levels=1 keys_zone=d2:100m max_size=500m inactive=20m;',
|
||||
},
|
||||
{
|
||||
:title => 'should not set proxy_cache_path',
|
||||
:attr => 'proxy_cache_path',
|
||||
:value => false,
|
||||
:notmatch => / proxy_cache_path \/path\/to\/proxy\.cache levels=1 keys_zone=d2:100m max_size=500m inactive=20m;/,
|
||||
},
|
||||
{
|
||||
:title => 'should contain ordered appended directives',
|
||||
:attr => 'http_cfg_append',
|
||||
:value => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' },
|
||||
:match => [
|
||||
' allow test value 3;',
|
||||
' test1 test value 1;',
|
||||
' test2 test value 2;',
|
||||
],
|
||||
},
|
||||
].each do |param|
|
||||
context "when #{param[:attr]} is #{param[:value]}" do
|
||||
let :params do { param[:attr].to_sym => param[:value] } end
|
||||
|
||||
it { should contain_file("/etc/nginx/nginx.conf").with_mode('0644') }
|
||||
it param[:title] do
|
||||
verify_contents(subject, "/etc/nginx/nginx.conf", Array(param[:match]))
|
||||
Array(param[:notmatch]).each do |item|
|
||||
should contain_file("/etc/nginx/nginx.conf").without_content(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "proxy.conf template content" do
|
||||
[
|
||||
{
|
||||
:title => 'should set client_max_body_size',
|
||||
:attr => 'client_max_body_size',
|
||||
:value => '5m',
|
||||
:match => 'client_max_body_size 5m;',
|
||||
},
|
||||
{
|
||||
:title => 'should set proxy_buffers',
|
||||
:attr => 'proxy_buffers',
|
||||
:value => '50 5k',
|
||||
:match => 'proxy_buffers 50 5k;',
|
||||
},
|
||||
{
|
||||
:title => 'should set proxy_buffer_size',
|
||||
:attr => 'proxy_buffer_size',
|
||||
:value => '2k',
|
||||
:match => 'proxy_buffer_size 2k;',
|
||||
},
|
||||
{
|
||||
:title => 'should set proxy_http_version',
|
||||
:attr => 'proxy_http_version',
|
||||
:value => '1.1',
|
||||
:match => 'proxy_http_version 1.1;',
|
||||
},
|
||||
{
|
||||
:title => 'should contain ordered appended directives',
|
||||
:attr => 'proxy_set_header',
|
||||
:value => ['header1','header2'],
|
||||
:match => [
|
||||
'proxy_set_header header1;',
|
||||
'proxy_set_header header2;',
|
||||
],
|
||||
},
|
||||
].each do |param|
|
||||
context "when #{param[:attr]} is #{param[:value]}" do
|
||||
let :params do { param[:attr].to_sym => param[:value] } end
|
||||
|
||||
it { should contain_file("/etc/nginx/conf.d/proxy.conf").with_mode('0644') }
|
||||
it param[:title] do
|
||||
verify_contents(subject, "/etc/nginx/conf.d/proxy.conf", Array(param[:match]))
|
||||
Array(param[:notmatch]).each do |item|
|
||||
should contain_file("/etc/nginx/conf.d/proxy.conf").without_content(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when confd_purge true" do
|
||||
let(:params) {{:confd_purge => true}}
|
||||
it { should contain_file('/etc/nginx/conf.d').with(
|
||||
:purge => true,
|
||||
:recurse => true
|
||||
)}
|
||||
end
|
||||
|
||||
context "when confd_purge false" do
|
||||
let(:params) {{:confd_purge => false}}
|
||||
it { should contain_file('/etc/nginx/conf.d').without([
|
||||
'ignore',
|
||||
'purge',
|
||||
'recurse'
|
||||
])}
|
||||
end
|
||||
|
||||
context "when vhost_purge true" do
|
||||
let(:params) {{:vhost_purge => true}}
|
||||
it { should contain_file('/etc/nginx/sites-available').with(
|
||||
:purge => true,
|
||||
:recurse => true
|
||||
)}
|
||||
it { should contain_file('/etc/nginx/sites-enabled').with(
|
||||
:purge => true,
|
||||
:recurse => true
|
||||
)}
|
||||
end
|
||||
|
||||
context "when vhost_purge false" do
|
||||
let(:params) {{:vhost_purge => false}}
|
||||
it { should contain_file('/etc/nginx/sites-available').without([
|
||||
'ignore',
|
||||
'purge',
|
||||
'recurse'
|
||||
])}
|
||||
it { should contain_file('/etc/nginx/sites-enabled').without([
|
||||
'ignore',
|
||||
'purge',
|
||||
'recurse'
|
||||
])}
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,61 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'nginx' do
|
||||
let :params do
|
||||
{
|
||||
:nginx_upstreams => { 'upstream1' => { 'members' => ['localhost:3000']} },
|
||||
:nginx_vhosts => { 'test2.local' => { 'www_root' => '/' } },
|
||||
:nginx_locations => { 'test2.local' => { 'vhost' => 'test2.local', 'www_root' => '/'} }
|
||||
}
|
||||
end
|
||||
|
||||
shared_examples "a Linux OS" do
|
||||
it { should compile.with_all_deps }
|
||||
it { should contain_class('nginx') }
|
||||
it { should contain_anchor('nginx::begin') }
|
||||
it { should contain_nginx__package.that_requires('Anchor[nginx::begin]') }
|
||||
it { should contain_nginx__config.that_requires('Class[nginx::package]') }
|
||||
it { should contain_nginx__service.that_subscribes_to('Anchor[nginx::begin]') }
|
||||
it { should contain_nginx__service.that_subscribes_to('Class[nginx::package]') }
|
||||
it { should contain_nginx__service.that_subscribes_to('Class[nginx::config]') }
|
||||
it { should contain_anchor('nginx::end').that_requires('Class[nginx::service]') }
|
||||
it { should contain_class("nginx::params") }
|
||||
it { should contain_nginx__resource__upstream("upstream1") }
|
||||
it { should contain_nginx__resource__vhost("test2.local") }
|
||||
it { should contain_nginx__resource__location("test2.local") }
|
||||
end
|
||||
|
||||
context "Debian OS" do
|
||||
it_behaves_like "a Linux OS" do
|
||||
let :facts do
|
||||
{
|
||||
:operatingsystem => 'Debian',
|
||||
:osfamily => 'Debian',
|
||||
:lsbdistcodename => 'precise',
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "RedHat OS" do
|
||||
it_behaves_like "a Linux OS" do
|
||||
let :facts do
|
||||
{
|
||||
:operatingsystem => 'RedHat',
|
||||
:osfamily => 'RedHat',
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "Suse OS" do
|
||||
it_behaves_like "a Linux OS" do
|
||||
let :facts do
|
||||
{
|
||||
:operatingsystem => 'SuSE',
|
||||
:osfamily => 'Suse',
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,163 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'nginx::package' do
|
||||
|
||||
shared_examples 'redhat' do |operatingsystem|
|
||||
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'RedHat' }}
|
||||
|
||||
context "using defaults" do
|
||||
it { should contain_package('nginx') }
|
||||
it { should contain_yumrepo('nginx-release').with(
|
||||
'baseurl' => 'http://nginx.org/packages/rhel/6/$basearch/',
|
||||
'descr' => 'nginx repo',
|
||||
'enabled' => '1',
|
||||
'gpgcheck' => '1',
|
||||
'priority' => '1',
|
||||
'gpgkey' => 'http://nginx.org/keys/nginx_signing.key'
|
||||
)}
|
||||
it { should contain_file('/etc/yum.repos.d/nginx-release.repo') }
|
||||
it { should contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::redhat]') }
|
||||
it { should contain_anchor('nginx::package::end').that_requires('Class[nginx::package::redhat]') }
|
||||
end
|
||||
|
||||
context "manage_repo => false" do
|
||||
let(:params) {{ :manage_repo => false }}
|
||||
it { should contain_package('nginx') }
|
||||
it { should_not contain_yumrepo('nginx-release') }
|
||||
it { should_not contain_file('/etc/yum.repos.d/nginx-release.repo') }
|
||||
end
|
||||
|
||||
context "lsbmajdistrelease = 5" do
|
||||
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'RedHat', :lsbmajdistrelease => 5 }}
|
||||
it { should contain_package('nginx') }
|
||||
it { should contain_yumrepo('nginx-release').with(
|
||||
'baseurl' => 'http://nginx.org/packages/rhel/5/$basearch/'
|
||||
)}
|
||||
it { should contain_file('/etc/yum.repos.d/nginx-release.repo') }
|
||||
end
|
||||
|
||||
describe 'installs the requested package version' do
|
||||
let(:facts) {{ :operatingsystem => 'redhat', :osfamily => 'redhat' }}
|
||||
let(:params) {{ :package_ensure => '3.0.0' }}
|
||||
|
||||
it 'installs 3.0.0 exactly' do
|
||||
should contain_package('nginx').with({
|
||||
'ensure' => '3.0.0'
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples 'debian' do |operatingsystem, lsbdistcodename|
|
||||
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'Debian', :lsbdistcodename => lsbdistcodename }}
|
||||
|
||||
context "using defaults" do
|
||||
it { should contain_package('nginx') }
|
||||
it { should_not contain_package('passenger') }
|
||||
it { should contain_apt__source('nginx').with(
|
||||
'location' => "http://nginx.org/packages/#{operatingsystem}",
|
||||
'repos' => 'nginx',
|
||||
'key' => '7BD9BF62',
|
||||
'key_source' => 'http://nginx.org/keys/nginx_signing.key'
|
||||
)}
|
||||
it { should contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::debian]') }
|
||||
it { should contain_anchor('nginx::package::end').that_requires('Class[nginx::package::debian]') }
|
||||
end
|
||||
|
||||
context "package_source => 'passenger'" do
|
||||
let(:params) {{ :package_source => 'passenger' }}
|
||||
it { should contain_package('nginx') }
|
||||
it { should contain_package('passenger') }
|
||||
it { should contain_apt__source('nginx').with(
|
||||
'location' => 'https://oss-binaries.phusionpassenger.com/apt/passenger',
|
||||
'repos' => "main",
|
||||
'key' => '561F9B9CAC40B2F7',
|
||||
'key_source' => 'https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt'
|
||||
)}
|
||||
end
|
||||
|
||||
context "manage_repo => false" do
|
||||
let(:params) {{ :manage_repo => false }}
|
||||
it { should contain_package('nginx') }
|
||||
it { should_not contain_apt__source('nginx') }
|
||||
it { should_not contain_package('passenger') }
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples 'suse' do |operatingsystem|
|
||||
let(:facts) {{ :operatingsystem => operatingsystem, :osfamily => 'Suse'}}
|
||||
[
|
||||
'nginx-0.8',
|
||||
'apache2',
|
||||
'apache2-itk',
|
||||
'apache2-utils',
|
||||
'gd',
|
||||
'libapr1',
|
||||
'libapr-util1',
|
||||
'libjpeg62',
|
||||
'libpng14-14',
|
||||
'libxslt',
|
||||
'rubygem-daemon_controller',
|
||||
'rubygem-fastthread',
|
||||
'rubygem-file-tail',
|
||||
'rubygem-passenger',
|
||||
'rubygem-passenger-nginx',
|
||||
'rubygem-rack',
|
||||
'rubygem-rake',
|
||||
'rubygem-spruz',
|
||||
].each do |package|
|
||||
it { should contain_package("#{package}") }
|
||||
end
|
||||
it { should contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::suse]') }
|
||||
it { should contain_anchor('nginx::package::end').that_requires('Class[nginx::package::suse]') }
|
||||
end
|
||||
|
||||
|
||||
context 'redhat' do
|
||||
it_behaves_like 'redhat', 'centos'
|
||||
it_behaves_like 'redhat', 'rhel'
|
||||
it_behaves_like 'redhat', 'redhat'
|
||||
it_behaves_like 'redhat', 'scientific'
|
||||
it_behaves_like 'redhat', 'amazon'
|
||||
end
|
||||
|
||||
context 'debian' do
|
||||
it_behaves_like 'debian', 'debian', 'wheezy'
|
||||
it_behaves_like 'debian', 'ubuntu', 'precise'
|
||||
end
|
||||
|
||||
context 'suse' do
|
||||
it_behaves_like 'suse', 'opensuse'
|
||||
it_behaves_like 'suse', 'suse'
|
||||
end
|
||||
|
||||
context 'amazon with facter < 1.7.2' do
|
||||
let(:facts) {{ :operatingsystem => 'Amazon', :osfamily => 'Linux' }}
|
||||
it { should contain_package('nginx') }
|
||||
it { should contain_yumrepo('nginx-release').with(
|
||||
'baseurl' => 'http://nginx.org/packages/rhel/6/$basearch/',
|
||||
'descr' => 'nginx repo',
|
||||
'enabled' => '1',
|
||||
'gpgcheck' => '1',
|
||||
'priority' => '1',
|
||||
'gpgkey' => 'http://nginx.org/keys/nginx_signing.key'
|
||||
)}
|
||||
it { should contain_file('/etc/yum.repos.d/nginx-release.repo') }
|
||||
it { should contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::redhat]') }
|
||||
it { should contain_anchor('nginx::package::end').that_requires('Class[nginx::package::redhat]') }
|
||||
end
|
||||
|
||||
context 'fedora' do
|
||||
# fedora is identical to the rest of osfamily RedHat except for not
|
||||
# including nginx-release
|
||||
let(:facts) {{ :operatingsystem => 'Fedora', :osfamily => 'RedHat', :lsbmajdistrelease => 6 }}
|
||||
it { should contain_package('nginx') }
|
||||
it { should_not contain_yumrepo('nginx-release') }
|
||||
it { should_not contain_file('/etc/yum.repos.d/nginx-release.repo') }
|
||||
end
|
||||
|
||||
context 'other' do
|
||||
let(:facts) {{ :operatingsystem => 'xxx', :osfamily => 'linux' }}
|
||||
it { expect { subject }.to raise_error(Puppet::Error, /Module nginx is not supported on xxx/) }
|
||||
end
|
||||
end
|
@@ -0,0 +1,15 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'nginx::params' do
|
||||
context "On a Debian OS" do
|
||||
let :facts do {
|
||||
:osfamily => 'debian',
|
||||
:operatingsystem => 'debian',
|
||||
} end
|
||||
|
||||
it { should contain_nginx__params }
|
||||
it { should have_class_count(1) } #only nginx::params itself
|
||||
it { should have_resource_count(0) } #params class should never declare resources
|
||||
|
||||
end
|
||||
end
|
@@ -0,0 +1,38 @@
|
||||
require 'spec_helper'
|
||||
describe 'nginx::service' do
|
||||
|
||||
let :facts do {
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'debian',
|
||||
} end
|
||||
|
||||
let :params do {
|
||||
:configtest_enable => false,
|
||||
:service_restart => '/etc/init.d/nginx configtest && /etc/init.d/nginx restart',
|
||||
:service_ensure => 'running',
|
||||
} end
|
||||
|
||||
context "using default parameters" do
|
||||
|
||||
it { should contain_service('nginx').with(
|
||||
:ensure => 'running',
|
||||
:enable => true,
|
||||
:hasstatus => true,
|
||||
:hasrestart => true
|
||||
)}
|
||||
|
||||
it { should contain_service('nginx').without_restart }
|
||||
|
||||
end
|
||||
|
||||
describe "when configtest_enable => true" do
|
||||
let(:params) {{ :configtest_enable => true, :service_restart => '/etc/init.d/nginx configtest && /etc/init.d/nginx restart'}}
|
||||
it { should contain_service('nginx').with_restart('/etc/init.d/nginx configtest && /etc/init.d/nginx restart') }
|
||||
|
||||
context "when service_restart => 'a restart command'" do
|
||||
let(:params) {{ :configtest_enable => true, :service_restart => 'a restart command' }}
|
||||
it { should contain_service('nginx').with_restart('a restart command') }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,621 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'nginx::resource::location' do
|
||||
let :title do
|
||||
'rspec-test'
|
||||
end
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'debian',
|
||||
}
|
||||
end
|
||||
let :pre_condition do
|
||||
[
|
||||
'include ::nginx::params',
|
||||
'include ::nginx::config',
|
||||
]
|
||||
end
|
||||
|
||||
describe 'os-independent items' do
|
||||
|
||||
describe 'basic assumptions' do
|
||||
let :params do {
|
||||
:www_root => "/var/www/rspec",
|
||||
:vhost => 'vhost1',
|
||||
} end
|
||||
|
||||
it { should contain_class("nginx::params") }
|
||||
it { should contain_class("nginx::config") }
|
||||
it { should contain_concat__fragment("vhost1-500-rspec-test").with_content(/location rspec-test/) }
|
||||
it { should_not contain_file('/etc/nginx/fastcgi_params') }
|
||||
it { should_not contain_concat__fragment("vhost1-800-rspec-test-ssl") }
|
||||
it { should_not contain_file("/etc/nginx/rspec-test_htpasswd") }
|
||||
end
|
||||
|
||||
describe "vhost_location_proxy template content" do
|
||||
[
|
||||
{
|
||||
:title => 'should set the location',
|
||||
:attr => 'location',
|
||||
:value => 'my_location',
|
||||
:match => ' location my_location {',
|
||||
},
|
||||
{
|
||||
:title => 'should contain ordered prepended directives',
|
||||
:attr => 'location_cfg_prepend',
|
||||
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3',
|
||||
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value1b"'],
|
||||
'subtest2' => '"sub test value2"' } },
|
||||
:match => [
|
||||
' allow test value 3;',
|
||||
' test1 test value 1;',
|
||||
' test2 test value 2a;',
|
||||
' test2 test value 2b;',
|
||||
' test4 subtest1 "sub test value1a";',
|
||||
' test4 subtest1 "sub test value1b";',
|
||||
' test4 subtest2 "sub test value2";',
|
||||
],
|
||||
},
|
||||
{
|
||||
:title => 'should set proxy_cache',
|
||||
:attr => 'proxy_cache',
|
||||
:value => 'value',
|
||||
:match => ' proxy_cache value;',
|
||||
},
|
||||
{
|
||||
:title => 'should not set proxy_cache',
|
||||
:attr => 'proxy_cache',
|
||||
:value => false,
|
||||
:notmatch => /proxy_cache/
|
||||
},
|
||||
{
|
||||
:title => 'should set proxy_method',
|
||||
:attr => 'proxy_method',
|
||||
:value => 'value',
|
||||
:match => ' proxy_method value;',
|
||||
},
|
||||
{
|
||||
:title => 'should set proxy_set_body',
|
||||
:attr => 'proxy_set_body',
|
||||
:value => 'value',
|
||||
:match => ' proxy_set_body value;',
|
||||
},
|
||||
{
|
||||
:title => 'should set proxy_pass',
|
||||
:attr => 'proxy',
|
||||
:value => 'value',
|
||||
:match => ' proxy_pass value;',
|
||||
},
|
||||
{
|
||||
:title => 'should set proxy_read_timeout',
|
||||
:attr => 'proxy_read_timeout',
|
||||
:value => 'value',
|
||||
:match => ' proxy_read_timeout value;',
|
||||
},
|
||||
{
|
||||
:title => 'should contain ordered appended directives',
|
||||
:attr => 'location_cfg_append',
|
||||
:value => { 'test1' => ['test value 1a', 'test value 1b'], 'test2' => 'test value 2', 'allow' => 'test value 3',
|
||||
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value1b"'],
|
||||
'subtest2' => '"sub test value2"' } },
|
||||
:match => [
|
||||
' allow test value 3;',
|
||||
' test1 test value 1a;',
|
||||
' test1 test value 1b;',
|
||||
' test2 test value 2;',
|
||||
' test4 subtest1 "sub test value1a";',
|
||||
' test4 subtest1 "sub test value1b";',
|
||||
' test4 subtest2 "sub test value2";',
|
||||
],
|
||||
},
|
||||
{
|
||||
:title => 'should contain rewrite rules',
|
||||
:attr => 'rewrite_rules',
|
||||
:value => [
|
||||
'^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last',
|
||||
'^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last',
|
||||
'^/users/(.*)$ /show?user=$1? last',
|
||||
],
|
||||
:match => [
|
||||
' rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last;',
|
||||
' rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last;',
|
||||
' rewrite ^/users/(.*)$ /show?user=$1? last;',
|
||||
],
|
||||
},
|
||||
{
|
||||
:title => 'should not set rewrite_rules',
|
||||
:attr => 'rewrite_rules',
|
||||
:value => [],
|
||||
:notmatch => /rewrite/
|
||||
},
|
||||
].each do |param|
|
||||
context "when #{param[:attr]} is #{param[:value]}" do
|
||||
let :default_params do { :location => 'location', :proxy => 'proxy_value', :vhost => 'vhost1' } end
|
||||
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
|
||||
|
||||
it { should contain_concat__fragment("vhost1-500-#{params[:location]}") }
|
||||
it param[:title] do
|
||||
lines = subject.resource('concat::fragment', "vhost1-500-#{params[:location]}").send(:parameters)[:content].split("\n")
|
||||
(lines & Array(param[:match])).should == Array(param[:match])
|
||||
Array(param[:notmatch]).each do |item|
|
||||
should contain_concat__fragment("vhost1-500-#{params[:location]}").without_content(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when proxy_cache_valid is 10m" do
|
||||
let :params do {
|
||||
:location => 'location',
|
||||
:proxy => 'proxy_value',
|
||||
:vhost => 'vhost1',
|
||||
:proxy_cache => 'true',
|
||||
:proxy_cache_valid => '10m',
|
||||
} end
|
||||
|
||||
it { should contain_concat__fragment("vhost1-500-location").with_content(/proxy_cache_valid 10m;/) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "vhost_location_alias template content" do
|
||||
[
|
||||
{
|
||||
:title => 'should set the location',
|
||||
:attr => 'location',
|
||||
:value => 'my_location',
|
||||
:match => ' location my_location {',
|
||||
},
|
||||
{
|
||||
:title => 'should contain ordered prepended directives',
|
||||
:attr => 'location_cfg_prepend',
|
||||
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3',
|
||||
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value1b"'],
|
||||
'subtest2' => '"sub test value2"' } },
|
||||
:match => [
|
||||
' allow test value 3;',
|
||||
' test1 test value 1;',
|
||||
' test2 test value 2a;',
|
||||
' test2 test value 2b;',
|
||||
' test4 subtest1 "sub test value1a";',
|
||||
' test4 subtest1 "sub test value1b";',
|
||||
' test4 subtest2 "sub test value2";',
|
||||
],
|
||||
},
|
||||
{
|
||||
:title => 'should set alias',
|
||||
:attr => 'location_alias',
|
||||
:value => 'value',
|
||||
:match => ' alias value;',
|
||||
},
|
||||
{
|
||||
:title => 'should contain ordered appended directives',
|
||||
:attr => 'location_cfg_append',
|
||||
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3',
|
||||
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value1b"'],
|
||||
'subtest2' => '"sub test value2"' } },
|
||||
:match => [
|
||||
' allow test value 3;',
|
||||
' test1 test value 1;',
|
||||
' test2 test value 2a;',
|
||||
' test2 test value 2b;',
|
||||
' test4 subtest1 "sub test value1a";',
|
||||
' test4 subtest1 "sub test value1b";',
|
||||
' test4 subtest2 "sub test value2";',
|
||||
],
|
||||
},
|
||||
].each do |param|
|
||||
context "when #{param[:attr]} is #{param[:value]}" do
|
||||
let :default_params do { :location => 'location', :location_alias => 'location_alias_value', :vhost => 'vhost1' } end
|
||||
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
|
||||
|
||||
it { should contain_concat__fragment("vhost1-500-#{params[:location]}") }
|
||||
it param[:title] do
|
||||
lines = subject.resource('concat::fragment', "vhost1-500-#{params[:location]}").send(:parameters)[:content].split("\n")
|
||||
(lines & Array(param[:match])).should == Array(param[:match])
|
||||
Array(param[:notmatch]).each do |item|
|
||||
should contain_concat__fragment("vhost1-500-#{params[:location]}").without_content(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "vhost_location_stub_status template content" do
|
||||
[
|
||||
{
|
||||
:title => 'should set the location',
|
||||
:attr => 'location',
|
||||
:value => 'my_location',
|
||||
:match => ' location my_location {',
|
||||
},
|
||||
{
|
||||
:title => 'should contain ordered prepended directives',
|
||||
:attr => 'location_cfg_prepend',
|
||||
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3',
|
||||
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value1b"'],
|
||||
'subtest2' => '"sub test value2"' } },
|
||||
:match => [
|
||||
' allow test value 3;',
|
||||
' test1 test value 1;',
|
||||
' test2 test value 2a;',
|
||||
' test2 test value 2b;',
|
||||
' test4 subtest1 "sub test value1a";',
|
||||
' test4 subtest1 "sub test value1b";',
|
||||
' test4 subtest2 "sub test value2";',
|
||||
],
|
||||
},
|
||||
{
|
||||
:title => 'should contain ordered appended directives',
|
||||
:attr => 'location_cfg_append',
|
||||
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3',
|
||||
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value1b"'],
|
||||
'subtest2' => '"sub test value2"' } },
|
||||
:match => [
|
||||
' allow test value 3;',
|
||||
' test1 test value 1;',
|
||||
' test2 test value 2a;',
|
||||
' test2 test value 2b;',
|
||||
' test4 subtest1 "sub test value1a";',
|
||||
' test4 subtest1 "sub test value1b";',
|
||||
' test4 subtest2 "sub test value2";',
|
||||
],
|
||||
},
|
||||
].each do |param|
|
||||
context "when #{param[:attr]} is #{param[:value]}" do
|
||||
let :default_params do { :location => 'location', :stub_status => true, :vhost => 'vhost1' } end
|
||||
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
|
||||
|
||||
it { should contain_concat__fragment("vhost1-500-#{params[:location]}") }
|
||||
it param[:title] do
|
||||
lines = subject.resource('concat::fragment', "vhost1-500-#{params[:location]}").send(:parameters)[:content].split("\n")
|
||||
(lines & Array(param[:match])).should == Array(param[:match])
|
||||
Array(param[:notmatch]).each do |item|
|
||||
should contain_concat__fragment("vhost1-500-#{params[:location]}").without_content(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "vhost_location_fastcgi template content" do
|
||||
[
|
||||
{
|
||||
:title => 'should set the location',
|
||||
:attr => 'location',
|
||||
:value => 'my_location',
|
||||
:match => ' location my_location {',
|
||||
},
|
||||
{
|
||||
:title => 'should contain ordered prepended directives',
|
||||
:attr => 'location_cfg_prepend',
|
||||
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3',
|
||||
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value1b"'],
|
||||
'subtest2' => '"sub test value2"' } },
|
||||
:match => [
|
||||
' allow test value 3;',
|
||||
' test1 test value 1;',
|
||||
' test2 test value 2a;',
|
||||
' test2 test value 2b;',
|
||||
' test4 subtest1 "sub test value1a";',
|
||||
' test4 subtest1 "sub test value1b";',
|
||||
' test4 subtest2 "sub test value2";',
|
||||
],
|
||||
},
|
||||
{
|
||||
:title => 'should set www_root',
|
||||
:attr => 'www_root',
|
||||
:value => '/',
|
||||
:match => ' root /;'
|
||||
},
|
||||
{
|
||||
:title => 'should set fastcgi_split_path',
|
||||
:attr => 'fastcgi_split_path',
|
||||
:value => 'value',
|
||||
:match => ' fastcgi_split_path_info value;'
|
||||
},
|
||||
{
|
||||
:title => 'should set try_file(s)',
|
||||
:attr => 'try_files',
|
||||
:value => ['name1','name2'],
|
||||
:match => ' try_files name1 name2;',
|
||||
},
|
||||
{
|
||||
:title => 'should set fastcgi_params',
|
||||
:attr => 'fastcgi_params',
|
||||
:value => 'value',
|
||||
:match => ' include value;'
|
||||
},
|
||||
{
|
||||
:title => 'should set fastcgi_pass',
|
||||
:attr => 'fastcgi',
|
||||
:value => 'value',
|
||||
:match => ' fastcgi_pass value;'
|
||||
},
|
||||
{
|
||||
:title => 'should set fastcgi_param',
|
||||
:attr => 'fastcgi_script',
|
||||
:value => 'value',
|
||||
:match => ' fastcgi_param SCRIPT_FILENAME value;',
|
||||
},
|
||||
{
|
||||
:title => 'should contain ordered appended directives',
|
||||
:attr => 'location_cfg_append',
|
||||
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3',
|
||||
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value1b"'],
|
||||
'subtest2' => '"sub test value2"' } },
|
||||
:match => [
|
||||
' allow test value 3;',
|
||||
' test1 test value 1;',
|
||||
' test2 test value 2a;',
|
||||
' test2 test value 2b;',
|
||||
' test4 subtest1 "sub test value1a";',
|
||||
' test4 subtest1 "sub test value1b";',
|
||||
' test4 subtest2 "sub test value2";',
|
||||
],
|
||||
},
|
||||
].each do |param|
|
||||
context "when #{param[:attr]} is #{param[:value]}" do
|
||||
let :default_params do { :location => 'location', :fastcgi => 'localhost:9000', :vhost => 'vhost1' } end
|
||||
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
|
||||
|
||||
it { should contain_concat__fragment("vhost1-500-#{params[:location]}") }
|
||||
it param[:title] do
|
||||
lines = subject.resource('concat::fragment', "vhost1-500-#{params[:location]}").send(:parameters)[:content].split("\n")
|
||||
(lines & Array(param[:match])).should == Array(param[:match])
|
||||
Array(param[:notmatch]).each do |item|
|
||||
should contain_concat__fragment("vhost1-500-#{params[:location]}").without_content(/#{item}/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "vhost_location_directory template content" do
|
||||
[
|
||||
{
|
||||
:title => 'should set the location',
|
||||
:attr => 'location',
|
||||
:value => 'my_location',
|
||||
:match => ' location my_location {',
|
||||
},
|
||||
{
|
||||
:title => 'should set the allow directive',
|
||||
:attr => 'location_allow',
|
||||
:value => ['rule1','rule2'],
|
||||
:match => [' allow rule1;', ' allow rule2;'],
|
||||
},
|
||||
{
|
||||
:title => 'should set the deny directive',
|
||||
:attr => 'location_deny',
|
||||
:value => ['rule1','rule2'],
|
||||
:match => [' deny rule1;', ' deny rule2;'],
|
||||
},
|
||||
{
|
||||
:title => 'should contain ordered prepended directives',
|
||||
:attr => 'location_cfg_prepend',
|
||||
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3',
|
||||
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value1b"'],
|
||||
'subtest2' => '"sub test value2"' } },
|
||||
:match => [
|
||||
' allow test value 3;',
|
||||
' test1 test value 1;',
|
||||
' test2 test value 2a;',
|
||||
' test2 test value 2b;',
|
||||
' test4 subtest1 "sub test value1a";',
|
||||
' test4 subtest1 "sub test value1b";',
|
||||
' test4 subtest2 "sub test value2";',
|
||||
],
|
||||
},
|
||||
{
|
||||
:title => 'should set www_root',
|
||||
:attr => 'www_root',
|
||||
:value => '/',
|
||||
:match => ' root /;'
|
||||
},
|
||||
{
|
||||
:title => 'should set try_file(s)',
|
||||
:attr => 'try_files',
|
||||
:value => ['name1','name2'],
|
||||
:match => ' try_files name1 name2;',
|
||||
},
|
||||
{
|
||||
:title => 'should set index_file(s)',
|
||||
:attr => 'index_files',
|
||||
:value => ['name1','name2'],
|
||||
:match => ' index name1 name2;',
|
||||
},
|
||||
{
|
||||
:title => 'should set auth_basic',
|
||||
:attr => 'auth_basic',
|
||||
:value => 'value',
|
||||
:match => ' auth_basic "value";',
|
||||
},
|
||||
{
|
||||
:title => 'should set auth_basic_user_file',
|
||||
:attr => 'auth_basic_user_file',
|
||||
:value => 'value',
|
||||
:match => ' auth_basic_user_file value;',
|
||||
},
|
||||
{
|
||||
:title => 'should contain ordered appended directives',
|
||||
:attr => 'location_cfg_append',
|
||||
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3',
|
||||
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value1b"'],
|
||||
'subtest2' => '"sub test value2"' } },
|
||||
:match => [
|
||||
' allow test value 3;',
|
||||
' test1 test value 1;',
|
||||
' test2 test value 2a;',
|
||||
' test2 test value 2b;',
|
||||
' test4 subtest1 "sub test value1a";',
|
||||
' test4 subtest1 "sub test value1b";',
|
||||
' test4 subtest2 "sub test value2";',
|
||||
],
|
||||
},
|
||||
{
|
||||
:title => 'should contain rewrite rules',
|
||||
:attr => 'rewrite_rules',
|
||||
:value => [
|
||||
'^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last',
|
||||
'^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last',
|
||||
'^/users/(.*)$ /show?user=$1? last',
|
||||
],
|
||||
:match => [
|
||||
' rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last;',
|
||||
' rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last;',
|
||||
' rewrite ^/users/(.*)$ /show?user=$1? last;',
|
||||
],
|
||||
},
|
||||
{
|
||||
:title => 'should not set rewrite_rules',
|
||||
:attr => 'rewrite_rules',
|
||||
:value => [],
|
||||
:notmatch => /rewrite/
|
||||
},
|
||||
].each do |param|
|
||||
context "when #{param[:attr]} is #{param[:value]}" do
|
||||
let :default_params do { :location => 'location', :www_root => '/var/www/root', :vhost => 'vhost1' } end
|
||||
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
|
||||
|
||||
it { should contain_concat__fragment("vhost1-500-#{params[:location]}") }
|
||||
it param[:title] do
|
||||
lines = subject.resource('concat::fragment', "vhost1-500-#{params[:location]}").send(:parameters)[:content].split("\n")
|
||||
(lines & Array(param[:match])).should == Array(param[:match])
|
||||
Array(param[:notmatch]).each do |item|
|
||||
should contain_concat__fragment("vhost1-500-#{params[:location]}").without_content(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "vhost_location_empty template content" do
|
||||
[
|
||||
{
|
||||
:title => 'should set the location',
|
||||
:attr => 'location',
|
||||
:value => 'my_location',
|
||||
:match => ' location my_location {',
|
||||
},
|
||||
{
|
||||
:title => 'should contain ordered config directives',
|
||||
:attr => 'location_custom_cfg',
|
||||
:value => { 'test1' => ['test value 1a', 'test value 1b'], 'test2' => 'test value 2', 'allow' => 'test value 3',
|
||||
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value1b"'],
|
||||
'subtest2' => '"sub test value2"' } },
|
||||
:match => [
|
||||
' allow test value 3;',
|
||||
' test1 test value 1a;',
|
||||
' test1 test value 1b;',
|
||||
' test2 test value 2;',
|
||||
' test4 subtest1 "sub test value1a";',
|
||||
' test4 subtest1 "sub test value1b";',
|
||||
' test4 subtest2 "sub test value2";',
|
||||
],
|
||||
},
|
||||
].each do |param|
|
||||
context "when #{param[:attr]} is #{param[:value]}" do
|
||||
let :default_params do { :location => 'location', :location_custom_cfg => {'test1'=>'value1'}, :vhost => 'vhost1' } end
|
||||
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
|
||||
|
||||
it { should contain_concat__fragment("vhost1-500-#{params[:location]}") }
|
||||
it param[:title] do
|
||||
lines = subject.resource('concat::fragment', "vhost1-500-#{params[:location]}").send(:parameters)[:content].split("\n")
|
||||
(lines & Array(param[:match])).should == Array(param[:match])
|
||||
Array(param[:notmatch]).each do |item|
|
||||
should contain_concat__fragment("vhost1-500-#{params[:location]}").without_content(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'attribute resources' do
|
||||
context 'when fastcgi => "localhost:9000"' do
|
||||
let :params do { :fastcgi => 'localhost:9000', :vhost => 'vhost1' } end
|
||||
|
||||
it { should contain_file('/etc/nginx/fastcgi_params').with_mode('0770') }
|
||||
end
|
||||
|
||||
context 'when ssl_only => true' do
|
||||
let :params do { :ssl_only => true, :vhost => 'vhost1', :www_root => '/', } end
|
||||
it { should_not contain_concat__fragment("vhost1-500-rspec-test") }
|
||||
end
|
||||
|
||||
context 'when ssl_only => false' do
|
||||
let :params do { :ssl_only => false, :vhost => 'vhost1', :www_root => '/', } end
|
||||
|
||||
it { should contain_concat__fragment("vhost1-500-rspec-test") }
|
||||
end
|
||||
|
||||
context 'when ssl => true' do
|
||||
let :params do { :ssl => true, :vhost => 'vhost1', :www_root => '/', } end
|
||||
|
||||
it { should contain_concat__fragment("vhost1-800-rspec-test-ssl") }
|
||||
end
|
||||
|
||||
context 'when ssl => false' do
|
||||
let :params do { :ssl => false, :vhost => 'vhost1', :www_root => '/', } end
|
||||
|
||||
it { should_not contain_concat__fragment("vhost1-800-rspec-test-ssl") }
|
||||
end
|
||||
|
||||
context 'when auth_basic_user_file => true' do
|
||||
let :params do { :auth_basic_user_file => '/path/to/file', :vhost => 'vhost1', :www_root => '/', } end
|
||||
|
||||
it { should contain_file("/etc/nginx/rspec-test_htpasswd") }
|
||||
end
|
||||
|
||||
context 'when ensure => absent' do
|
||||
let :params do {
|
||||
:www_root => '/',
|
||||
:vhost => 'vhost1',
|
||||
:ensure => 'absent',
|
||||
:ssl => true,
|
||||
:auth_basic_user_file => '/path/to/file',
|
||||
} end
|
||||
|
||||
it { should contain_file("/etc/nginx/rspec-test_htpasswd").with_ensure('absent') }
|
||||
end
|
||||
|
||||
context "vhost missing" do
|
||||
let :params do {
|
||||
:www_root => '/',
|
||||
} end
|
||||
|
||||
it { expect { should contain_class('nginx::resource::location') }.to raise_error(Puppet::Error, /Cannot create a location reference without attaching to a virtual host/) }
|
||||
end
|
||||
|
||||
context "location type missing" do
|
||||
let :params do {
|
||||
:vhost => 'vhost1',
|
||||
} end
|
||||
|
||||
it { expect { should contain_class('nginx::resource::location') }.to raise_error(Puppet::Error, /Cannot create a location reference without a www_root, proxy, location_alias, fastcgi, stub_status, or location_custom_cfg defined/) }
|
||||
end
|
||||
|
||||
context "www_root and proxy are set" do
|
||||
let :params do {
|
||||
:vhost => 'vhost1',
|
||||
:www_root => '/',
|
||||
:proxy => 'http://localhost:8000/uri/',
|
||||
} end
|
||||
|
||||
it { expect { should contain_class('nginx::resource::location') }.to raise_error(Puppet::Error, /Cannot define both directory and proxy in a virtual host/) }
|
||||
end
|
||||
|
||||
context 'when vhost name is sanitized' do
|
||||
let :title do 'www.rspec-location.com' end
|
||||
let :params do {
|
||||
:vhost => 'www rspec-vhost com',
|
||||
:www_root => '/',
|
||||
:ssl => true,
|
||||
} end
|
||||
|
||||
it { should contain_concat__fragment("www_rspec-vhost_com-500-www.rspec-location.com").with_target('/etc/nginx/sites-available/www_rspec-vhost_com.conf') }
|
||||
it { should contain_concat__fragment("www_rspec-vhost_com-800-www.rspec-location.com-ssl").with_target('/etc/nginx/sites-available/www_rspec-vhost_com.conf') }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,401 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'nginx::resource::mailhost' do
|
||||
let :title do
|
||||
'www.rspec.example.com'
|
||||
end
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'debian',
|
||||
:operatingsystem => 'debian',
|
||||
:ipaddress6 => '::',
|
||||
}
|
||||
end
|
||||
let :default_params do
|
||||
{
|
||||
:listen_port => 25,
|
||||
:ipv6_enable => true,
|
||||
}
|
||||
end
|
||||
let :pre_condition do
|
||||
[
|
||||
'include ::nginx::config',
|
||||
]
|
||||
end
|
||||
|
||||
describe 'os-independent items' do
|
||||
|
||||
describe 'basic assumptions' do
|
||||
let :params do default_params end
|
||||
it { should contain_class("nginx::config") }
|
||||
it { should contain_concat("/etc/nginx/conf.mail.d/#{title}.conf").with({
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'mode' => '0644',
|
||||
})}
|
||||
it { should contain_concat__fragment("#{title}-header") }
|
||||
it { should_not contain_concat__fragment("#{title}-ssl") }
|
||||
end
|
||||
|
||||
describe "mailhost template content" do
|
||||
[
|
||||
{
|
||||
:title => 'should set the IPv4 listen IP',
|
||||
:attr => 'listen_ip',
|
||||
:value => '127.0.0.1',
|
||||
:match => ' listen 127.0.0.1:25;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv4 listen port',
|
||||
:attr => 'listen_port',
|
||||
:value => 45,
|
||||
:match => ' listen *:45;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv4 listen options',
|
||||
:attr => 'listen_options',
|
||||
:value => 'spdy default',
|
||||
:match => ' listen *:25 spdy default;',
|
||||
},
|
||||
{
|
||||
:title => 'should enable IPv6',
|
||||
:attr => 'ipv6_enable',
|
||||
:value => true,
|
||||
:match => ' listen [::]:80 default ipv6only=on;',
|
||||
},
|
||||
{
|
||||
:title => 'should not enable IPv6',
|
||||
:attr => 'ipv6_enable',
|
||||
:value => false,
|
||||
:notmatch => / listen \[::\]:80 default ipv6only=on;/,
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv6 listen IP',
|
||||
:attr => 'ipv6_listen_ip',
|
||||
:value => '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
|
||||
:match => ' listen [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80 default ipv6only=on;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv6 listen port',
|
||||
:attr => 'ipv6_listen_port',
|
||||
:value => 45,
|
||||
:match => ' listen [::]:45 default ipv6only=on;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv6 listen options',
|
||||
:attr => 'ipv6_listen_options',
|
||||
:value => 'spdy',
|
||||
:match => ' listen [::]:80 spdy;',
|
||||
},
|
||||
{
|
||||
:title => 'should set servername(s)',
|
||||
:attr => 'server_name',
|
||||
:value => ['name1','name2'],
|
||||
:match => ' server_name name1 name2;',
|
||||
},
|
||||
{
|
||||
:title => 'should set protocol',
|
||||
:attr => 'protocol',
|
||||
:value => 'test-protocol',
|
||||
:match => ' protocol test-protocol;',
|
||||
},
|
||||
{
|
||||
:title => 'should set xclient',
|
||||
:attr => 'xclient',
|
||||
:value => 'test-xclient',
|
||||
:match => ' xclient test-xclient;',
|
||||
},
|
||||
{
|
||||
:title => 'should set auth_http',
|
||||
:attr => 'auth_http',
|
||||
:value => 'test-auth_http',
|
||||
:match => ' auth_http test-auth_http;',
|
||||
},
|
||||
{
|
||||
:title => 'should set starttls',
|
||||
:attr => 'starttls',
|
||||
:value => 'on',
|
||||
:match => ' starttls on;',
|
||||
},
|
||||
{
|
||||
:title => 'should set starttls',
|
||||
:attr => 'starttls',
|
||||
:value => 'only',
|
||||
:match => ' starttls only;',
|
||||
},
|
||||
{
|
||||
:title => 'should not enable SSL',
|
||||
:attr => 'starttls',
|
||||
:value => 'off',
|
||||
:notmatch => / ssl_session_timeout 5m;/,
|
||||
},
|
||||
].each do |param|
|
||||
context "when #{param[:attr]} is #{param[:value]}" do
|
||||
let :default_params do {
|
||||
:listen_port => 25,
|
||||
:ipv6_enable => true,
|
||||
:ssl_cert => 'dummy.crt',
|
||||
:ssl_key => 'dummy.key',
|
||||
} end
|
||||
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
|
||||
|
||||
it { should contain_concat__fragment("#{title}-header") }
|
||||
it param[:title] do
|
||||
lines = subject.resource('concat::fragment', "#{title}-header").send(:parameters)[:content].split("\n")
|
||||
(lines & Array(param[:match])).should == Array(param[:match])
|
||||
Array(param[:notmatch]).each do |item|
|
||||
should contain_concat__fragment("#{title}-header").without_content(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "mailhost template content (SSL enabled)" do
|
||||
[
|
||||
{
|
||||
:title => 'should enable SSL',
|
||||
:attr => 'starttls',
|
||||
:value => 'on',
|
||||
:match => ' ssl_session_timeout 5m;',
|
||||
},
|
||||
{
|
||||
:title => 'should enable SSL',
|
||||
:attr => 'starttls',
|
||||
:value => 'only',
|
||||
:match => ' ssl_session_timeout 5m;',
|
||||
},
|
||||
{
|
||||
:title => 'should not enable SSL',
|
||||
:attr => 'starttls',
|
||||
:value => 'off',
|
||||
:notmatch => / ssl_session_timeout 5m;/,
|
||||
},
|
||||
{
|
||||
:title => 'should set ssl_certificate',
|
||||
:attr => 'ssl_cert',
|
||||
:value => 'test-ssl-cert',
|
||||
:match => ' ssl_certificate test-ssl-cert;',
|
||||
},
|
||||
{
|
||||
:title => 'should set ssl_certificate_key',
|
||||
:attr => 'ssl_key',
|
||||
:value => 'test-ssl-cert-key',
|
||||
:match => ' ssl_certificate_key test-ssl-cert-key;',
|
||||
},
|
||||
].each do |param|
|
||||
context "when #{param[:attr]} is #{param[:value]}" do
|
||||
let :default_params do {
|
||||
:listen_port => 25,
|
||||
:starttls => 'on',
|
||||
:ssl_cert => 'dummy.crt',
|
||||
:ssl_key => 'dummy.key',
|
||||
} end
|
||||
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
|
||||
|
||||
it { should contain_concat__fragment("#{title}-header") }
|
||||
it param[:title] do
|
||||
lines = subject.resource('concat::fragment', "#{title}-header").send(:parameters)[:content].split("\n")
|
||||
(lines & Array(param[:match])).should == Array(param[:match])
|
||||
Array(param[:notmatch]).each do |item|
|
||||
should contain_concat__fragment("#{title}-header").without_content(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "mailhost_ssl template content" do
|
||||
[
|
||||
{
|
||||
:title => 'should set the IPv4 SSL listen port',
|
||||
:attr => 'ssl_port',
|
||||
:value => '45',
|
||||
:match => ' listen 45;',
|
||||
},
|
||||
{
|
||||
:title => 'should enable IPv6',
|
||||
:attr => 'ipv6_enable',
|
||||
:value => true,
|
||||
:match => ' listen [::]:80 default ipv6only=on;',
|
||||
},
|
||||
{
|
||||
:title => 'should not enable IPv6',
|
||||
:attr => 'ipv6_enable',
|
||||
:value => false,
|
||||
:notmatch => / listen \[::\]:80 default ipv6only=on;/,
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv6 listen IP',
|
||||
:attr => 'ipv6_listen_ip',
|
||||
:value => '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
|
||||
:match => ' listen [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80 default ipv6only=on;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv6 listen port',
|
||||
:attr => 'ipv6_listen_port',
|
||||
:value => 45,
|
||||
:match => ' listen [::]:45 default ipv6only=on;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv6 listen options',
|
||||
:attr => 'ipv6_listen_options',
|
||||
:value => 'spdy',
|
||||
:match => ' listen [::]:80 spdy;',
|
||||
},
|
||||
{
|
||||
:title => 'should set servername(s)',
|
||||
:attr => 'server_name',
|
||||
:value => ['name1','name2'],
|
||||
:match => ' server_name name1 name2;',
|
||||
},
|
||||
{
|
||||
:title => 'should set protocol',
|
||||
:attr => 'protocol',
|
||||
:value => 'test-protocol',
|
||||
:match => ' protocol test-protocol;',
|
||||
},
|
||||
{
|
||||
:title => 'should set xclient',
|
||||
:attr => 'xclient',
|
||||
:value => 'test-xclient',
|
||||
:match => ' xclient test-xclient;',
|
||||
},
|
||||
{
|
||||
:title => 'should set auth_http',
|
||||
:attr => 'auth_http',
|
||||
:value => 'test-auth_http',
|
||||
:match => ' auth_http test-auth_http;',
|
||||
},
|
||||
{
|
||||
:title => 'should set ssl_certificate',
|
||||
:attr => 'ssl_cert',
|
||||
:value => 'test-ssl-cert',
|
||||
:match => ' ssl_certificate test-ssl-cert;',
|
||||
},
|
||||
{
|
||||
:title => 'should set ssl_certificate_key',
|
||||
:attr => 'ssl_key',
|
||||
:value => 'test-ssl-cert-key',
|
||||
:match => ' ssl_certificate_key test-ssl-cert-key;',
|
||||
},
|
||||
].each do |param|
|
||||
context "when #{param[:attr]} is #{param[:value]}" do
|
||||
let :default_params do {
|
||||
:listen_port => 25,
|
||||
:ipv6_enable => true,
|
||||
:ssl => true,
|
||||
:ssl_cert => 'dummy.crt',
|
||||
:ssl_key => 'dummy.key',
|
||||
} end
|
||||
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
|
||||
|
||||
it { should contain_concat__fragment("#{title}-ssl") }
|
||||
it param[:title] do
|
||||
lines = subject.resource('concat::fragment', "#{title}-ssl").send(:parameters)[:content].split("\n")
|
||||
(lines & Array(param[:match])).should == Array(param[:match])
|
||||
Array(param[:notmatch]).each do |item|
|
||||
should contain_concat__fragment("#{title}-ssl").without_content(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'attribute resources' do
|
||||
context "SSL cert missing and ssl => true" do
|
||||
let :params do default_params.merge({
|
||||
:ssl => true,
|
||||
:ssl_key => 'key',
|
||||
}) end
|
||||
|
||||
it { expect { should contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
|
||||
end
|
||||
|
||||
context "SSL key missing and ssl => true" do
|
||||
let :params do default_params.merge({
|
||||
:ssl => true,
|
||||
:ssl_cert => 'cert',
|
||||
}) end
|
||||
|
||||
it { expect { should contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
|
||||
end
|
||||
|
||||
context "SSL cert missing and starttls => 'on'" do
|
||||
let :params do default_params.merge({
|
||||
:starttls => 'on',
|
||||
:ssl_key => 'key',
|
||||
}) end
|
||||
|
||||
it { expect { should contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
|
||||
end
|
||||
|
||||
context "SSL key missing and starttls => 'on'" do
|
||||
let :params do default_params.merge({
|
||||
:starttls => 'on',
|
||||
:ssl_cert => 'cert',
|
||||
}) end
|
||||
|
||||
it { expect { should contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
|
||||
end
|
||||
|
||||
context "SSL cert missing and starttls => 'only'" do
|
||||
let :params do default_params.merge({
|
||||
:starttls => 'only',
|
||||
:ssl_key => 'key',
|
||||
}) end
|
||||
|
||||
it { expect { should contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
|
||||
end
|
||||
|
||||
context "SSL key missing and starttls => 'only'" do
|
||||
let :params do default_params.merge({
|
||||
:starttls => 'only',
|
||||
:ssl_cert => 'cert',
|
||||
}) end
|
||||
|
||||
it { expect { should contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
|
||||
end
|
||||
|
||||
context 'when listen_port != ssl_port' do
|
||||
let :params do default_params.merge({
|
||||
:listen_port => 80,
|
||||
:ssl_port => 443,
|
||||
}) end
|
||||
|
||||
it { should contain_concat__fragment("#{title}-header") }
|
||||
end
|
||||
|
||||
context 'when listen_port == ssl_port' do
|
||||
let :params do default_params.merge({
|
||||
:listen_port => 80,
|
||||
:ssl_port => 80,
|
||||
}) end
|
||||
|
||||
it { should_not contain_concat__fragment("#{title}-header") }
|
||||
end
|
||||
|
||||
context 'when ssl => true' do
|
||||
let :params do default_params.merge({
|
||||
:ensure => 'absent',
|
||||
:ssl => true,
|
||||
:ssl_key => 'dummy.key',
|
||||
:ssl_cert => 'dummy.cert',
|
||||
}) end
|
||||
|
||||
it { should contain_concat__fragment("#{title}-header") }
|
||||
it { should contain_concat__fragment("#{title}-ssl") }
|
||||
end
|
||||
|
||||
context 'when ssl => false' do
|
||||
let :params do default_params.merge({
|
||||
:ensure => 'absent',
|
||||
:ssl => false,
|
||||
}) end
|
||||
|
||||
it { should contain_concat__fragment("#{title}-header") }
|
||||
it { should_not contain_concat__fragment("#{title}-ssl") }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,93 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'nginx::resource::upstream' do
|
||||
let :title do
|
||||
'upstream-test'
|
||||
end
|
||||
|
||||
let :default_params do
|
||||
{
|
||||
:members => ['test'],
|
||||
}
|
||||
end
|
||||
|
||||
describe 'os-independent items' do
|
||||
|
||||
describe 'basic assumptions' do
|
||||
let :params do default_params end
|
||||
|
||||
it { should contain_file("/etc/nginx/conf.d/#{title}-upstream.conf").with(
|
||||
{
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'mode' => '0644',
|
||||
'ensure' => 'file',
|
||||
'content' => /upstream #{title}/,
|
||||
}
|
||||
)}
|
||||
end
|
||||
|
||||
describe "upstream.conf template content" do
|
||||
[
|
||||
{
|
||||
:title => 'should contain ordered prepended directives',
|
||||
:attr => 'upstream_cfg_prepend',
|
||||
:value => {
|
||||
'test3' => 'test value 3',
|
||||
'test1' => 'test value 1',
|
||||
'test2' => 'test value 2',
|
||||
'test4' => ['test value 1', 'test value 2'],
|
||||
'test5' => {'subkey1' => 'subvalue1'},
|
||||
'test6' => {'subkey1' => ['subvalue1', 'subvalue2']},
|
||||
},
|
||||
:match => [
|
||||
' test1 test value 1;',
|
||||
' test2 test value 2;',
|
||||
' test3 test value 3;',
|
||||
' test4 test value 1;',
|
||||
' test4 test value 2;',
|
||||
' test5 subkey1 subvalue1;',
|
||||
' test6 subkey1 subvalue1;',
|
||||
' test6 subkey1 subvalue2;',
|
||||
],
|
||||
},
|
||||
{
|
||||
:title => 'should set server',
|
||||
:attr => 'members',
|
||||
:value => [
|
||||
'test3',
|
||||
'test1',
|
||||
'test2',
|
||||
],
|
||||
:match => [
|
||||
' server test3 fail_timeout=10s;',
|
||||
' server test1 fail_timeout=10s;',
|
||||
' server test2 fail_timeout=10s;',
|
||||
],
|
||||
},
|
||||
].each do |param|
|
||||
context "when #{param[:attr]} is #{param[:value]}" do
|
||||
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
|
||||
|
||||
it { should contain_file("/etc/nginx/conf.d/#{title}-upstream.conf").with_mode('0644') }
|
||||
it param[:title] do
|
||||
verify_contents(subject, "/etc/nginx/conf.d/#{title}-upstream.conf", Array(param[:match]))
|
||||
Array(param[:notmatch]).each do |item|
|
||||
should contain_file("/etc/nginx/conf.d/#{title}-upstream.conf").without_content(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when ensure => absent' do
|
||||
let :params do default_params.merge(
|
||||
{
|
||||
:ensure => 'absent'
|
||||
}
|
||||
) end
|
||||
|
||||
it { should contain_file("/etc/nginx/conf.d/#{title}-upstream.conf").with_ensure('absent') }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,647 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'nginx::resource::vhost' do
|
||||
let :title do
|
||||
'www.rspec.example.com'
|
||||
end
|
||||
let :default_params do
|
||||
{
|
||||
:www_root => '/',
|
||||
:ipv6_enable => true,
|
||||
}
|
||||
end
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'debian',
|
||||
:ipaddress6 => '::',
|
||||
}
|
||||
end
|
||||
let :pre_condition do
|
||||
[
|
||||
'include ::nginx::params',
|
||||
'include ::nginx::config',
|
||||
]
|
||||
end
|
||||
|
||||
describe 'os-independent items' do
|
||||
|
||||
describe 'basic assumptions' do
|
||||
let :params do default_params end
|
||||
it { should contain_class("nginx::params") }
|
||||
it { should contain_class("nginx::config") }
|
||||
it { should contain_concat("/etc/nginx/sites-available/#{title}.conf").with({
|
||||
'owner' => 'root',
|
||||
'group' => 'root',
|
||||
'mode' => '0644',
|
||||
})}
|
||||
it { should contain_concat__fragment("#{title}-header").with_content(%r{access_log[ ]+/var/log/nginx/www\.rspec\.example\.com\.access\.log}) }
|
||||
it { should contain_concat__fragment("#{title}-header").with_content(%r{error_log[ ]+/var/log/nginx/www\.rspec\.example\.com\.error\.log}) }
|
||||
it { should contain_concat__fragment("#{title}-footer") }
|
||||
it { should contain_nginx__resource__location("#{title}-default") }
|
||||
it { should_not contain_file("/etc/nginx/fastcgi_params") }
|
||||
it { should contain_file("#{title}.conf symlink").with({
|
||||
'ensure' => 'link',
|
||||
'path' => "/etc/nginx/sites-enabled/#{title}.conf",
|
||||
'target' => "/etc/nginx/sites-available/#{title}.conf"
|
||||
})}
|
||||
end
|
||||
|
||||
describe "vhost_header template content" do
|
||||
[
|
||||
{
|
||||
:title => 'should set the IPv4 listen IP',
|
||||
:attr => 'listen_ip',
|
||||
:value => '127.0.0.1',
|
||||
:match => ' listen 127.0.0.1:80;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv4 listen port',
|
||||
:attr => 'listen_port',
|
||||
:value => 45,
|
||||
:match => ' listen *:45;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv4 listen options',
|
||||
:attr => 'listen_options',
|
||||
:value => 'spdy default',
|
||||
:match => ' listen *:80 spdy default;',
|
||||
},
|
||||
{
|
||||
:title => 'should enable IPv6',
|
||||
:attr => 'ipv6_enable',
|
||||
:value => true,
|
||||
:match => ' listen [::]:80 default ipv6only=on;',
|
||||
},
|
||||
{
|
||||
:title => 'should not enable IPv6',
|
||||
:attr => 'ipv6_enable',
|
||||
:value => false,
|
||||
:notmatch => / listen \[::\]:80 default ipv6only=on;/,
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv6 listen IP',
|
||||
:attr => 'ipv6_listen_ip',
|
||||
:value => '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
|
||||
:match => ' listen [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80 default ipv6only=on;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv6 listen port',
|
||||
:attr => 'ipv6_listen_port',
|
||||
:value => 45,
|
||||
:match => ' listen [::]:45 default ipv6only=on;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv6 listen options',
|
||||
:attr => 'ipv6_listen_options',
|
||||
:value => 'spdy',
|
||||
:match => ' listen [::]:80 spdy;',
|
||||
},
|
||||
{
|
||||
:title => 'should set servername(s)',
|
||||
:attr => 'server_name',
|
||||
:value => ['name1','name2'],
|
||||
:match => ' server_name name1 name2;',
|
||||
},
|
||||
{
|
||||
:title => 'should rewrite www servername to non-www',
|
||||
:attr => 'rewrite_www_to_non_www',
|
||||
:value => true,
|
||||
:match => ' server_name rspec.example.com;',
|
||||
},
|
||||
{
|
||||
:title => 'should not rewrite www servername to non-www',
|
||||
:attr => 'rewrite_www_to_non_www',
|
||||
:value => false,
|
||||
:match => ' server_name www.rspec.example.com;',
|
||||
},
|
||||
{
|
||||
:title => 'should set auth_basic',
|
||||
:attr => 'auth_basic',
|
||||
:value => 'value',
|
||||
:match => ' auth_basic "value";',
|
||||
},
|
||||
{
|
||||
:title => 'should set auth_basic_user_file',
|
||||
:attr => 'auth_basic_user_file',
|
||||
:value => 'value',
|
||||
:match => ' auth_basic_user_file value;',
|
||||
},
|
||||
{
|
||||
:title => 'should contain ordered prepended directives',
|
||||
:attr => 'vhost_cfg_prepend',
|
||||
:value => { 'test1' => ['test value 1a', 'test value 1b'], 'test2' => 'test value 2', 'allow' => 'test value 3' },
|
||||
:match => [
|
||||
' allow test value 3;',
|
||||
' test1 test value 1a;',
|
||||
' test1 test value 1b;',
|
||||
' test2 test value 2;',
|
||||
],
|
||||
},
|
||||
{
|
||||
:title => 'should set root',
|
||||
:attr => 'use_default_location',
|
||||
:value => false,
|
||||
:match => ' root /;',
|
||||
},
|
||||
{
|
||||
:title => 'should not set root',
|
||||
:attr => 'use_default_location',
|
||||
:value => true,
|
||||
:notmatch => / root \/;/,
|
||||
},
|
||||
{
|
||||
:title => 'should set proxy_set_header',
|
||||
:attr => 'proxy_set_header',
|
||||
:value => ['header1','header2'],
|
||||
:match => [
|
||||
' proxy_set_header header1;',
|
||||
' proxy_set_header header2;',
|
||||
],
|
||||
},
|
||||
{
|
||||
:title => 'should rewrite to HTTPS',
|
||||
:attr => 'rewrite_to_https',
|
||||
:value => true,
|
||||
:match => [
|
||||
' if ($ssl_protocol = "") {',
|
||||
' return 301 https://$host$request_uri;',
|
||||
],
|
||||
},
|
||||
{
|
||||
:title => 'should not rewrite to HTTPS',
|
||||
:attr => 'rewrite_to_https',
|
||||
:value => false,
|
||||
:notmatch => [
|
||||
/if \(\$ssl_protocol = ""\) \{/,
|
||||
/ return 301 https:\/\/\$host\$request_uri;/,
|
||||
],
|
||||
},
|
||||
{
|
||||
:title => 'should set access_log',
|
||||
:attr => 'access_log',
|
||||
:value => '/path/to/access.log',
|
||||
:match => ' access_log /path/to/access.log;',
|
||||
},
|
||||
{
|
||||
:title => 'should set error_log',
|
||||
:attr => 'error_log',
|
||||
:value => '/path/to/error.log',
|
||||
:match => ' error_log /path/to/error.log;',
|
||||
},
|
||||
].each do |param|
|
||||
context "when #{param[:attr]} is #{param[:value]}" do
|
||||
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
|
||||
|
||||
it { should contain_concat__fragment("#{title}-header") }
|
||||
it param[:title] do
|
||||
lines = subject.resource('concat::fragment', "#{title}-header").send(:parameters)[:content].split("\n")
|
||||
(lines & Array(param[:match])).should == Array(param[:match])
|
||||
Array(param[:notmatch]).each do |item|
|
||||
should contain_concat__fragment("#{title}-header").without_content(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "vhost_footer template content" do
|
||||
[
|
||||
{
|
||||
:title => 'should contain include directives',
|
||||
:attr => 'include_files',
|
||||
:value => [ '/file1', '/file2' ],
|
||||
:match => [
|
||||
'include /file1;',
|
||||
'include /file2;',
|
||||
],
|
||||
},
|
||||
{
|
||||
:title => 'should contain ordered appended directives',
|
||||
:attr => 'vhost_cfg_append',
|
||||
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3' },
|
||||
:match => [
|
||||
' allow test value 3;',
|
||||
' test1 test value 1;',
|
||||
' test2 test value 2a;',
|
||||
' test2 test value 2b;',
|
||||
],
|
||||
},
|
||||
{
|
||||
:title => 'should contain www to non-www rewrite',
|
||||
:attr => 'rewrite_www_to_non_www',
|
||||
:value => true,
|
||||
:match => [
|
||||
' listen *:80;',
|
||||
' server_name www.rspec.example.com;',
|
||||
' rewrite ^ http://rspec.example.com$uri permanent;',
|
||||
],
|
||||
},
|
||||
{
|
||||
:title => 'should not contain www to non-www rewrite',
|
||||
:attr => 'rewrite_www_to_non_www',
|
||||
:value => false,
|
||||
:notmatch => [
|
||||
/ listen \*:80;/,
|
||||
/ server_name www\.rspec\.example\.com;/,
|
||||
/ rewrite \^ http:\/\/rspec\.example\.com\$uri permanent;/,
|
||||
],
|
||||
},
|
||||
].each do |param|
|
||||
context "when #{param[:attr]} is #{param[:value]}" do
|
||||
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
|
||||
|
||||
it { should contain_concat__fragment("#{title}-footer") }
|
||||
it param[:title] do
|
||||
lines = subject.resource('concat::fragment', "#{title}-footer").send(:parameters)[:content].split("\n")
|
||||
(lines & Array(param[:match])).should == Array(param[:match])
|
||||
Array(param[:notmatch]).each do |item|
|
||||
should contain_concat__fragment("#{title}-footer").without_content(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "vhost_ssl_header template content" do
|
||||
[
|
||||
{
|
||||
:title => 'should set the IPv4 listen IP',
|
||||
:attr => 'listen_ip',
|
||||
:value => '127.0.0.1',
|
||||
:match => ' listen 127.0.0.1:443 ssl;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv4 SSL listen port',
|
||||
:attr => 'ssl_port',
|
||||
:value => 45,
|
||||
:match => ' listen *:45 ssl;',
|
||||
},
|
||||
{
|
||||
:title => 'should set SPDY',
|
||||
:attr => 'spdy',
|
||||
:value => 'on',
|
||||
:match => ' listen *:443 ssl spdy;',
|
||||
},
|
||||
{
|
||||
:title => 'should not set SPDY',
|
||||
:attr => 'spdy',
|
||||
:value => 'off',
|
||||
:match => ' listen *:443 ssl;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv4 listen options',
|
||||
:attr => 'listen_options',
|
||||
:value => 'default',
|
||||
:match => ' listen *:443 ssl default;',
|
||||
},
|
||||
{
|
||||
:title => 'should enable IPv6',
|
||||
:attr => 'ipv6_enable',
|
||||
:value => true,
|
||||
:match => ' listen [::]:443 ssl default ipv6only=on;',
|
||||
},
|
||||
{
|
||||
:title => 'should disable IPv6',
|
||||
:attr => 'ipv6_enable',
|
||||
:value => false,
|
||||
:notmatch => / listen \[::\]:443 ssl default ipv6only=on;/,
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv6 listen IP',
|
||||
:attr => 'ipv6_listen_ip',
|
||||
:value => '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
|
||||
:match => ' listen [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:443 ssl default ipv6only=on;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv6 listen port',
|
||||
:attr => 'ssl_port',
|
||||
:value => 45,
|
||||
:match => ' listen [::]:45 ssl default ipv6only=on;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the IPv6 listen options',
|
||||
:attr => 'ipv6_listen_options',
|
||||
:value => 'spdy default',
|
||||
:match => ' listen [::]:443 ssl spdy default;',
|
||||
},
|
||||
{
|
||||
:title => 'should set servername(s)',
|
||||
:attr => 'server_name',
|
||||
:value => ['name1','name2'],
|
||||
:match => ' server_name name1 name2;',
|
||||
},
|
||||
{
|
||||
:title => 'should rewrite www servername to non-www',
|
||||
:attr => 'rewrite_www_to_non_www',
|
||||
:value => true,
|
||||
:match => ' server_name rspec.example.com;',
|
||||
},
|
||||
{
|
||||
:title => 'should not rewrite www servername to non-www',
|
||||
:attr => 'rewrite_www_to_non_www',
|
||||
:value => false,
|
||||
:match => ' server_name www.rspec.example.com;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the SSL cache',
|
||||
:attr => 'ssl_cache',
|
||||
:value => 'shared:SSL:1m',
|
||||
:match => ' ssl_session_cache shared:SSL:1m;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the SSL protocols',
|
||||
:attr => 'ssl_protocols',
|
||||
:value => 'SSLv3',
|
||||
:match => ' ssl_protocols SSLv3;',
|
||||
},
|
||||
{
|
||||
:title => 'should set the SSL ciphers',
|
||||
:attr => 'ssl_ciphers',
|
||||
:value => 'HIGH',
|
||||
:match => ' ssl_ciphers HIGH;',
|
||||
},
|
||||
{
|
||||
:title => 'should set auth_basic',
|
||||
:attr => 'auth_basic',
|
||||
:value => 'value',
|
||||
:match => ' auth_basic "value";',
|
||||
},
|
||||
{
|
||||
:title => 'should set auth_basic_user_file',
|
||||
:attr => 'auth_basic_user_file',
|
||||
:value => 'value',
|
||||
:match => ' auth_basic_user_file "value";',
|
||||
},
|
||||
{
|
||||
:title => 'should set access_log',
|
||||
:attr => 'access_log',
|
||||
:value => '/path/to/access.log',
|
||||
:match => ' access_log /path/to/access.log;',
|
||||
},
|
||||
{
|
||||
:title => 'should set error_log',
|
||||
:attr => 'error_log',
|
||||
:value => '/path/to/error.log',
|
||||
:match => ' error_log /path/to/error.log;',
|
||||
},
|
||||
{
|
||||
:title => 'should contain ordered prepend directives',
|
||||
:attr => 'vhost_cfg_prepend',
|
||||
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3' },
|
||||
:match => [
|
||||
' allow test value 3;',
|
||||
' test1 test value 1;',
|
||||
' test2 test value 2a;',
|
||||
' test2 test value 2b;',
|
||||
]
|
||||
},
|
||||
{
|
||||
:title => 'should contain ordered ssl prepend directives',
|
||||
:attr => 'vhost_cfg_ssl_prepend',
|
||||
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3' },
|
||||
:match => [
|
||||
' allow test value 3;',
|
||||
' test1 test value 1;',
|
||||
' test2 test value 2a;',
|
||||
' test2 test value 2b;',
|
||||
]
|
||||
},
|
||||
{
|
||||
:title => 'should set root',
|
||||
:attr => 'use_default_location',
|
||||
:value => false,
|
||||
:match => ' root /;',
|
||||
},
|
||||
{
|
||||
:title => 'should not set root',
|
||||
:attr => 'use_default_location',
|
||||
:value => true,
|
||||
:notmatch => / root \/;/,
|
||||
},
|
||||
].each do |param|
|
||||
context "when #{param[:attr]} is #{param[:value]}" do
|
||||
let :params do default_params.merge({
|
||||
param[:attr].to_sym => param[:value],
|
||||
:ssl => true,
|
||||
:ssl_key => 'dummy.key',
|
||||
:ssl_cert => 'dummy.crt',
|
||||
}) end
|
||||
it { should contain_concat__fragment("#{title}-ssl-header") }
|
||||
it param[:title] do
|
||||
lines = subject.resource('concat::fragment', "#{title}-ssl-header").send(:parameters)[:content].split("\n")
|
||||
(lines & Array(param[:match])).should == Array(param[:match])
|
||||
Array(param[:notmatch]).each do |item|
|
||||
should contain_concat__fragment("#{title}-ssl-header").without_content(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "vhost_ssl_footer template content" do
|
||||
[
|
||||
{
|
||||
:title => 'should contain include directives',
|
||||
:attr => 'include_files',
|
||||
:value => [ '/file1', '/file2' ],
|
||||
:match => [
|
||||
'include /file1;',
|
||||
'include /file2;',
|
||||
],
|
||||
},
|
||||
{
|
||||
:title => 'should contain ordered appended directives',
|
||||
:attr => 'vhost_cfg_append',
|
||||
:value => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' },
|
||||
:match => [
|
||||
' allow test value 3;',
|
||||
' test1 test value 1;',
|
||||
' test2 test value 2;',
|
||||
]
|
||||
},
|
||||
{
|
||||
:title => 'should contain ordered ssl appended directives',
|
||||
:attr => 'vhost_cfg_ssl_append',
|
||||
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3' },
|
||||
:match => [
|
||||
' allow test value 3;',
|
||||
' test1 test value 1;',
|
||||
' test2 test value 2a;',
|
||||
' test2 test value 2b;',
|
||||
]
|
||||
},
|
||||
{
|
||||
:title => 'should contain www to non-www rewrite',
|
||||
:attr => 'rewrite_www_to_non_www',
|
||||
:value => true,
|
||||
:match => [
|
||||
' listen *:443 ssl;',
|
||||
' server_name www.rspec.example.com;',
|
||||
' rewrite ^ https://rspec.example.com$uri permanent;',
|
||||
],
|
||||
},
|
||||
{
|
||||
:title => 'should not contain www to non-www rewrite',
|
||||
:attr => 'rewrite_www_to_non_www',
|
||||
:value => false,
|
||||
:notmatch => [
|
||||
/ listen \*:443 ssl;/,
|
||||
/ server_name www\.rspec\.example\.com;/,
|
||||
/ rewrite \^ https:\/\/rspec\.example\.com\$uri permanent;/,
|
||||
],
|
||||
},
|
||||
].each do |param|
|
||||
context "when #{param[:attr]} is #{param[:value]}" do
|
||||
let :params do default_params.merge({
|
||||
param[:attr].to_sym => param[:value],
|
||||
:ssl => true,
|
||||
:ssl_key => 'dummy.key',
|
||||
:ssl_cert => 'dummy.crt',
|
||||
}) end
|
||||
|
||||
it { should contain_concat__fragment("#{title}-ssl-footer") }
|
||||
it param[:title] do
|
||||
lines = subject.resource('concat::fragment', "#{title}-ssl-footer").send(:parameters)[:content].split("\n")
|
||||
(lines & Array(param[:match])).should == Array(param[:match])
|
||||
Array(param[:notmatch]).each do |item|
|
||||
should contain_concat__fragment("#{title}-ssl-footer").without_content(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
context 'attribute resources' do
|
||||
context "SSL cert missing" do
|
||||
let(:params) {{ :ssl => true, :ssl_key => 'key' }}
|
||||
|
||||
it { expect { should contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
|
||||
end
|
||||
|
||||
context "SSL key missing" do
|
||||
let(:params) {{ :ssl => true, :ssl_cert => 'cert' }}
|
||||
|
||||
it { expect { should contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error, %r{nginx: SSL certificate/key \(ssl_cert/ssl_cert\) and/or SSL Private must be defined and exist on the target system\(s\)}) }
|
||||
end
|
||||
|
||||
context 'when use_default_location => true' do
|
||||
let :params do default_params.merge({
|
||||
:use_default_location => true,
|
||||
}) end
|
||||
|
||||
it { should contain_nginx__resource__location("#{title}-default") }
|
||||
end
|
||||
|
||||
context 'when use_default_location => false' do
|
||||
let :params do default_params.merge({
|
||||
:use_default_location => false,
|
||||
}) end
|
||||
|
||||
it { should_not contain_nginx__resource__location("#{title}-default") }
|
||||
end
|
||||
|
||||
context 'when location_cfg_prepend => { key => value }' do
|
||||
let :params do default_params.merge({
|
||||
:location_cfg_prepend => { 'key' => 'value' },
|
||||
}) end
|
||||
|
||||
it { should contain_nginx__resource__location("#{title}-default").with_location_cfg_prepend({ 'key' => 'value' }) }
|
||||
end
|
||||
|
||||
context 'when location_cfg_append => { key => value }' do
|
||||
let :params do default_params.merge({
|
||||
:location_cfg_append => { 'key' => 'value' },
|
||||
}) end
|
||||
|
||||
it { should contain_nginx__resource__location("#{title}-default").with_location_cfg_append({ 'key' => 'value' }) }
|
||||
end
|
||||
|
||||
context 'when fastcgi => "localhost:9000"' do
|
||||
let :params do default_params.merge({
|
||||
:fastcgi => 'localhost:9000',
|
||||
}) end
|
||||
|
||||
it { should contain_file('/etc/nginx/fastcgi_params').with_mode('0770') }
|
||||
end
|
||||
|
||||
context 'when listen_port == ssl_port' do
|
||||
let :params do default_params.merge({
|
||||
:listen_port => 80,
|
||||
:ssl_port => 80,
|
||||
}) end
|
||||
|
||||
it { should_not contain_concat__fragment("#{title}-header") }
|
||||
it { should_not contain_concat__fragment("#{title}-footer") }
|
||||
end
|
||||
|
||||
context 'when listen_port != ssl_port' do
|
||||
let :params do default_params.merge({
|
||||
:listen_port => 80,
|
||||
:ssl_port => 443,
|
||||
}) end
|
||||
|
||||
it { should contain_concat__fragment("#{title}-header") }
|
||||
it { should contain_concat__fragment("#{title}-footer") }
|
||||
end
|
||||
|
||||
context 'when ensure => absent' do
|
||||
let :params do default_params.merge({
|
||||
:ensure => 'absent',
|
||||
:ssl => true,
|
||||
:ssl_key => 'dummy.key',
|
||||
:ssl_cert => 'dummy.cert',
|
||||
}) end
|
||||
|
||||
it { should contain_nginx__resource__location("#{title}-default").with_ensure('absent') }
|
||||
it { should contain_file("#{title}.conf symlink").with_ensure('absent') }
|
||||
end
|
||||
|
||||
context 'when ssl => true and ssl_port == listen_port' do
|
||||
let :params do default_params.merge({
|
||||
:ssl => true,
|
||||
:listen_port => 80,
|
||||
:ssl_port => 80,
|
||||
:ssl_key => 'dummy.key',
|
||||
:ssl_cert => 'dummy.cert',
|
||||
}) end
|
||||
|
||||
it { should contain_nginx__resource__location("#{title}-default").with_ssl_only(true) }
|
||||
it { should contain_concat__fragment("#{title}-ssl-header").with_content(%r{access_log[ ]+/var/log/nginx/ssl-www\.rspec\.example\.com\.access\.log}) }
|
||||
it { should contain_concat__fragment("#{title}-ssl-header").with_content(%r{error_log[ ]+/var/log/nginx/ssl-www\.rspec\.example\.com\.error\.log}) }
|
||||
it { should contain_concat__fragment("#{title}-ssl-footer") }
|
||||
it { should contain_file("/etc/nginx/#{title}.crt") }
|
||||
it { should contain_file("/etc/nginx/#{title}.key") }
|
||||
end
|
||||
|
||||
context 'when passenger_cgi_param is set' do
|
||||
let :params do default_params.merge({
|
||||
:passenger_cgi_param => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'test3' => 'test value 3' }
|
||||
}) end
|
||||
|
||||
it { should contain_concat__fragment("#{title}-header").with_content( /passenger_set_cgi_param test1 test value 1;/ ) }
|
||||
it { should contain_concat__fragment("#{title}-header").with_content( /passenger_set_cgi_param test2 test value 2;/ ) }
|
||||
it { should contain_concat__fragment("#{title}-header").with_content( /passenger_set_cgi_param test3 test value 3;/ ) }
|
||||
end
|
||||
|
||||
context 'when passenger_cgi_param is set and ssl => true' do
|
||||
let :params do default_params.merge({
|
||||
:passenger_cgi_param => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'test3' => 'test value 3' },
|
||||
:ssl => true,
|
||||
:ssl_key => 'dummy.key',
|
||||
:ssl_cert => 'dummy.cert',
|
||||
}) end
|
||||
|
||||
it { should contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_set_cgi_param test1 test value 1;/ ) }
|
||||
it { should contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_set_cgi_param test2 test value 2;/ ) }
|
||||
it { should contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_set_cgi_param test3 test value 3;/ ) }
|
||||
end
|
||||
|
||||
context 'when vhost name is sanitized' do
|
||||
let :title do 'www rspec-vhost com' end
|
||||
let :params do default_params end
|
||||
|
||||
it { should contain_concat('/etc/nginx/sites-available/www_rspec-vhost_com.conf') }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,8 @@
|
||||
require 'puppetlabs_spec_helper/module_spec_helper'
|
||||
|
||||
RSpec.configure do |c|
|
||||
c.default_facts = {
|
||||
:kernel => 'Linux',
|
||||
:concat_basedir => '/var/lib/puppet/concat',
|
||||
}
|
||||
end
|
@@ -0,0 +1,64 @@
|
||||
require 'rspec-system/spec_helper'
|
||||
require 'rspec-system-puppet/helpers'
|
||||
require 'rspec-system-serverspec/helpers'
|
||||
include RSpecSystemPuppet::Helpers
|
||||
|
||||
RSpec.configure do |c|
|
||||
# Project root
|
||||
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
||||
|
||||
# Enable colour
|
||||
c.tty = true
|
||||
|
||||
# This is where we 'setup' the nodes before running our tests
|
||||
c.before :suite do
|
||||
# Install puppet
|
||||
puppet_install
|
||||
|
||||
# Install modules and dependencies
|
||||
puppet_module_install(:source => proj_root, :module_name => 'nginx')
|
||||
shell('puppet module install puppetlabs-apt')
|
||||
shell('puppet module install puppetlabs-stdlib')
|
||||
shell('puppet module install puppetlabs-concat')
|
||||
|
||||
# Fake keys.
|
||||
# Valid self-signed SSL key with 10 year expiry.
|
||||
# Required for nginx to start when SSL enabled
|
||||
shell('echo "-----BEGIN PRIVATE KEY-----
|
||||
MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAOPchwRZRF4KmU6E
|
||||
g7C6Pq9zhdLiQt9owdcLZNiZS+UVRQjeDHSy3titzh5YwSoQonlnSqd0g/PJ6kNA
|
||||
O3CNOMVuzAddnAaHzW1J4Rt6sZwOuidtJC4t/hFCgz5NqOMgYOOfratQx00A7ZXK
|
||||
TXMgNG79lDP5L/N06Ox53sOxhy4hAgMBAAECgYEAlfktCKi0fe0d8Hb5slUzMwmn
|
||||
GCECAMeTZbXDH2jucg4ozOhRbHHaiOUEmCa0pLokJiHdGhBvVQMd5Dufo7nflZzE
|
||||
mpZY0lCZE7HSeK6Bcbru/8w3vm3iBQTGK+MCaDtH5nQU7m/3cOXaenOX0ZmsTzRs
|
||||
QE/V84S1fuO8bBPSz20CQQD9d4LxrBByosFxRdHsTb/nnqx/rzLEf4M3MC7uydPv
|
||||
fDDbSRRSYpNxonQJfU3JrOk1WPWoXY30VQCv395s57X7AkEA5iOBT+ME8/PxuUUC
|
||||
ZDjg21tAdkaiCQ5kgeVTmkD1k/gTwreOV2AexWGrrcW/MLaIhpDCpQkw37y5vrYw
|
||||
UyDdkwJAAU+j8sIUF7O10nMtAc7pJjaQ59wtJA0QzbFHHN8YZI285vV60G5IGvdf
|
||||
KElopJlrX2ZFZwiM2m2yIjbDPMb6DwJAbNoiUbzZHOInVTA0316fzGEu7kKeZZYv
|
||||
J9lmX7GV9nUCM7lKVD2ckFOQNlMwCURs8ukJh7H/MfQ8Dt5xoQAMjQJBAOWpK6k6
|
||||
b0fTREZFZRGZBJcSu959YyMzhpSFA+lXkLNTWX8j1/D88H731oMSImoQNWcYx2dH
|
||||
sCwOCDqu1nZ2LJ8=
|
||||
-----END PRIVATE KEY-----" > /tmp/blah.key')
|
||||
shell('echo "-----BEGIN CERTIFICATE-----
|
||||
MIIDRjCCAq+gAwIBAgIJAL9m0V4sHW2tMA0GCSqGSIb3DQEBBQUAMIG7MQswCQYD
|
||||
VQQGEwItLTESMBAGA1UECAwJU29tZVN0YXRlMREwDwYDVQQHDAhTb21lQ2l0eTEZ
|
||||
MBcGA1UECgwQU29tZU9yZ2FuaXphdGlvbjEfMB0GA1UECwwWU29tZU9yZ2FuaXph
|
||||
dGlvbmFsVW5pdDEeMBwGA1UEAwwVbG9jYWxob3N0LmxvY2FsZG9tYWluMSkwJwYJ
|
||||
KoZIhvcNAQkBFhpyb290QGxvY2FsaG9zdC5sb2NhbGRvbWFpbjAeFw0xMzExMzAw
|
||||
NzA3NDlaFw0yMzExMjgwNzA3NDlaMIG7MQswCQYDVQQGEwItLTESMBAGA1UECAwJ
|
||||
U29tZVN0YXRlMREwDwYDVQQHDAhTb21lQ2l0eTEZMBcGA1UECgwQU29tZU9yZ2Fu
|
||||
aXphdGlvbjEfMB0GA1UECwwWU29tZU9yZ2FuaXphdGlvbmFsVW5pdDEeMBwGA1UE
|
||||
AwwVbG9jYWxob3N0LmxvY2FsZG9tYWluMSkwJwYJKoZIhvcNAQkBFhpyb290QGxv
|
||||
Y2FsaG9zdC5sb2NhbGRvbWFpbjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA
|
||||
49yHBFlEXgqZToSDsLo+r3OF0uJC32jB1wtk2JlL5RVFCN4MdLLe2K3OHljBKhCi
|
||||
eWdKp3SD88nqQ0A7cI04xW7MB12cBofNbUnhG3qxnA66J20kLi3+EUKDPk2o4yBg
|
||||
45+tq1DHTQDtlcpNcyA0bv2UM/kv83To7Hnew7GHLiECAwEAAaNQME4wHQYDVR0O
|
||||
BBYEFP5Kkot/7pStLaYPtT+vngE0v6N8MB8GA1UdIwQYMBaAFP5Kkot/7pStLaYP
|
||||
tT+vngE0v6N8MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAwYYQKVRN
|
||||
HaHIWGMBuXApE7t4PNdYWZ5Y56tI+HT59yVoDjc1YSnuzkKlWUPibVYoLpX/ROKr
|
||||
aIZ8kxsBjLvpi9KQTHi7Wl6Sw3ecoYdKy+2P8S5xOIpWjs8XVmOWf7Tq1+9KPv3z
|
||||
HLw/FDCzntkdq3G4em15CdFlO9BTY4HXiHU=
|
||||
-----END CERTIFICATE-----" > /tmp/blah.cert')
|
||||
end
|
||||
end
|
@@ -0,0 +1,33 @@
|
||||
require 'spec_helper_system'
|
||||
|
||||
# Here we put the more basic fundamental tests, ultra obvious stuff.
|
||||
describe "basic tests:" do
|
||||
context 'make sure we have copied the module across' do
|
||||
# No point diagnosing any more if the module wasn't copied properly
|
||||
context shell 'ls /etc/puppet/modules/nginx' do
|
||||
its(:stdout) { should =~ /Modulefile/ }
|
||||
its(:stderr) { should be_empty }
|
||||
its(:exit_code) { should be_zero }
|
||||
end
|
||||
end
|
||||
|
||||
#puppet smoke test
|
||||
context puppet_apply 'notice("foo")' do
|
||||
its(:stdout) { should =~ /foo/ }
|
||||
its(:stderr) { should be_empty }
|
||||
its(:exit_code) { should be_zero }
|
||||
end
|
||||
|
||||
it 'nginx class should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'nginx': }
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
puppet_apply(pp) do |r|
|
||||
[0,2].should include(r.exit_code)
|
||||
r.refresh
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,35 @@
|
||||
require 'spec_helper_system'
|
||||
|
||||
describe "nginx class:" do
|
||||
case node.facts['osfamily']
|
||||
when 'RedHat'
|
||||
package_name = 'nginx'
|
||||
when 'Debian'
|
||||
package_name = 'nginx'
|
||||
when 'Suse'
|
||||
package_name = 'nginx-0.8'
|
||||
end
|
||||
|
||||
context 'should run successfully' do
|
||||
it 'should run successfully' do
|
||||
pp = "class { 'nginx': }"
|
||||
|
||||
puppet_apply(pp) do |r|
|
||||
#r.stderr.should be_empty
|
||||
[0,2].should include r.exit_code
|
||||
r.refresh
|
||||
#r.stderr.should be_empty
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe package(package_name) do
|
||||
it { should be_installed }
|
||||
end
|
||||
|
||||
describe service('nginx') do
|
||||
it { should be_running }
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,42 @@
|
||||
require 'spec_helper_system'
|
||||
|
||||
describe "nginx::resource::mailhost define:" do
|
||||
it 'should run successfully' do
|
||||
|
||||
pp = "
|
||||
class { 'nginx':
|
||||
mail => true,
|
||||
}
|
||||
nginx::resource::vhost { 'www.puppetlabs.com':
|
||||
ensure => present,
|
||||
www_root => '/var/www/www.puppetlabs.com',
|
||||
}
|
||||
nginx::resource::mailhost { 'domain1.example':
|
||||
ensure => present,
|
||||
auth_http => 'localhost/cgi-bin/auth',
|
||||
protocol => 'smtp',
|
||||
listen_port => 587,
|
||||
ssl_port => 465,
|
||||
xclient => 'off',
|
||||
}
|
||||
"
|
||||
|
||||
puppet_apply(pp) do |r|
|
||||
[0,2].should include r.exit_code
|
||||
r.refresh
|
||||
# Not until deprecated variables fixed.
|
||||
#r.stderr.should be_empty
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
|
||||
describe file('/etc/nginx/conf.mail.d/domain1.example.conf') do
|
||||
it { should be_file }
|
||||
it { should contain "auth_http localhost/cgi-bin/auth;" }
|
||||
end
|
||||
|
||||
describe file('/etc/nginx/sites-available/www.puppetlabs.com.conf') do
|
||||
it { should be_file }
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,43 @@
|
||||
require 'spec_helper_system'
|
||||
|
||||
describe "nginx::resource::upstream define:" do
|
||||
it 'should run successfully' do
|
||||
|
||||
pp = "
|
||||
class { 'nginx': }
|
||||
nginx::resource::upstream { 'puppet_rack_app':
|
||||
ensure => present,
|
||||
members => [
|
||||
'localhost:3000',
|
||||
'localhost:3001',
|
||||
'localhost:3002',
|
||||
],
|
||||
}
|
||||
nginx::resource::vhost { 'rack.puppetlabs.com':
|
||||
ensure => present,
|
||||
proxy => 'http://puppet_rack_app',
|
||||
}
|
||||
"
|
||||
|
||||
puppet_apply(pp) do |r|
|
||||
[0,2].should include r.exit_code
|
||||
r.refresh
|
||||
r.stderr.should be_empty
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
|
||||
describe file('/etc/nginx/conf.d/puppet_rack_app-upstream.conf') do
|
||||
it { should be_file }
|
||||
it { should contain "server localhost:3000" }
|
||||
it { should contain "server localhost:3001" }
|
||||
it { should contain "server localhost:3002" }
|
||||
it { should_not contain "server localhost:3003" }
|
||||
end
|
||||
|
||||
describe file('/etc/nginx/sites-available/rack.puppetlabs.com.conf') do
|
||||
it { should be_file }
|
||||
it { should contain "proxy_pass http://puppet_rack_app;" }
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,100 @@
|
||||
require 'spec_helper_system'
|
||||
|
||||
describe "nginx::resource::vhost define:" do
|
||||
context 'new vhost on port 80' do
|
||||
it 'should configure a nginx vhost' do
|
||||
|
||||
pp = "
|
||||
class { 'nginx': }
|
||||
nginx::resource::vhost { 'www.puppetlabs.com':
|
||||
ensure => present,
|
||||
www_root => '/var/www/www.puppetlabs.com',
|
||||
}
|
||||
host { 'www.puppetlabs.com': ip => '127.0.0.1', }
|
||||
file { ['/var/www','/var/www/www.puppetlabs.com']: ensure => directory }
|
||||
file { '/var/www/www.puppetlabs.com/index.html': ensure => file, content => 'Hello from www\n', }
|
||||
"
|
||||
|
||||
puppet_apply(pp) do |r|
|
||||
[0,2].should include r.exit_code
|
||||
r.refresh
|
||||
r.stderr.should be_empty
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
|
||||
describe file('/etc/nginx/sites-available/www.puppetlabs.com.conf') do
|
||||
it { should be_file }
|
||||
it { should contain "www.puppetlabs.com" }
|
||||
end
|
||||
|
||||
describe file('/etc/nginx/sites-enabled/www.puppetlabs.com.conf') do
|
||||
it { should be_linked_to '/etc/nginx/sites-available/www.puppetlabs.com.conf' }
|
||||
end
|
||||
|
||||
describe service('nginx') do
|
||||
it { should be_running }
|
||||
end
|
||||
|
||||
it 'should answer to www.puppetlabs.com' do
|
||||
shell("/usr/bin/curl http://www.puppetlabs.com:80") do |r|
|
||||
r.stdout.should == "Hello from www\n"
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'should run successfully with ssl' do
|
||||
it 'should configure a nginx SSL vhost' do
|
||||
|
||||
pp = "
|
||||
class { 'nginx': }
|
||||
nginx::resource::vhost { 'www.puppetlabs.com':
|
||||
ensure => present,
|
||||
ssl => true,
|
||||
ssl_cert => '/tmp/blah.cert',
|
||||
ssl_key => '/tmp/blah.key',
|
||||
www_root => '/var/www/www.puppetlabs.com',
|
||||
}
|
||||
host { 'www.puppetlabs.com': ip => '127.0.0.1', }
|
||||
file { ['/var/www','/var/www/www.puppetlabs.com']: ensure => directory }
|
||||
file { '/var/www/www.puppetlabs.com/index.html': ensure => file, content => 'Hello from www\n', }
|
||||
"
|
||||
|
||||
puppet_apply(pp) do |r|
|
||||
[0,2].should include r.exit_code
|
||||
r.refresh
|
||||
r.stderr.should be_empty
|
||||
r.exit_code.should be_zero
|
||||
end
|
||||
end
|
||||
|
||||
describe file('/etc/nginx/sites-available/www.puppetlabs.com.conf') do
|
||||
it { should be_file }
|
||||
it { should contain "ssl on;" }
|
||||
end
|
||||
|
||||
describe file('/etc/nginx/sites-enabled/www.puppetlabs.com.conf') do
|
||||
it { should be_linked_to '/etc/nginx/sites-available/www.puppetlabs.com.conf' }
|
||||
end
|
||||
|
||||
describe service('nginx') do
|
||||
it { should be_running }
|
||||
end
|
||||
|
||||
it 'should answer to http://www.puppetlabs.com' do
|
||||
shell("/usr/bin/curl http://www.puppetlabs.com:80") do |r|
|
||||
r.stdout.should == "Hello from www\n"
|
||||
r.exit_code.should == 0
|
||||
end
|
||||
end
|
||||
|
||||
it 'should answer to https://www.puppetlabs.com' do
|
||||
# use --insecure because it's a self-signed cert
|
||||
shell("/usr/bin/curl --insecure https://www.puppetlabs.com:443") do |r|
|
||||
r.stdout.should == "Hello from www\n"
|
||||
r.exit_code.should == 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user