|
| 1 | +# Set defaults, use debian as base |
| 2 | + |
| 3 | +server_available = '/etc/nginx/sites-available' |
| 4 | +server_enabled = '/etc/nginx/sites-enabled' |
| 5 | + |
| 6 | +# Override by OS |
| 7 | +case os[:name] |
| 8 | +when 'redhat', 'centos', 'fedora' |
| 9 | + server_available = '/etc/nginx/conf.d' |
| 10 | + server_enabled = '/etc/nginx/conf.d' |
| 11 | +end |
| 12 | + |
1 | 13 | control 'Nginx configuration' do
|
2 | 14 | title 'should match desired lines'
|
3 | 15 |
|
| 16 | + # main configuration |
4 | 17 | describe file('/etc/nginx/nginx.conf') do
|
5 | 18 | it { should be_file }
|
6 | 19 | it { should be_owned_by 'root' }
|
7 | 20 | it { should be_grouped_into 'root' }
|
8 | 21 | its('mode') { should cmp '0644' }
|
9 | 22 | end
|
| 23 | + |
| 24 | + # snippets configuration |
| 25 | + describe file('/etc/nginx/snippets/letsencrypt.conf') do |
| 26 | + it { should be_file } |
| 27 | + it { should be_owned_by 'root' } |
| 28 | + it { should be_grouped_into 'root' } |
| 29 | + its('mode') { should cmp '0644' } |
| 30 | + its('content') { should include 'location ^~ /.well-known/acme-challenge/ {' } |
| 31 | + its('content') { should include 'proxy_pass http://localhost:9999;' } |
| 32 | + its('content') { should include '{' } |
| 33 | + end |
| 34 | + |
| 35 | + # sites configuration |
| 36 | + [server_available, server_enabled].each do |dir| |
| 37 | + |
| 38 | + describe file ("#{dir}/default") do |
| 39 | + it { should_not exist } |
| 40 | + end |
| 41 | + |
| 42 | + describe file ("#{dir}/mysite") do |
| 43 | + it { should be_file } |
| 44 | + it { should be_owned_by 'root' } |
| 45 | + it { should be_grouped_into 'root' } |
| 46 | + its('mode') { should cmp '0644' } |
| 47 | + its('content') { should include 'server_name localhost;' } |
| 48 | + its('content') { should include 'listen 80 default_server;' } |
| 49 | + its('content') { should include 'index index.html index.htm;' } |
| 50 | + its('content') { should include 'location ~ .htm {' } |
| 51 | + its('content') { should include 'try_files $uri $uri/ =404;' } |
| 52 | + its('content') { should include 'include snippets/letsencrypt.conf;' } |
| 53 | + end |
| 54 | + |
| 55 | + end |
10 | 56 | end
|
0 commit comments