2019-06-11 22:24:35 +00:00
|
|
|
require "functional/helper"
|
|
|
|
require "tempfile"
|
2018-08-09 13:18:10 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "inspec exec automate" do
|
2018-08-09 13:18:10 +00:00
|
|
|
include FunctionalHelper
|
|
|
|
|
2019-03-26 14:44:01 +00:00
|
|
|
let(:config_path) do
|
2019-11-07 02:35:43 +00:00
|
|
|
@file = Tempfile.new("config.json")
|
|
|
|
@file.write(config_data)
|
|
|
|
@file.close
|
|
|
|
@file.path
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
@file.unlink
|
2018-08-09 13:18:10 +00:00
|
|
|
end
|
|
|
|
|
2019-03-26 14:44:01 +00:00
|
|
|
let(:invocation) do
|
2020-01-28 23:52:02 +00:00
|
|
|
"exec #{complete_profile} --config #{config_path}"
|
2019-03-26 14:44:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:run_result) { run_inspec_process(invocation) }
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the the URL is fake" do
|
2019-03-26 14:44:01 +00:00
|
|
|
let(:config_data) do
|
2019-05-31 21:59:06 +00:00
|
|
|
<<~END
|
2019-06-01 20:08:50 +00:00
|
|
|
{
|
|
|
|
"reporter": {
|
|
|
|
"automate": {
|
|
|
|
"stdout": false,
|
|
|
|
"url": "https://fake_url_a2.com/data-collector/v0/",
|
|
|
|
"token": "faketoken123",
|
|
|
|
"insecure": true,
|
|
|
|
"node_uuid": "test123"
|
|
|
|
}
|
2019-05-31 21:59:06 +00:00
|
|
|
}
|
2019-06-11 22:24:35 +00:00
|
|
|
}
|
2019-05-31 21:59:06 +00:00
|
|
|
END
|
2019-03-26 14:44:01 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "should fail" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(run_result.stderr).must_equal "Error generating reporter 'automate'\n"
|
|
|
|
_(run_result.stdout).must_include "ERROR: send_report: POST to /data-collector/v0/"
|
2019-07-23 01:44:43 +00:00
|
|
|
assert_exit_code 1, run_result
|
2019-03-26 14:44:01 +00:00
|
|
|
end
|
2018-08-09 13:18:10 +00:00
|
|
|
end
|
2019-03-28 04:41:05 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when outputting to $stdout" do
|
2019-03-28 04:41:05 +00:00
|
|
|
let(:config_data) do
|
2019-05-31 21:59:06 +00:00
|
|
|
<<~END
|
2019-06-01 20:08:50 +00:00
|
|
|
{
|
|
|
|
"reporter": {
|
|
|
|
"json-automate": {
|
|
|
|
"stdout": true,
|
|
|
|
"job_uuid": "test123",
|
|
|
|
"roles": ["stuff"],
|
|
|
|
"environment": "prod",
|
|
|
|
"node_name": "some_node",
|
|
|
|
"passthrough": {
|
|
|
|
"projects": ["alpha", "beta"],
|
|
|
|
"another_tramp_datum": "another_value"
|
|
|
|
}
|
2019-03-28 04:41:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-31 21:59:06 +00:00
|
|
|
END
|
2019-03-28 04:41:05 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "should include tramp data" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(run_result.stderr).must_equal ""
|
2019-03-28 04:41:05 +00:00
|
|
|
|
|
|
|
# Can't use json-mode on run_inspec_process - it sets
|
|
|
|
# the reporter to be 'json', we need 'json-automate'
|
|
|
|
json = JSON.parse(run_result.stdout)
|
|
|
|
|
|
|
|
# As of InSpec v3.7.11, these are all top-level tramp data:
|
2019-06-11 22:24:35 +00:00
|
|
|
%w{
|
|
|
|
node_name
|
|
|
|
job_uuid
|
|
|
|
environment
|
|
|
|
roles
|
|
|
|
}.each do |field|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(json.keys).must_include field
|
2019-03-28 04:41:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# As of InSpec v3.7.11+, these should be removed:
|
|
|
|
[
|
2019-06-11 22:24:35 +00:00
|
|
|
"recipies", # sic
|
2019-03-28 04:41:05 +00:00
|
|
|
].each do |field|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(json.keys).wont_include field
|
2019-03-28 04:41:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Added in InSpec v3.7.11+
|
2019-09-30 22:31:55 +00:00
|
|
|
_(json.keys).must_include "passthrough"
|
|
|
|
_(json["passthrough"].keys.sort).must_equal %w{another_tramp_datum projects}
|
|
|
|
_(json["passthrough"]["projects"]).must_equal %w{alpha beta}
|
2019-03-28 04:41:05 +00:00
|
|
|
|
2020-01-28 23:52:02 +00:00
|
|
|
assert_exit_code 0, run_result
|
2019-03-28 04:41:05 +00:00
|
|
|
end
|
|
|
|
end
|
2018-08-09 13:18:10 +00:00
|
|
|
end
|