2015-04-06 04:53:52 +02:00
|
|
|
require 'spec_helper_acceptance'
|
2013-09-04 21:11:36 +02:00
|
|
|
|
|
|
|
describe "nginx::resource::vhost define:" do
|
2013-12-01 01:08:28 +01:00
|
|
|
context 'new vhost on port 80' do
|
|
|
|
it 'should configure a nginx vhost' do
|
2013-09-04 21:11:36 +02:00
|
|
|
|
2013-12-01 01:08:28 +01:00
|
|
|
pp = "
|
|
|
|
class { 'nginx': }
|
|
|
|
nginx::resource::vhost { 'www.puppetlabs.com':
|
|
|
|
ensure => present,
|
|
|
|
www_root => '/var/www/www.puppetlabs.com',
|
|
|
|
}
|
2013-12-01 01:07:37 +01:00
|
|
|
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', }
|
2013-12-01 01:08:28 +01:00
|
|
|
"
|
2013-09-04 21:11:36 +02:00
|
|
|
|
2015-04-06 04:53:52 +02:00
|
|
|
apply_manifest(pp, :catch_failures => true)
|
2013-09-04 21:11:36 +02:00
|
|
|
end
|
2013-12-01 01:07:37 +01:00
|
|
|
|
2013-12-01 01:51:31 +01:00
|
|
|
describe file('/etc/nginx/sites-available/www.puppetlabs.com.conf') do
|
2015-04-07 01:43:50 +02:00
|
|
|
it { is_expected.to be_file }
|
|
|
|
it { is_expected.to contain "www.puppetlabs.com" }
|
2013-12-01 01:51:31 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe file('/etc/nginx/sites-enabled/www.puppetlabs.com.conf') do
|
2015-04-07 01:43:50 +02:00
|
|
|
it { is_expected.to be_linked_to '/etc/nginx/sites-available/www.puppetlabs.com.conf' }
|
2013-12-01 01:51:31 +01:00
|
|
|
end
|
|
|
|
|
2013-12-01 01:07:37 +01:00
|
|
|
describe service('nginx') do
|
2015-04-07 01:43:50 +02:00
|
|
|
it { is_expected.to be_running }
|
2013-12-01 01:07:37 +01:00
|
|
|
end
|
2015-04-09 16:44:07 +02:00
|
|
|
|
|
|
|
describe port(80) do
|
|
|
|
it { is_expected.to be_listening }
|
|
|
|
end
|
2013-12-01 01:07:37 +01:00
|
|
|
|
|
|
|
it 'should answer to www.puppetlabs.com' do
|
|
|
|
shell("/usr/bin/curl http://www.puppetlabs.com:80") do |r|
|
2015-04-07 01:43:50 +02:00
|
|
|
expect(r.stdout).to eq("Hello from www\n")
|
|
|
|
expect(r.exit_code).to be_zero
|
2013-12-01 01:07:37 +01:00
|
|
|
end
|
|
|
|
end
|
2013-09-04 21:11:36 +02:00
|
|
|
end
|
|
|
|
|
2013-12-01 01:07:37 +01:00
|
|
|
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', }
|
|
|
|
"
|
|
|
|
|
2015-04-06 04:53:52 +02:00
|
|
|
apply_manifest(pp, :catch_failures => true)
|
2013-12-01 01:07:37 +01:00
|
|
|
end
|
|
|
|
|
2013-12-01 01:51:31 +01:00
|
|
|
describe file('/etc/nginx/sites-available/www.puppetlabs.com.conf') do
|
2015-04-07 01:43:50 +02:00
|
|
|
it { is_expected.to be_file }
|
|
|
|
it { is_expected.to contain "ssl on;" }
|
2013-12-01 01:51:31 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe file('/etc/nginx/sites-enabled/www.puppetlabs.com.conf') do
|
2015-04-07 01:43:50 +02:00
|
|
|
it { is_expected.to be_linked_to '/etc/nginx/sites-available/www.puppetlabs.com.conf' }
|
2013-12-01 01:51:31 +01:00
|
|
|
end
|
|
|
|
|
2013-12-01 01:07:37 +01:00
|
|
|
describe service('nginx') do
|
2015-04-07 01:43:50 +02:00
|
|
|
it { is_expected.to be_running }
|
2013-12-01 01:07:37 +01:00
|
|
|
end
|
|
|
|
|
2015-04-09 16:44:07 +02:00
|
|
|
describe port(443) do
|
|
|
|
it { is_expected.to be_listening }
|
|
|
|
end
|
|
|
|
|
2013-12-01 01:07:37 +01:00
|
|
|
it 'should answer to http://www.puppetlabs.com' do
|
|
|
|
shell("/usr/bin/curl http://www.puppetlabs.com:80") do |r|
|
2015-04-07 01:43:50 +02:00
|
|
|
expect(r.stdout).to eq("Hello from www\n")
|
|
|
|
expect(r.exit_code).to eq(0)
|
2013-12-01 01:07:37 +01:00
|
|
|
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|
|
2015-04-07 01:43:50 +02:00
|
|
|
expect(r.stdout).to eq("Hello from www\n")
|
|
|
|
expect(r.exit_code).to eq(0)
|
2013-12-01 01:07:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-09-04 21:11:36 +02:00
|
|
|
end
|