2019-06-11 22:24:35 +00:00
|
|
|
require "functional/helper"
|
2016-03-25 00:31:19 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "example inheritance profile" do
|
2016-03-25 00:31:19 +00:00
|
|
|
include FunctionalHelper
|
2019-06-11 22:24:35 +00:00
|
|
|
let(:path) { File.join(examples_path, "inheritance") }
|
|
|
|
let(:input_file) { File.join(examples_path, "profile-attribute.yml") } # TODO rename attributes in examples
|
2016-03-25 00:31:19 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "check succeeds with --profiles-path" do
|
|
|
|
out = inspec("check " + path + " --profiles-path " + examples_path)
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(out.stderr).must_equal ""
|
|
|
|
_(out.stdout).must_match(/Valid.*true/)
|
2019-07-23 01:44:43 +00:00
|
|
|
assert_exit_code 0, out
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "check succeeds without --profiles-path using inspec.yml" do
|
|
|
|
prepare_examples("inheritance") do |dir|
|
|
|
|
inspec("vendor " + dir)
|
|
|
|
out = inspec("check " + dir)
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(out.stderr).must_equal ""
|
|
|
|
_(out.stdout).must_match(/Valid.*true/)
|
2019-07-23 01:44:43 +00:00
|
|
|
assert_exit_code 0, out
|
2018-11-02 16:52:54 +00:00
|
|
|
end
|
2016-08-11 15:34:27 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "archive is successful with --profiles-path" do
|
|
|
|
prepare_examples("inheritance") do |dir|
|
|
|
|
out = inspec("archive " + dir + " --output " + dst.path + " --profiles-path " + examples_path)
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(out.stderr).must_equal ""
|
|
|
|
_(out.stdout).must_include "Generate archive " + dst.path
|
|
|
|
_(out.stdout).must_include "Finished archive generation."
|
|
|
|
_(File.exist?(dst.path)).must_equal true
|
2019-07-23 01:44:43 +00:00
|
|
|
assert_exit_code 0, out
|
2018-11-02 16:52:54 +00:00
|
|
|
end
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "archive is successful without --profiles-path using inspec.yml" do
|
|
|
|
prepare_examples("inheritance") do |dir|
|
|
|
|
out = inspec("archive " + dir + " --output " + dst.path)
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(out.stderr).must_equal ""
|
|
|
|
_(out.stdout).must_include "Generate archive " + dst.path
|
|
|
|
_(out.stdout).must_include "Finished archive generation."
|
|
|
|
_(File.exist?(dst.path)).must_equal true
|
2019-07-23 01:44:43 +00:00
|
|
|
assert_exit_code 0, out
|
2018-11-02 16:52:54 +00:00
|
|
|
end
|
2016-08-11 15:34:27 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "read the profile json with --profiles-path" do
|
|
|
|
out = inspec("json " + path + " --profiles-path " + examples_path)
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(out.stderr).must_equal ""
|
2016-03-25 00:31:19 +00:00
|
|
|
s = out.stdout
|
|
|
|
hm = JSON.load(s)
|
2019-07-24 18:10:15 +00:00
|
|
|
hm["name"].must_equal "inheritance"
|
|
|
|
hm["controls"].length.must_equal 6
|
2019-07-23 01:44:43 +00:00
|
|
|
assert_exit_code 0, out
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|
2016-08-11 15:34:27 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "read the profile json without --profiles-path using inspec.yml" do
|
|
|
|
out = inspec("json " + path)
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(out.stderr).must_equal ""
|
2016-08-11 15:34:27 +00:00
|
|
|
s = out.stdout
|
|
|
|
hm = JSON.load(s)
|
2019-07-24 18:10:15 +00:00
|
|
|
hm["name"].must_equal "inheritance"
|
|
|
|
hm["controls"].length.must_equal 6
|
2019-07-23 01:44:43 +00:00
|
|
|
assert_exit_code 0, out
|
2016-11-04 17:01:17 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "can execute a profile inheritance" do
|
|
|
|
out = inspec("exec " + path + " --reporter json --no-create-lockfile --input-file " + input_file)
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(out.stderr).must_equal ""
|
|
|
|
_(JSON.load(out.stdout)).must_be_kind_of Hash
|
2019-07-23 01:44:43 +00:00
|
|
|
assert_exit_code 101, out
|
2016-08-11 15:34:27 +00:00
|
|
|
end
|
2016-03-25 00:31:19 +00:00
|
|
|
end
|