nginx_vhost_spec.rb 2.8 KB

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