2019-06-11 22:24:35 +00:00
|
|
|
require "functional/helper"
|
|
|
|
require "json-schema"
|
2016-06-14 12:41:45 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "inspec exec" do
|
2016-06-14 12:41:45 +00:00
|
|
|
include FunctionalHelper
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "can execute a profile with the mini json formatter and validate its schema" do
|
|
|
|
out = inspec("exec " + example_profile + " --reporter json-min --no-create-lockfile")
|
2017-03-14 15:50:10 +00:00
|
|
|
data = JSON.parse(out.stdout)
|
2019-06-11 22:24:35 +00:00
|
|
|
sout = inspec("schema exec-jsonmin")
|
2017-03-14 15:50:10 +00:00
|
|
|
schema = JSON.parse(sout.stdout)
|
2019-06-02 06:17:53 +00:00
|
|
|
JSON::Validator.validate(schema, data).wont_equal false
|
2019-07-23 01:44:43 +00:00
|
|
|
|
|
|
|
out.stderr.must_equal ""
|
|
|
|
|
|
|
|
assert_exit_code 101, out
|
2016-06-14 12:41:45 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "can execute a simple file with the mini json formatter and validate its schema" do
|
|
|
|
out = inspec("exec " + example_control + " --reporter json-min --no-create-lockfile")
|
2017-03-14 15:50:10 +00:00
|
|
|
data = JSON.parse(out.stdout)
|
2019-06-11 22:24:35 +00:00
|
|
|
sout = inspec("schema exec-jsonmin")
|
2017-03-14 15:50:10 +00:00
|
|
|
schema = JSON.parse(sout.stdout)
|
2019-06-02 06:17:53 +00:00
|
|
|
JSON::Validator.validate(schema, data).wont_equal false
|
2019-07-23 01:44:43 +00:00
|
|
|
|
|
|
|
out.stderr.must_equal ""
|
|
|
|
|
2019-07-25 01:59:01 +00:00
|
|
|
skip_windows!
|
2019-07-23 01:44:43 +00:00
|
|
|
assert_exit_code 0, out
|
2016-06-14 12:41:45 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "does not contain any dupilcate results with describe.one" do
|
2018-02-08 09:06:58 +00:00
|
|
|
out = inspec("shell -c 'describe.one do describe 1 do it { should cmp 2 } end end' --reporter=json-min")
|
2017-06-06 20:39:10 +00:00
|
|
|
data = JSON.parse(out.stdout)
|
2019-06-11 22:24:35 +00:00
|
|
|
data["controls"].length.must_equal 1
|
|
|
|
data["controls"][0]["message"].must_equal "\nexpected: 2\n got: 1\n\n(compared using `cmp` matcher)\n"
|
2019-07-23 01:44:43 +00:00
|
|
|
|
|
|
|
out.stderr.must_equal ""
|
|
|
|
|
|
|
|
assert_exit_code 100, out
|
2017-06-06 20:39:10 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "execute a profile with mini json formatting" do
|
|
|
|
let(:json) { JSON.load(inspec("exec " + example_profile + " --reporter json-min --no-create-lockfile").stdout) }
|
|
|
|
let(:controls) { json["controls"] }
|
|
|
|
let(:ex1) { controls.find { |x| x["id"] == "tmp-1.0" } }
|
|
|
|
let(:ex2) { controls.find { |x| x["id"] =~ /generated/ } }
|
|
|
|
let(:ex3) { controls.find { |x| x["id"] == "gordon-1.0" } }
|
2016-06-14 12:41:45 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "must have 5 examples" do
|
|
|
|
json["controls"].length.must_equal 5
|
2016-06-14 12:41:45 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "has an id" do
|
|
|
|
controls.find { |ex| !ex.key? "id" }.must_be :nil?
|
2016-06-14 12:41:45 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "has a profile_id" do
|
|
|
|
controls.find { |ex| !ex.key? "profile_id" }.must_be :nil?
|
2016-06-14 12:41:45 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "has a code_desc" do
|
|
|
|
ex1["code_desc"].must_equal "File /tmp should be directory"
|
|
|
|
controls.find { |ex| !ex.key? "code_desc" }.must_be :nil?
|
2016-06-14 12:41:45 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "has a status" do
|
2019-07-25 01:59:01 +00:00
|
|
|
skip_windows!
|
2019-06-11 22:24:35 +00:00
|
|
|
ex1["status"].must_equal "passed"
|
|
|
|
ex3["status"].must_equal "skipped"
|
2016-06-14 12:41:45 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "has a skip_message" do
|
|
|
|
ex1["skip_message"].must_be :nil?
|
|
|
|
ex3["skip_message"].must_equal "Can't find file `/tmp/gordon/config.yaml`"
|
2016-06-14 12:41:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|