1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
require "spec_helper"
describe Chef::Compliance::Reporter::AuditEnforcer do
let(:reporter) { Chef::Compliance::Reporter::AuditEnforcer.new }
it "does not raise error for a successful InSpec report" do
report = {
"profiles": [
{
"controls": [
{ "id": "c1", "results": [{ "status": "passed" }] },
{ "id": "c2", "results": [{ "status": "passed" }] },
],
},
],
}
expect(reporter.send_report(report)).to eq(true)
end
it "does not raise error for an InSpec report with no controls" do
report = { "profiles": [{ "name": "empty" }] }
expect(reporter.send_report(report)).to eq(true)
end
it "does not raise error for an InSpec report with controls but no results" do
report = { "profiles": [{ "controls": [{ "id": "empty" }] }] }
expect(reporter.send_report(report)).to eq(true)
end
it "raises an error for a failed InSpec report" do
report = {
"profiles": [
{
"controls": [
{ "id": "c1", "results": [{ "status": "passed" }] },
{ "id": "c2", "results": [{ "status": "failed" }] },
],
},
],
}
expect {
reporter.send_report(report)
}.to raise_error(Chef::Compliance::Reporter::AuditEnforcer::ControlFailure, "Audit c2 has failed. Aborting chef-client run.")
end
end
|