2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/reporters"
|
2018-04-05 12:51:51 +00:00
|
|
|
|
|
|
|
describe Inspec::Reporters::Automate do
|
|
|
|
let(:path) { File.expand_path(File.dirname(__FILE__)) }
|
|
|
|
let(:options) do
|
|
|
|
{
|
2019-06-11 22:24:35 +00:00
|
|
|
"url" => "https://my-automate-server.mycompany.com/data-collector/v0/",
|
|
|
|
"token" => "kwe09wef9uqwqmpoqwdqd=",
|
|
|
|
"node_uuid" => "22ad2f99-f84f-5456-95a0-7e91b4b66690",
|
|
|
|
"node_name" => "test_node",
|
|
|
|
"environment" => "prod",
|
|
|
|
"report_uuid" => "22ad2f99-f84f-5456-95a0-7e91b4b12345",
|
|
|
|
"job_uuid" => "22ad2f99-f84f-5456-95a0-jobuuid12345",
|
2018-04-05 12:51:51 +00:00
|
|
|
}
|
|
|
|
end
|
2018-09-26 17:28:58 +00:00
|
|
|
let(:report) do
|
2019-06-11 22:24:35 +00:00
|
|
|
data = JSON.parse(File.read(path + "/../mock/reporters/run_data.json"), symbolize_names: true)
|
|
|
|
options[:run_data] = data
|
2018-04-05 12:51:51 +00:00
|
|
|
Inspec::Reporters::Automate.new(options)
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#enriched_report" do
|
|
|
|
it "returns a enriched report" do
|
2018-04-05 12:51:51 +00:00
|
|
|
report.enriched_report[:node_uuid].must_equal "22ad2f99-f84f-5456-95a0-7e91b4b66690"
|
|
|
|
report.enriched_report[:node_name].must_equal "test_node"
|
|
|
|
report.enriched_report[:environment].must_equal "prod"
|
2018-05-16 17:33:17 +00:00
|
|
|
report.enriched_report[:report_uuid].must_equal "22ad2f99-f84f-5456-95a0-7e91b4b12345"
|
2018-05-17 13:24:38 +00:00
|
|
|
report.enriched_report[:job_uuid].must_equal "22ad2f99-f84f-5456-95a0-jobuuid12345"
|
2018-04-05 12:51:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#send_report" do
|
|
|
|
it "returns true for sent report" do
|
2018-04-05 12:51:51 +00:00
|
|
|
headers = {
|
2019-06-11 22:24:35 +00:00
|
|
|
"Content-Type" => "application/json",
|
|
|
|
"x-data-collector-token" => "kwe09wef9uqwqmpoqwdqd=",
|
|
|
|
"x-data-collector-auth" => "version=1.0",
|
2018-04-05 12:51:51 +00:00
|
|
|
}
|
|
|
|
stub = Net::HTTP::Post.new("/data-collector/v0/", headers)
|
|
|
|
Net::HTTP::Post.expects(:new).with("/data-collector/v0/", headers).returns(stub)
|
2018-09-18 04:00:54 +00:00
|
|
|
Net::HTTP.any_instance.stubs(:request).returns(Net::HTTPSuccess.new(nil, nil, nil))
|
2018-04-05 12:51:51 +00:00
|
|
|
report.send_report.must_equal true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#uuid_from_string" do
|
|
|
|
it "converts a string to a uuid" do
|
2018-04-05 12:51:51 +00:00
|
|
|
end_time = "2018-03-28T14:10:50Z"
|
|
|
|
node_uuid = "22ad2f99-f84f-5456-95a0-7e91b4b66690"
|
|
|
|
assert = "4cd5aaa3-eea0-5aa2-9837-631e10b873b1"
|
|
|
|
report.send(:uuid_from_string, end_time + node_uuid).must_equal assert
|
|
|
|
end
|
|
|
|
end
|
2018-06-14 18:05:21 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "config insecure override" do
|
|
|
|
it "updates verify_ssl if insecure is set to false" do
|
|
|
|
options["insecure"] = false
|
2018-06-14 18:05:21 +00:00
|
|
|
reporter = Inspec::Reporters::Automate.new(options)
|
|
|
|
config = reporter.instance_variable_get(:@config)
|
2019-06-11 22:24:35 +00:00
|
|
|
config["verify_ssl"].must_equal true
|
2018-06-14 18:05:21 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "updates verify_ssl if insecure is set to true" do
|
|
|
|
options["insecure"] = true
|
2018-06-14 18:05:21 +00:00
|
|
|
reporter = Inspec::Reporters::Automate.new(options)
|
|
|
|
config = reporter.instance_variable_get(:@config)
|
2019-06-11 22:24:35 +00:00
|
|
|
config["verify_ssl"].must_equal false
|
2018-06-14 18:05:21 +00:00
|
|
|
end
|
|
|
|
end
|
2018-04-05 12:51:51 +00:00
|
|
|
end
|