Browse Source

test(inspec): more tests on nginx config

tags/v0.55.0
Eric Veiras Galisson 5 years ago
parent
commit
7e737c1863
2 changed files with 77 additions and 0 deletions
  1. +46
    -0
      test/integration/default/controls/config.rb
  2. +31
    -0
      test/salt/default/pillar/nginx.sls

+ 46
- 0
test/integration/default/controls/config.rb View File

# Set defaults, use debian as base

server_available = '/etc/nginx/sites-available'
server_enabled = '/etc/nginx/sites-enabled'

# Override by OS
case os[:name]
when 'redhat', 'centos', 'fedora'
server_available = '/etc/nginx/conf.d'
server_enabled = '/etc/nginx/conf.d'
end

control 'Nginx configuration' do control 'Nginx configuration' do
title 'should match desired lines' title 'should match desired lines'


# main configuration
describe file('/etc/nginx/nginx.conf') do describe file('/etc/nginx/nginx.conf') do
it { should be_file } it { should be_file }
it { should be_owned_by 'root' } it { should be_owned_by 'root' }
it { should be_grouped_into 'root' } it { should be_grouped_into 'root' }
its('mode') { should cmp '0644' } its('mode') { should cmp '0644' }
end end

# snippets configuration
describe file('/etc/nginx/snippets/letsencrypt.conf') do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its('mode') { should cmp '0644' }
its('content') { should include 'location ^~ /.well-known/acme-challenge/ {' }
its('content') { should include 'proxy_pass http://localhost:9999;' }
its('content') { should include '{' }
end

# sites configuration
[server_available, server_enabled].each do |dir|

describe file ("#{dir}/default") do
it { should_not exist }
end

describe file ("#{dir}/mysite") do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its('mode') { should cmp '0644' }
its('content') { should include 'server_name localhost;' }
its('content') { should include 'listen 80 default_server;' }
its('content') { should include 'index index.html index.htm;' }
its('content') { should include 'location ~ .htm {' }
its('content') { should include 'try_files $uri $uri/ =404;' }
its('content') { should include 'include snippets/letsencrypt.conf;' }
end

end
end end

+ 31
- 0
test/salt/default/pillar/nginx.sls View File


# Simple pillar setup
# - snippet letsencrypt
# - remove 'default' site
# - create 'mysite' site

nginx:
ng:
snippets:
letsencrypt:
- location ^~ /.well-known/acme-challenge/:
- proxy_pass: http://localhost:9999
servers:
managed:
default:
deleted: True
enabled: False
config: {}

mysite:
enabled: True
config:
- server:
- server_name: localhost
- listen:
- '80 default_server'
- index: 'index.html index.htm'
- location ~ .htm:
- try_files: '$uri $uri/ =404'
- include: 'snippets/letsencrypt.conf'


Loading…
Cancel
Save