nginx_vhost_spec.rb 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. require 'spec_helper_acceptance'
  2. describe "nginx::resource::vhost define:" do
  3. context 'new vhost on port 80' do
  4. it 'should configure a nginx vhost' do
  5. pp = "
  6. class { 'nginx': }
  7. nginx::resource::vhost { 'www.puppetlabs.com':
  8. ensure => present,
  9. www_root => '/var/www/www.puppetlabs.com',
  10. }
  11. host { 'www.puppetlabs.com': ip => '127.0.0.1', }
  12. file { ['/var/www','/var/www/www.puppetlabs.com']: ensure => directory }
  13. file { '/var/www/www.puppetlabs.com/index.html': ensure => file, content => 'Hello from www\n', }
  14. "
  15. apply_manifest(pp, :catch_failures => true)
  16. end
  17. describe file('/etc/nginx/sites-available/www.puppetlabs.com.conf') do
  18. it { is_expected.to be_file }
  19. it { is_expected.to contain "www.puppetlabs.com" }
  20. end
  21. describe file('/etc/nginx/sites-enabled/www.puppetlabs.com.conf') do
  22. it { is_expected.to be_linked_to '/etc/nginx/sites-available/www.puppetlabs.com.conf' }
  23. end
  24. describe service('nginx') do
  25. it { is_expected.to be_running }
  26. end
  27. describe port(80) do
  28. it { is_expected.to be_listening }
  29. end
  30. it 'should answer to www.puppetlabs.com' do
  31. shell("/usr/bin/curl http://www.puppetlabs.com:80") do |r|
  32. expect(r.stdout).to eq("Hello from www\n")
  33. expect(r.exit_code).to be_zero
  34. end
  35. end
  36. end
  37. context 'should run successfully with ssl' do
  38. it 'should configure a nginx SSL vhost' do
  39. pp = "
  40. class { 'nginx': }
  41. nginx::resource::vhost { 'www.puppetlabs.com':
  42. ensure => present,
  43. ssl => true,
  44. ssl_cert => '/tmp/blah.cert',
  45. ssl_key => '/tmp/blah.key',
  46. www_root => '/var/www/www.puppetlabs.com',
  47. }
  48. host { 'www.puppetlabs.com': ip => '127.0.0.1', }
  49. file { ['/var/www','/var/www/www.puppetlabs.com']: ensure => directory }
  50. file { '/var/www/www.puppetlabs.com/index.html': ensure => file, content => 'Hello from www\n', }
  51. "
  52. apply_manifest(pp, :catch_failures => true)
  53. end
  54. describe file('/etc/nginx/sites-available/www.puppetlabs.com.conf') do
  55. it { is_expected.to be_file }
  56. it { is_expected.to contain "ssl on;" }
  57. end
  58. describe file('/etc/nginx/sites-enabled/www.puppetlabs.com.conf') do
  59. it { is_expected.to be_linked_to '/etc/nginx/sites-available/www.puppetlabs.com.conf' }
  60. end
  61. describe service('nginx') do
  62. it { is_expected.to be_running }
  63. end
  64. describe port(443) do
  65. it { is_expected.to be_listening }
  66. end
  67. it 'should answer to http://www.puppetlabs.com' do
  68. shell("/usr/bin/curl http://www.puppetlabs.com:80") do |r|
  69. expect(r.stdout).to eq("Hello from www\n")
  70. expect(r.exit_code).to eq(0)
  71. end
  72. end
  73. it 'should answer to https://www.puppetlabs.com' do
  74. # use --insecure because it's a self-signed cert
  75. shell("/usr/bin/curl --insecure https://www.puppetlabs.com:443") do |r|
  76. expect(r.stdout).to eq("Hello from www\n")
  77. expect(r.exit_code).to eq(0)
  78. end
  79. end
  80. end
  81. end