Skip to content

Commit

Permalink
Format test to use inspec profiles
Browse files Browse the repository at this point in the history
This allows us to inherit common controls

Signed-off-by: Dan Webb <dan.webb@damacus.io>
  • Loading branch information
damacus committed Jan 31, 2024
1 parent 896190b commit c40eba8
Show file tree
Hide file tree
Showing 42 changed files with 229 additions and 192 deletions.
10 changes: 4 additions & 6 deletions test/cookbooks/test/recipes/source_openssl.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
apt_update
# Remove old OpenSSL so we don't conflict
package 'openssl' do
action :remove
end

package %w(build-essential zlib1g-dev) if platform_family?('debian')

Expand All @@ -11,11 +14,6 @@
end
end

package 'openssl' do
action :remove
end


openssl_version = '3.2.1'

# download openssl
Expand Down
13 changes: 13 additions & 0 deletions test/integration/common/controls/common_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
describe directory '/etc/haproxy' do
it { should exist }
end

describe file('/etc/haproxy/haproxy.cfg') do
it { should exist }
it { should be_owned_by 'haproxy' }
it { should be_grouped_into 'haproxy' }
end

describe service('haproxy') do
it { should be_running }
end
7 changes: 7 additions & 0 deletions test/integration/common/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: haproxy-common
title: HAProxy Common Suite
summary: HAProxy common tests
supports:
- os-family: linux
- os-family: bsd
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
include_controls 'haproxy-common'

describe package('haproxy') do
it { should be_installed }
end

describe directory '/etc/haproxy' do
it { should exist }
end

# cfg_content = [
# 'global',
# ' user haproxy',
Expand Down Expand Up @@ -82,13 +80,6 @@
# ' server tile1 10\.0\.0\.10:80 check weight 1 maxconn 100',
# ]

describe file('/etc/haproxy/haproxy.cfg') do
it { should exist }
it { should be_owned_by 'haproxy' }
it { should be_grouped_into 'haproxy' }
# its('content') { should match(/#{cfg_content.join('\n')}/) }
end

describe service('haproxy') do
it { should be_running }
end
# describe file('/etc/haproxy/haproxy.cfg') do
# its('content') { should match(/#{cfg_content.join('\n')}/) }
# end
10 changes: 10 additions & 0 deletions test/integration/config_2/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: haproxy-config-2
title: HAProxy Config 2 Suite
summary: HAProxy tests using example configuration
supports:
- os-family: linux
- os-family: bsd
depends:
- name: haproxy-common
path: test/integration/common
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
title ''
include_controls 'haproxy-common'

describe package('haproxy') do
it { should be_installed }
end

describe directory '/etc/haproxy' do
it { should exist }
end

cfg_content = [
'global',
' user haproxy',
Expand Down Expand Up @@ -66,9 +62,5 @@
]

describe file('/etc/haproxy/haproxy.cfg') do
it { should exist }
it { should be_owned_by 'haproxy' }
it { should be_grouped_into 'haproxy' }

