Skip to content

Commit 7e737c1

Browse files
daksmyii
authored andcommitted
test(inspec): more tests on nginx config
1 parent 072a113 commit 7e737c1

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,56 @@
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+
113
control 'Nginx configuration' do
214
title 'should match desired lines'
315

16+
# main configuration
417
describe file('/etc/nginx/nginx.conf') do
518
it { should be_file }
619
it { should be_owned_by 'root' }
720
it { should be_grouped_into 'root' }
821
its('mode') { should cmp '0644' }
922
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
1056
end

test/salt/default/pillar/nginx.sls

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
# Simple pillar setup
3+
# - snippet letsencrypt
4+
# - remove 'default' site
5+
# - create 'mysite' site
6+
7+
nginx:
8+
ng:
9+
snippets:
10+
letsencrypt:
11+
- location ^~ /.well-known/acme-challenge/:
12+
- proxy_pass: http://localhost:9999
13+
servers:
14+
managed:
15+
default:
16+
deleted: True
17+
enabled: False
18+
config: {}
19+
20+
mysite:
21+
enabled: True
22+
config:
23+
- server:
24+
- server_name: localhost
25+
- listen:
26+
- '80 default_server'
27+
- index: 'index.html index.htm'
28+
- location ~ .htm:
29+
- try_files: '$uri $uri/ =404'
30+
- include: 'snippets/letsencrypt.conf'
31+

0 commit comments

Comments
 (0)