-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add waiver-file support
- Loading branch information
Showing
9 changed files
with
88 additions
and
0 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
16 changes: 16 additions & 0 deletions
16
test/cookbooks/test_helper/files/waivers-fixture/controls/waiver-check.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,16 @@ | ||
|
||
# Some of these controls are waivered by the file waivers/waivers.yaml | ||
|
||
# control-01 is normal, should pass | ||
control "control-01" do | ||
describe "the expected value" do | ||
it { should cmp "the expected value" } | ||
end | ||
end | ||
|
||
# control-02 is permanently waivered, should be skipped | ||
control "control-02" do | ||
describe "the expected value" do | ||
it { should cmp "the expected value" } | ||
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,6 @@ | ||
name: waivers-fixture | ||
license: Apache-2.0 | ||
summary: A simple profile to verify waiver functionality under audit cookbook | ||
version: 0.1.0 | ||
supports: | ||
platform: os |
4 changes: 4 additions & 0 deletions
4
test/cookbooks/test_helper/files/waivers-fixture/waivers/waivers.yaml
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,4 @@ | ||
--- | ||
control-02: | ||
justification: It must be waivered for this test | ||
run: false |
19 changes: 19 additions & 0 deletions
19
test/cookbooks/test_helper/recipes/setup_waiver_fixture.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,19 @@ | ||
|
||
[ | ||
"controls", | ||
"waivers", | ||
].each do |subdir| | ||
directory "#{node["audit"]["profiles"]["waiver-test-profile"]["path"]}/#{subdir}" do | ||
recursive true | ||
end | ||
end | ||
|
||
[ | ||
"inspec.yml", | ||
"controls/waiver-check.rb", | ||
"waivers/waivers.yaml", | ||
].each do |file| | ||
cookbook_file "#{node["audit"]["profiles"]["waiver-test-profile"]["path"]}/#{file}" do | ||
source "waivers-fixture/#{file}" | ||
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,18 @@ | ||
# get most recent json-file output | ||
json_file = command('ls -t /tmp/inspec-*.json').stdout.lines.first.chomp | ||
controls = json(json_file).profiles.first['controls'] | ||
|
||
# The test fixture has two controls - the first should pass, | ||
# the second should be a skip with a waiver justification | ||
|
||
control "the unwaivered control" do | ||
describe controls[0]['results'][0]['status'] do | ||
it { should cmp "passed" } | ||
end | ||
end | ||
|
||
control "the waivered control" do | ||
describe controls[1]['results'][0]['status'] do | ||
it { should cmp "skipped" } | ||
end | ||
end |