From 33624303f99b36eb405241c16ef159d7ecc91ce8 Mon Sep 17 00:00:00 2001 From: Vasu1105 Date: Thu, 12 May 2022 13:25:33 +0530 Subject: [PATCH] CFINSPEC-250: Fix for inspec json command does not populate the attribues/inputs for the profile Signed-off-by: Vasu1105 --- lib/inspec/profile.rb | 7 ++++++- test/functional/inspec_json_profile_test.rb | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/inspec/profile.rb b/lib/inspec/profile.rb index c99f6210a..1a2fafde1 100644 --- a/lib/inspec/profile.rb +++ b/lib/inspec/profile.rb @@ -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 diff --git a/test/functional/inspec_json_profile_test.rb b/test/functional/inspec_json_profile_test.rb index 6e5cbbe70..660a2ab6f 100644 --- a/test/functional/inspec_json_profile_test.rb +++ b/test/functional/inspec_json_profile_test.rb @@ -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") }