2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/reporters"
|
2018-02-08 09:06:58 +00:00
|
|
|
|
|
|
|
describe Inspec::Reporters::Json do
|
|
|
|
let(:report) do
|
2019-11-09 03:08:20 +00:00
|
|
|
data = JSON.parse(File.read("test/fixtures/reporters/run_data.json"), symbolize_names: true)
|
2018-02-08 09:06:58 +00:00
|
|
|
Inspec::Reporters::Json.new({ run_data: data })
|
|
|
|
end
|
|
|
|
let(:profile) { report.run_data[:profiles].first }
|
|
|
|
let(:control) { profile[:controls].first }
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#render" do
|
|
|
|
it "confirm render output" do
|
2019-11-09 03:08:20 +00:00
|
|
|
output = File.read("test/fixtures/reporters/json_output")
|
2018-02-08 09:06:58 +00:00
|
|
|
report.render
|
2019-10-10 00:20:24 +00:00
|
|
|
_(JSON.parse(report.rendered_output)).must_equal JSON.parse(output)
|
2018-02-08 09:06:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#report" do
|
|
|
|
it "confirm report output" do
|
2019-11-09 03:08:20 +00:00
|
|
|
output = File.read("test/fixtures/reporters/json_output")
|
2018-02-09 14:14:40 +00:00
|
|
|
output = JSON.parse(output, symbolize_names: true)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(report.report).must_equal output
|
2018-02-09 14:14:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#platform" do
|
|
|
|
it "confirm platform output" do
|
|
|
|
hash = { name: "mac_os_x", release: "17.2.0" }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(report.send(:platform)).must_equal hash
|
2018-02-08 09:06:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "report output includes depends" do
|
|
|
|
it "sets the depends key" do
|
2018-05-10 17:53:37 +00:00
|
|
|
depends = {
|
|
|
|
depends: {
|
2019-06-11 22:24:35 +00:00
|
|
|
"path" => "../child",
|
|
|
|
"name" => "child",
|
|
|
|
},
|
2018-05-10 17:53:37 +00:00
|
|
|
}
|
2019-11-09 03:08:20 +00:00
|
|
|
data = JSON.parse(File.read("test/fixtures/reporters/run_data.json"), symbolize_names: true)
|
2018-05-10 17:53:37 +00:00
|
|
|
data[:profiles].first[:depends] = depends
|
|
|
|
json_report = Inspec::Reporters::Json.new({ run_data: data })
|
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(json_report.report[:profiles].first[:depends]).must_equal depends
|
2018-05-10 17:53:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#profile_results" do
|
|
|
|
it "confirm profile_results output" do
|
2018-02-08 09:06:58 +00:00
|
|
|
hash = {
|
2019-06-11 22:24:35 +00:00
|
|
|
status: "passed",
|
|
|
|
code_desc: "File /tmp should be directory",
|
2018-02-08 09:06:58 +00:00
|
|
|
run_time: 0.002058,
|
2019-06-11 22:24:35 +00:00
|
|
|
start_time: "2018-01-05 11:43:04 -0500",
|
2018-02-08 09:06:58 +00:00
|
|
|
}
|
|
|
|
result = report.send(:profile_results, control)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(result.first).must_equal hash
|
2018-02-08 09:06:58 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "confirm profile_result with optional" do
|
|
|
|
control[:results].first[:resource] = "File"
|
|
|
|
control[:results].first[:skip_message] = "skipping"
|
2018-02-08 09:06:58 +00:00
|
|
|
hash = {
|
2019-06-11 22:24:35 +00:00
|
|
|
status: "passed",
|
|
|
|
code_desc: "File /tmp should be directory",
|
2018-02-08 09:06:58 +00:00
|
|
|
run_time: 0.002058,
|
2019-06-11 22:24:35 +00:00
|
|
|
start_time: "2018-01-05 11:43:04 -0500",
|
|
|
|
resource: "File",
|
|
|
|
skip_message: "skipping",
|
2018-02-08 09:06:58 +00:00
|
|
|
}
|
|
|
|
result = report.send(:profile_results, control)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(result.first).must_equal hash
|
2018-02-08 09:06:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#profile_controls" do
|
|
|
|
it "confirm profile_results output" do
|
2018-02-08 09:06:58 +00:00
|
|
|
hash = {
|
2019-06-11 22:24:35 +00:00
|
|
|
id: "(generated from example.rb:7 871cd54043069c5c4f6e382fd5627830)",
|
2018-02-08 09:06:58 +00:00
|
|
|
title: nil,
|
|
|
|
desc: nil,
|
2018-09-26 17:28:58 +00:00
|
|
|
descriptions: [],
|
2018-02-08 09:06:58 +00:00
|
|
|
impact: 0.5,
|
|
|
|
refs: [],
|
|
|
|
tags: {},
|
2019-06-11 22:24:35 +00:00
|
|
|
code: "",
|
2018-02-08 09:06:58 +00:00
|
|
|
source_location: {
|
|
|
|
line: 89,
|
2019-06-11 22:24:35 +00:00
|
|
|
ref: "/Users/jquick/Chef/inspec/lib/inspec/control_eval_context.rb",
|
2018-02-08 09:06:58 +00:00
|
|
|
},
|
2019-10-09 04:00:11 +00:00
|
|
|
waiver_data: {},
|
2018-02-08 09:06:58 +00:00
|
|
|
}
|
|
|
|
control = report.send(:profile_controls, profile).first
|
|
|
|
control.delete(:results)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(control).must_equal hash
|
2018-02-08 09:06:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#profile_groups" do
|
|
|
|
it "confirm profile_groups output" do
|
2018-02-08 09:06:58 +00:00
|
|
|
hash = {
|
2019-06-11 22:24:35 +00:00
|
|
|
id: "controls/example.rb",
|
2018-02-08 09:06:58 +00:00
|
|
|
controls: [
|
2019-06-11 22:24:35 +00:00
|
|
|
"(generated from example.rb:7 871cd54043069c5c4f6e382fd5627830)",
|
|
|
|
"tmp-1.0",
|
|
|
|
"(generated from example.rb:21 2ff474c5357e7070f4c3efa932032dcb)",
|
2018-02-08 09:06:58 +00:00
|
|
|
],
|
2019-06-11 22:24:35 +00:00
|
|
|
title: "sample section",
|
2018-02-08 09:06:58 +00:00
|
|
|
}
|
|
|
|
group = report.send(:profile_groups, profile)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(group.first).must_equal hash
|
2018-02-08 09:06:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#profiles" do
|
|
|
|
it "confirm profile_groups output" do
|
2018-02-08 09:06:58 +00:00
|
|
|
hash = {
|
2019-06-11 22:24:35 +00:00
|
|
|
name: "long_commands",
|
|
|
|
version: "0.1.0",
|
|
|
|
sha256: "4f816f8cf18f165f05f1cf20936aaad06a15287de3f578891197647ca05c7df4",
|
|
|
|
title: "InSpec Profile",
|
|
|
|
maintainer: "The Authors",
|
|
|
|
summary: "An InSpec Compliance Profile",
|
|
|
|
license: "Apache-2.0",
|
|
|
|
copyright: "The Authors",
|
|
|
|
copyright_email: "you@example.com",
|
2018-02-08 09:06:58 +00:00
|
|
|
supports: [
|
2019-06-11 22:24:35 +00:00
|
|
|
{ 'os-family': "bds" },
|
2018-02-08 09:06:58 +00:00
|
|
|
{
|
2019-06-11 22:24:35 +00:00
|
|
|
'os-name': "mac_os_x",
|
|
|
|
release: "17.*",
|
2018-02-08 09:06:58 +00:00
|
|
|
},
|
|
|
|
],
|
2019-02-12 23:02:54 +00:00
|
|
|
attributes: [], # TODO: rename attributes in json reporter
|
2018-02-08 09:06:58 +00:00
|
|
|
}
|
|
|
|
profile = report.send(:profiles).first
|
|
|
|
profile.delete(:groups)
|
|
|
|
profile.delete(:controls)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(profile).must_equal hash
|
2018-02-08 09:06:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|