Saltstack Official Nginx Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.0KB

  1. # frozen_string_literal: true
  2. # Set defaults, use debian as base
  3. # Override by platform family
  4. server_available, server_enabled =
  5. case platform[:family]
  6. when 'redhat', 'fedora'
  7. %w[/etc/nginx/conf.d /etc/nginx/conf.d]
  8. when 'suse'
  9. %w[/etc/nginx/vhosts.d /etc/nginx/vhosts.d]
  10. when 'bsd'
  11. %w[/usr/local/etc/nginx/sites-available /usr/local/etc/nginx/sites-enabled]
  12. else
  13. %w[/etc/nginx/sites-available /etc/nginx/sites-enabled]
  14. end
  15. nginx_conf, snippets_letsencrypt_conf, file_owner, file_group =
  16. case platform[:family]
  17. when 'bsd'
  18. %w[/usr/local/etc/nginx/nginx.conf /usr/local/etc/nginx/snippets/letsencrypt.conf
  19. root wheel]
  20. else
  21. %w[/etc/nginx/nginx.conf /etc/nginx/snippets/letsencrypt.conf root root]
  22. end
  23. control 'Nginx configuration' do
  24. title 'should match desired lines'
  25. # main configuration
  26. describe file(nginx_conf) do
  27. it { should be_file }
  28. it { should be_owned_by file_owner }
  29. it { should be_grouped_into file_group }
  30. its('mode') { should cmp '0644' }
  31. its('content') do
  32. # rubocop:disable Metrics/LineLength
  33. should include %( log_format main '$remote_addr - $remote_user [$time_local] $status '
  34. '"$request" $body_bytes_sent "$http_referer" '
  35. '"$http_user_agent" "$http_x_forwarded_for"';)
  36. # rubocop:enable Metrics/LineLength
  37. end
  38. end
  39. # snippets configuration
  40. describe file(snippets_letsencrypt_conf) do
  41. it { should be_file }
  42. it { should be_owned_by file_owner }
  43. it { should be_grouped_into file_group }
  44. its('mode') { should cmp '0644' }
  45. its('content') { should include 'location ^~ /.well-known/acme-challenge/ {' }
  46. its('content') { should include 'proxy_pass http://localhost:9999;' }
  47. its('content') { should include '{' }
  48. end
  49. # sites configuration
  50. [server_available, server_enabled].each do |dir|
  51. describe file "#{dir}/default" do
  52. it { should_not exist }
  53. end
  54. describe file "#{dir}/mysite" do
  55. it { should be_file }
  56. it { should be_owned_by file_owner }
  57. it { should be_grouped_into file_group }
  58. its('mode') { should cmp '0644' }
  59. its('content') { should include 'server_name localhost;' }
  60. its('content') { should include 'listen 80 default_server;' }
  61. its('content') { should include 'index index.html index.htm;' }
  62. its('content') { should include 'location ~ .htm {' }
  63. its('content') { should include 'try_files $uri $uri/ =404;' }
  64. its('content') { should include 'include snippets/letsencrypt.conf;' }
  65. end
  66. describe file "#{dir}/mysite_with_require" do
  67. it { should be_file }
  68. it { should be_owned_by file_owner }
  69. it { should be_grouped_into file_group }
  70. its('mode') { should cmp '0644' }
  71. its('content') { should include 'server_name with-deps;' }
  72. its('content') { should include 'listen 80;' }
  73. its('content') { should include 'index index.html index.htm;' }
  74. its('content') { should include 'location ~ .htm {' }
  75. its('content') { should include 'try_files $uri $uri/ =404;' }
  76. end
  77. end
  78. end