Merge pull request #6059 from inspec/cw/backport-json-inputs-fix

CFINSPEC-250: Fix for inspec json command populating inputs
This commit is contained in:
Clinton Wolfe 2022-05-12 10:53:56 -04:00 committed by GitHub
commit c715c16121
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View file

@ -787,7 +787,12 @@ module Inspec
f = load_rule_filepath(prefix, rule)
load_rule(rule, f, controls, groups)
end
params[:inputs] = Inspec::InputRegistry.list_inputs_for_profile(@profile_id)
if @profile_id.nil?
# identifying inputs using profile name
params[:inputs] = Inspec::InputRegistry.list_inputs_for_profile(params[:name])
else
params[:inputs] = Inspec::InputRegistry.list_inputs_for_profile(@profile_id)
end
params
end

View file

@ -26,6 +26,10 @@ describe "inspec json" do
_(json["generator"]["version"]).must_equal Inspec::VERSION
end
it "has empty array of inputs" do
_(json["inputs"]).must_be_empty
end
it "has a name" do
_(json["name"]).must_equal "profile"
end
@ -85,6 +89,14 @@ describe "inspec json" do
end
end
describe "json profile data with inputs" do
let(:json) { JSON.load(inspec("json " + examples_path + "/profile-attribute").stdout) }
it "has a inputs" do
_(json["inputs"]).must_equal [{ "name" => "user", "options" => { "value" => "alice" } }, { "name" => "password", "options" => { "value" => "Input 'password' does not have a value. Skipping test." } }]
end
end
describe "filter with --controls" do
let(:out) { inspec("json " + example_profile + " --controls tmp-1.0") }