From 7e737c1863a46c0914b869a4c0086e4bad12e95f Mon Sep 17 00:00:00 2001 From: Eric Veiras Galisson Date: Fri, 12 Apr 2019 23:32:53 +0200 Subject: [PATCH] test(inspec): more tests on nginx config --- test/integration/default/controls/config.rb | 46 +++++++++++++++++++++ test/salt/default/pillar/nginx.sls | 31 ++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/test/integration/default/controls/config.rb b/test/integration/default/controls/config.rb index e165fad..a0ca2cb 100644 --- a/test/integration/default/controls/config.rb +++ b/test/integration/default/controls/config.rb @@ -1,10 +1,56 @@ +# 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 title 'should match desired lines' + # main configuration describe file('/etc/nginx/nginx.conf') do it { should be_file } it { should be_owned_by 'root' } it { should be_grouped_into 'root' } its('mode') { should cmp '0644' } 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 diff --git a/test/salt/default/pillar/nginx.sls b/test/salt/default/pillar/nginx.sls index e69de29..feb6581 100644 --- a/test/salt/default/pillar/nginx.sls +++ b/test/salt/default/pillar/nginx.sls @@ -0,0 +1,31 @@ + +# 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' +