forked from simp/pupmod-simp-rsyslog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(SIMP-6708) Create and ensure inspec tests work by module (simp#96)
SIMP-6708 #comment simp-rsyslog updated
- Loading branch information
1 parent
6315dff
commit 782fca6
Showing
10 changed files
with
215 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
spec/acceptance/suites/compliance/00_simp_profile_install_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require 'spec_helper_acceptance' | ||
|
||
test_name 'rsyslog STIG enforcement of simp profile' | ||
|
||
describe 'rsyslog STIG enforcement of simp profile' do | ||
|
||
let(:manifest) { | ||
<<-EOS | ||
include 'rsyslog' | ||
EOS | ||
} | ||
|
||
let(:hieradata) { <<-EOF | ||
--- | ||
simp_options::pki: true | ||
simp_options::pki::source: '/etc/pki/simp-testing/pki' | ||
compliance_markup::enforcement: | ||
- disa_stig | ||
EOF | ||
} | ||
|
||
hosts.each do |host| | ||
|
||
let(:hiera_yaml) { <<-EOM | ||
--- | ||
version: 5 | ||
hierarchy: | ||
- name: Common | ||
path: common.yaml | ||
- name: Compliance | ||
lookup_key: compliance_markup::enforcement | ||
defaults: | ||
data_hash: yaml_data | ||
datadir: "#{hiera_datadir(host)}" | ||
EOM | ||
} | ||
|
||
context 'when enforcing the STIG' do | ||
it 'should work with no errors' do | ||
create_remote_file(host, host.puppet['hiera_config'], hiera_yaml) | ||
write_hieradata_to(host, hieradata) | ||
|
||
apply_manifest_on(host, manifest, :catch_failures => true) | ||
end | ||
|
||
it 'should reboot for audit updates' do | ||
host.reboot | ||
|
||
apply_manifest_on(host, manifest, :catch_failures => true) | ||
end | ||
|
||
it 'should be idempotent' do | ||
apply_manifest_on(host, manifest, :catch_changes => true) | ||
end | ||
end | ||
end | ||
end |
65 changes: 65 additions & 0 deletions
65
spec/acceptance/suites/compliance/01_simp_profile_inspec_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
require 'spec_helper_acceptance' | ||
require 'json' | ||
|
||
test_name 'Check Inspec for simp profile' | ||
|
||
describe 'run inspec against the appropriate fixtures' do | ||
|
||
profiles_to_validate = ['disa_stig'] | ||
|
||
hosts.each do |host| | ||
profiles_to_validate.each do |profile| | ||
context "for profile #{profile}" do | ||
context "on #{host}" do | ||
profile_path = File.join( | ||
fixtures_path, | ||
'inspec_profiles', | ||
"#{fact_on(host, 'operatingsystem')}-#{fact_on(host, 'operatingsystemmajrelease')}-#{profile}" | ||
) | ||
|
||
unless File.exist?(profile_path) | ||
it 'should run inspec' do | ||
skip("No matching profile available at #{profile_path}") | ||
end | ||
else | ||
before(:all) do | ||
@inspec = Simp::BeakerHelpers::Inspec.new(host, profile) | ||
@inspec_report = {:data => nil} | ||
end | ||
|
||
it 'should run inspec' do | ||
@inspec.run | ||
end | ||
|
||
it 'should have an inspec report' do | ||
@inspec_report[:data] = @inspec.process_inspec_results | ||
|
||
info = [ | ||
'Results:', | ||
" * Passed: #{@inspec_report[:data][:passed]}", | ||
" * Failed: #{@inspec_report[:data][:failed]}", | ||
" * Skipped: #{@inspec_report[:data][:skipped]}" | ||
] | ||
|
||
puts info.join("\n") | ||
|
||
@inspec.write_report(@inspec_report[:data]) | ||
end | ||
|
||
it 'should have run some tests' do | ||
expect(@inspec_report[:data][:failed] + @inspec_report[:data][:passed]).to be > 0 | ||
end | ||
|
||
it 'should not have any failing tests' do | ||
if @inspec_report[:data][:failed] > 0 | ||
puts @inspec_report[:data][:report] | ||
end | ||
|
||
expect( @inspec_report[:data][:failed] ).to eq(0) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../nodesets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
RedHat-7-disa_stig |
38 changes: 38 additions & 0 deletions
38
spec/fixtures/inspec_profiles/RedHat-7-disa_stig/controls/00_Control_Selector.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
skips = {} | ||
overrides = [] | ||
subsystems = [ 'rsyslog' ] | ||
|
||
|
||
require_controls 'disa_stig-el7-baseline' do | ||
skips.each_pair do |ctrl, reason| | ||
control ctrl do | ||
describe "Skip #{ctrl}" do | ||
skip "Reason: #{skips[ctrl]}" do | ||
end | ||
end | ||
end | ||
end | ||
|
||
@conf['profile'].info[:controls].each do |ctrl| | ||
next if (overrides + skips.keys).include?(ctrl[:id]) | ||
|
||
tags = ctrl[:tags] | ||
if tags && tags[:subsystems] | ||
subsystems.each do |subsystem| | ||
if tags[:subsystems].include?(subsystem) | ||
control ctrl[:id] | ||
end | ||
end | ||
end | ||
end | ||
|
||
## Overrides ## | ||
|
||
# # USEFUL DESCRIPTION | ||
# control 'V-IDENTIFIER' do | ||
# # Enhancement, leave this out if you just want to add a different test | ||
# overrides << self.to_s | ||
# | ||
# only_if { file('whatever').exist? } | ||
# end | ||
end |
15 changes: 15 additions & 0 deletions
15
spec/fixtures/inspec_profiles/RedHat-7-disa_stig/inspec.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: EL7 rsyslog STIG | ||
title: rsyslog STIG for EL 7 | ||
supports: | ||
- os-family: redhat | ||
maintainer: SIMP Team | ||
copyright: Onyx Point, Inc. | ||
copyright_email: [email protected] | ||
license: Apache-2.0 | ||
summary: | | ||
A collection of InSpec tests for the rsyslog subsystem | ||
version: 0.0.1 | ||
depends: | ||
- name: disa_stig-el7-baseline | ||
path: ../../inspec_deps/inspec_profiles/profiles/disa_stig-el7-baseline | ||
|