nginx_vhost_spec.rb 3.0 KB

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