its('content') { should match(/#{cfg_content.join('\n')}/) }
end
10 changes: 10 additions & 0 deletions test/integration/config_3/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: haproxy-config-3
title: HAProxy Config 3 Suite
summary: HAProxy tests using example configuration
supports:
- os-family: linux
- os-family: bsd
depends:
- name: haproxy-common
path: test/integration/common
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
include_controls 'haproxy-common'

describe package('haproxy') do
it { should be_installed }
end

describe directory '/etc/haproxy' do
it { should exist }
end

describe file('/etc/haproxy/haproxy.cfg') do
it { should exist }
it { should be_owned_by 'haproxy' }
it { should be_grouped_into 'haproxy' }
its('content') { should_not match(/^ daemon$/) }
# Defaults
defaults = [
Expand Down Expand Up @@ -78,6 +73,3 @@
its('content') { should match(/#{listen_admin.join('\n')}/) }
end

describe service('haproxy') do
it { should be_running }
end
10 changes: 10 additions & 0 deletions test/integration/config_acl/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: haproxy-config-acl
title: HAProxy Config ACL Suite
summary: HAProxy tests using example configuration
supports:
- os-family: linux
- os-family: bsd
depends:
- name: haproxy-common
path: test/integration/common
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
title 'Frontend & Backend should be configurable'

include_controls 'haproxy-common'

describe package('haproxy') do
it { should be_installed }
end

describe directory '/etc/haproxy' do
it { should exist }
end

cfg_content = [
'global',
' user haproxy',
Expand Down Expand Up @@ -67,12 +65,6 @@
]

describe file('/etc/haproxy/haproxy.cfg') do
it { should exist }
it { should be_owned_by 'haproxy' }
it { should be_grouped_into 'haproxy' }
its('content') { should match(/#{cfg_content.join('\n')}/) }
end

describe service('haproxy') do
it { should be_running }
end
10 changes: 10 additions & 0 deletions test/integration/config_array/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: haproxy-config-array
title: HAProxy Config Array Suite
summary: HAProxy tests using example configuration
supports:
- os-family: linux
- os-family: bsd
depends:
- name: haproxy-common
path: test/integration/common
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
title 'Frontend & Backend should be configurable'

include_controls 'haproxy-common'

describe package('haproxy') do
it { should be_installed }
end

describe directory '/etc/haproxy' do
it { should exist }
end

cfg_content = [
'global',
' user haproxy',
Expand Down Expand Up @@ -48,12 +46,5 @@
]

describe file('/etc/haproxy/haproxy.cfg') do
it { should exist }
it { should be_owned_by 'haproxy' }
it { should be_grouped_into 'haproxy' }
its('content') { should match(/#{cfg_content.join('\n')}/) }
end

describe service('haproxy') do
it { should be_running }
end
10 changes: 10 additions & 0 deletions test/integration/config_backend_search/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: haproxy-config-backend-search
title: HAProxy Config Backend Search Suite
summary: HAProxy tests using example configuration
supports:
- os-family: linux
- os-family: bsd
depends:
- name: haproxy-common
path: test/integration/common
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

describe directory '/etc/haproxy' do
it { should exist }
end
include_controls 'haproxy-common'

cfg_content = [
'global',
Expand All @@ -19,13 +16,5 @@
]

describe file('/etc/haproxy/haproxy.cfg') do
it { should exist }
it { should be_owned_by 'haproxy' }
it { should be_grouped_into 'haproxy' }

its('content') { should match(/#{cfg_content.join('\n')}/) }
end

describe service('haproxy') do
it { should be_running }
end
10 changes: 10 additions & 0 deletions test/integration/config_custom_template/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: haproxy-config-custom-template
title: HAProxy Config Custom Template Suite
summary: HAProxy tests using example configuration
supports:
- os-family: linux
- os-family: bsd
depends:
- name: haproxy-common
path: test/integration/common
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
title 'FastCGI should be configurable'

describe directory '/etc/haproxy' do
it { should exist }
end
include_controls 'haproxy-common'

cfg_content = [
'fcgi-app php-fpm',
Expand Down Expand Up @@ -32,12 +30,5 @@
]

describe file('/etc/haproxy/haproxy.cfg') do
it { should exist }
it { should be_owned_by 'haproxy' }
it { should be_grouped_into 'haproxy' }
its('content') { should match(/#{cfg_content.join('\n')}/) }
end

describe service('haproxy') do
it { should be_running }
end
10 changes: 10 additions & 0 deletions test/integration/config_fastcgi/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: haproxy-config-fast-csgi
title: HAProxy Config FastCGI Suite
summary: HAProxy tests using example configuration
supports:
- os-family: linux
- os-family: bsd
depends:
- name: haproxy-common
path: test/integration/common
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

describe directory '/etc/haproxy' do
it { should exist }
end
include_controls 'haproxy-common'

cfg_content = [
'global',
Expand Down Expand Up @@ -37,9 +34,5 @@
]

describe file('/etc/haproxy/haproxy.cfg') do
it { should exist }
it { should be_owned_by 'haproxy' }
it { should be_grouped_into 'haproxy' }

its('content') { should match(/#{cfg_content.join('\n')}/) }
end
10 changes: 10 additions & 0 deletions test/integration/config_resolver/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: haproxy-config-resolver
title: HAProxy Config Resolver Suite
summary: HAProxy tests using example configuration
supports:
- os-family: linux
- os-family: bsd
depends:
- name: haproxy-common
path: test/integration/common
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
it { should be_installed }
end

describe directory '/etc/haproxy' do
it { should exist }
end

cfg_content = [
'global',
' user haproxy',
Expand Down Expand Up @@ -55,12 +51,5 @@
]

describe file('/etc/haproxy/haproxy.cfg') do
it { should exist }
it { should be_owned_by 'haproxy' }
it { should be_grouped_into 'haproxy' }
its('content') { should match(/#{cfg_content.join('\n')}/) }
end

describe service('haproxy') do
it { should be_running }
end
10 changes: 10 additions & 0 deletions test/integration/config_ssl_redirect/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: haproxy-config-ssl-redirect
title: HAProxy Config SSL Redirect Suite
summary: HAProxy tests using example configuration
supports:
- os-family: linux
- os-family: bsd
depends:
- name: haproxy-common
path: test/integration/common
5 changes: 5 additions & 0 deletions test/integration/package/controls/package_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe file '/etc/haproxy/haproxy.cfg' do
its(:mode) { should cmp '0640' }
end

include_controls 'common_spec'
10 changes: 10 additions & 0 deletions test/integration/package/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: haproxy-package
title: HAProxy Package Suite
summary: HAProxy tests using example configuration
supports:
- os-family: linux
- os-family: bsd
depends:
- name: haproxy-common
path: test/integration/common
Loading

0 comments on commit c40eba8

Please sign in to comment.