Merge pull request #5918 from inspec/vasundhara/deprecates-target-id-option

CFINSPEC-137: Deprecate --target-id option
This commit is contained in:
Clinton Wolfe 2022-03-11 14:36:36 -05:00 committed by GitHub
commit 0fb344c1d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 76 additions and 74 deletions

View file

@ -380,7 +380,7 @@ This subcommand has the following additional options:
* ``-t``, ``--target=TARGET`` * ``-t``, ``--target=TARGET``
Simple targeting option using URIs, e.g. ssh://user:pass@host:port. Simple targeting option using URIs, e.g. ssh://user:pass@host:port.
* ``--target-id=TARGET_ID`` * ``--target-id=TARGET_ID``
Provide a ID which will be included on reports. Provide a ID which will be included on reports - deprecated.
* ``--tags=one two three`` * ``--tags=one two three``
A list of tags or a list of regular expressions that match tags. `exec` will run controls referenced by the listed or matching tags. A list of tags or a list of regular expressions that match tags. `exec` will run controls referenced by the listed or matching tags.
* ``--user=USER`` * ``--user=USER``

View file

@ -122,6 +122,10 @@
"action": "warn", "action": "warn",
"prefix": "The --hook option is being replaced by the --activator option.", "prefix": "The --hook option is being replaced by the --activator option.",
"suffix": "This options will be removed in InSpec 4.0." "suffix": "This options will be removed in InSpec 4.0."
},
"cli_option_target_id":{
"action": "warn",
"prefix": "The --target-id option is deprecated in InSpec 5. Its value will be ignored."
} }
} }
} }

View file

@ -131,7 +131,7 @@ module Inspec
option :insecure, type: :boolean, default: false, option :insecure, type: :boolean, default: false,
desc: "Disable SSL verification on select targets" desc: "Disable SSL verification on select targets"
option :target_id, type: :string, option :target_id, type: :string,
desc: "Provide a ID which will be included on reports" desc: "Provide a ID which will be included on reports - deprecated"
option :winrm_shell_type, type: :string, default: "powershell", option :winrm_shell_type, type: :string, default: "powershell",
desc: "Specify a shell type for winrm (eg. 'elevated' or 'powershell')" desc: "Specify a shell type for winrm (eg. 'elevated' or 'powershell')"
option :docker_url, type: :string, option :docker_url, type: :string,

View file

@ -302,6 +302,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
def exec(*targets) def exec(*targets)
o = config o = config
diagnose(o) diagnose(o)
deprecate_target_id(config)
configure_logger(o) configure_logger(o)
runner = Inspec::Runner.new(o) runner = Inspec::Runner.new(o)
@ -320,6 +321,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
option :format, type: :string option :format, type: :string
def detect def detect
o = config o = config
deprecate_target_id(config)
o[:command] = "platform.params" o[:command] = "platform.params"
configure_logger(o) configure_logger(o)
@ -360,6 +362,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
desc: "Specify one or more inputs directly on the command line to the shell, as --input NAME=VALUE. Accepts single-quoted YAML and JSON structures." desc: "Specify one or more inputs directly on the command line to the shell, as --input NAME=VALUE. Accepts single-quoted YAML and JSON structures."
def shell_func def shell_func
o = config o = config
deprecate_target_id(config)
diagnose(o) diagnose(o)
o[:debug_shell] = true o[:debug_shell] = true
@ -447,6 +450,12 @@ class Inspec::InspecCLI < Inspec::BaseCLI
private private
def deprecate_target_id(config)
unless config[:target_id].nil?
Inspec.deprecate "cli_option_target_id"
end
end
def run_command(opts) def run_command(opts)
runner = Inspec::Runner.new(Inspec::Config.new(opts)) runner = Inspec::Runner.new(Inspec::Config.new(opts))
res = runner.eval_with_virtual_profile(opts[:command]) res = runner.eval_with_virtual_profile(opts[:command])

View file

@ -21,7 +21,7 @@ module Inspec::Reporters
final_report[:type] = "inspec_report" final_report[:type] = "inspec_report"
final_report[:end_time] = Time.now.utc.strftime("%FT%TZ") final_report[:end_time] = Time.now.utc.strftime("%FT%TZ")
final_report[:node_uuid] = report[:platform][:target_id] || @config["node_uuid"] || @config["target_id"] final_report[:node_uuid] = @config["node_uuid"] || report[:platform][:target_id]
raise Inspec::ReporterError, "Cannot find a UUID for your node. Please specify one via json-config." if final_report[:node_uuid].nil? raise Inspec::ReporterError, "Cannot find a UUID for your node. Please specify one via json-config." if final_report[:node_uuid].nil?
final_report[:report_uuid] = @config["report_uuid"] || uuid_from_string(final_report[:end_time] + final_report[:node_uuid]) final_report[:report_uuid] = @config["report_uuid"] || uuid_from_string(final_report[:end_time] + final_report[:node_uuid])

View file

@ -76,7 +76,7 @@ module Inspec::Reporters
} }
header["Failure Message"] = profile[:status_message] if profile[:status] == "failed" header["Failure Message"] = profile[:status_message] if profile[:status] == "failed"
header["Target"] = run_data[:platform][:target] unless run_data[:platform][:target].nil? header["Target"] = run_data[:platform][:target] unless run_data[:platform][:target].nil?
header["Target ID"] = @config["target_id"] unless @config["target_id"].nil? header["Target ID"] = run_data[:platform][:target_id] || ""
pad = header.keys.max_by(&:length).length + 1 pad = header.keys.max_by(&:length).length + 1
header.each do |title, value| header.each do |title, value|

View file

@ -29,7 +29,7 @@ module Inspec::Reporters
{ {
name: run_data[:platform][:name], name: run_data[:platform][:name],
release: run_data[:platform][:release], release: run_data[:platform][:release],
target_id: run_data[:platform][:target_id] || @config["target_id"], target_id: run_data[:platform][:target_id] || "",
}.reject { |_k, v| v.nil? } }.reject { |_k, v| v.nil? }
end end

View file

@ -1,7 +1,8 @@
Profile: InSpec Profile (long_commands) Profile: InSpec Profile (long_commands)
Version: 0.1.0 Version: 0.1.0
Target: local:// Target: local://
Target ID:
 ✔ tmp-1.0: Create /tmp directory  ✔ tmp-1.0: Create /tmp directory
 ✔ File /tmp should be directory  ✔ File /tmp should be directory

View file

@ -1,7 +1,8 @@
Profile: InSpec Profile (long_commands) Profile: InSpec Profile (long_commands)
Version: 0.1.0 Version: 0.1.0
Target: local:// Target: local://
Target ID:
 [PASS] tmp-1.0: Create /tmp directory  [PASS] tmp-1.0: Create /tmp directory
 [PASS] File /tmp should be directory  [PASS] File /tmp should be directory

View file

@ -1,7 +1,8 @@
{ {
"platform": { "platform": {
"name": "mac_os_x", "name": "mac_os_x",
"release": "17.5.0" "release": "17.5.0",
"target_id": ""
}, },
"profiles": [ "profiles": [
{ {

View file

@ -1 +1 @@
{"platform":{"name":"mac_os_x","release":"17.2.0"},"profiles":[{"name":"long_commands","version":"0.1.0","sha256":"4f816f8cf18f165f05f1cf20936aaad06a15287de3f578891197647ca05c7df4","title":"InSpec Profile","maintainer":"The Authors","summary":"An InSpec Compliance Profile","license":"Apache-2.0","copyright":"The Authors","copyright_email":"you@example.com","supports":[{"os-family":"bds"},{"os-name":"mac_os_x","release":"17.*"}],"attributes":[],"groups":[{"id":"controls/example.rb","controls":["(generated from example.rb:7 871cd54043069c5c4f6e382fd5627830)","tmp-1.0","(generated from example.rb:21 2ff474c5357e7070f4c3efa932032dcb)"],"title":"sample section"},{"id":"controls/run_command.rb","controls":["(generated from run_command.rb:5 a411d4ded1530b2f48170840e1127584)"]}],"controls":[{"id":"(generated from example.rb:7 871cd54043069c5c4f6e382fd5627830)","title":null,"desc":null,"descriptions":[],"impact":0.5,"refs":[],"tags":{},"code":"","source_location":{"line":89,"ref":"/Users/jquick/Chef/inspec/lib/inspec/control_eval_context.rb"},"waiver_data":{},"results":[{"status":"passed","code_desc":"File /tmp should be directory","run_time":0.002058,"start_time":"2018-01-05 11:43:04 -0500","resource_params":"","resource_id":"File /tmp"}]},{"id":"tmp-1.0","title":"Create /tmp directory","desc":"An optional description...","descriptions":[{"label":"default","data":"An optional description..."}],"impact":0.7,"refs":[],"tags":{},"code":"control 'tmp-1.0' do # A unique ID for this control\n impact 0.7 # The criticality, if this control fails.\n title 'Create /tmp directory' # A human-readable title\n desc 'An optional description...'\n describe file('/tmp') do # The actual test\n it { should be_directory }\n end\nend\n","waiver_data":{},"source_location":{"line":12,"ref":"../inspec-demo/_test/long_commands/controls/example.rb"},"results":[{"status":"passed","code_desc":"File /tmp should be directory","run_time":0.000102,"start_time":"2018-01-05 11:43:04 -0500","resource_params":"","resource_id":"File /tmp"}]},{"id":"(generated from example.rb:21 2ff474c5357e7070f4c3efa932032dcb)","title":null,"desc":null,"descriptions":[],"impact":0.5,"refs":[],"tags":{},"code":"","waiver_data":{},"source_location":{"line":89,"ref":"/Users/jquick/Chef/inspec/lib/inspec/control_eval_context.rb"},"results":[{"status":"failed","code_desc":"gem package rubocop should be installed","run_time":0.000168,"start_time":"2018-01-05 11:43:04 -0500","message":"rubocop is not installed","resource_params":"","resource_id":"gem package rubocop"}]},{"id":"(generated from run_command.rb:5 a411d4ded1530b2f48170840e1127584)","title":null,"desc":null,"descriptions":[],"impact":0.5,"refs":[],"tags":{},"code":"","waiver_data":{},"source_location":{"line":89,"ref":"/Users/jquick/Chef/inspec/lib/inspec/control_eval_context.rb"},"results":[{"status":"passed","code_desc":"Command whoami stdout should eq \"jquick\\n\"","run_time":0.034938,"start_time":"2018-01-05 11:43:04 -0500","resource_params":"","resource_id":"stdout"}]}]}],"statistics":{"duration":0.039182},"version":"1.49.2"} {"platform":{"name":"mac_os_x","release":"17.2.0", "target_id":""},"profiles":[{"name":"long_commands","version":"0.1.0","sha256":"4f816f8cf18f165f05f1cf20936aaad06a15287de3f578891197647ca05c7df4","title":"InSpec Profile","maintainer":"The Authors","summary":"An InSpec Compliance Profile","license":"Apache-2.0","copyright":"The Authors","copyright_email":"you@example.com","supports":[{"os-family":"bds"},{"os-name":"mac_os_x","release":"17.*"}],"attributes":[],"groups":[{"id":"controls/example.rb","controls":["(generated from example.rb:7 871cd54043069c5c4f6e382fd5627830)","tmp-1.0","(generated from example.rb:21 2ff474c5357e7070f4c3efa932032dcb)"],"title":"sample section"},{"id":"controls/run_command.rb","controls":["(generated from run_command.rb:5 a411d4ded1530b2f48170840e1127584)"]}],"controls":[{"id":"(generated from example.rb:7 871cd54043069c5c4f6e382fd5627830)","title":null,"desc":null,"descriptions":[],"impact":0.5,"refs":[],"tags":{},"code":"","source_location":{"line":89,"ref":"/Users/jquick/Chef/inspec/lib/inspec/control_eval_context.rb"},"waiver_data":{},"results":[{"status":"passed","code_desc":"File /tmp should be directory","run_time":0.002058,"start_time":"2018-01-05 11:43:04 -0500","resource_params":"","resource_id":"File /tmp"}]},{"id":"tmp-1.0","title":"Create /tmp directory","desc":"An optional description...","descriptions":[{"label":"default","data":"An optional description..."}],"impact":0.7,"refs":[],"tags":{},"code":"control 'tmp-1.0' do # A unique ID for this control\n impact 0.7 # The criticality, if this control fails.\n title 'Create /tmp directory' # A human-readable title\n desc 'An optional description...'\n describe file('/tmp') do # The actual test\n it { should be_directory }\n end\nend\n","waiver_data":{},"source_location":{"line":12,"ref":"../inspec-demo/_test/long_commands/controls/example.rb"},"results":[{"status":"passed","code_desc":"File /tmp should be directory","run_time":0.000102,"start_time":"2018-01-05 11:43:04 -0500","resource_params":"","resource_id":"File /tmp"}]},{"id":"(generated from example.rb:21 2ff474c5357e7070f4c3efa932032dcb)","title":null,"desc":null,"descriptions":[],"impact":0.5,"refs":[],"tags":{},"code":"","waiver_data":{},"source_location":{"line":89,"ref":"/Users/jquick/Chef/inspec/lib/inspec/control_eval_context.rb"},"results":[{"status":"failed","code_desc":"gem package rubocop should be installed","run_time":0.000168,"start_time":"2018-01-05 11:43:04 -0500","message":"rubocop is not installed","resource_params":"","resource_id":"gem package rubocop"}]},{"id":"(generated from run_command.rb:5 a411d4ded1530b2f48170840e1127584)","title":null,"desc":null,"descriptions":[],"impact":0.5,"refs":[],"tags":{},"code":"","waiver_data":{},"source_location":{"line":89,"ref":"/Users/jquick/Chef/inspec/lib/inspec/control_eval_context.rb"},"results":[{"status":"passed","code_desc":"Command whoami stdout should eq \"jquick\\n\"","run_time":0.034938,"start_time":"2018-01-05 11:43:04 -0500","resource_params":"","resource_id":"stdout"}]}]}],"statistics":{"duration":0.039182},"version":"1.49.2"}

View file

@ -2,6 +2,7 @@
:platform: :platform:
:name: fedora :name: fedora
:release: '28' :release: '28'
:target_id: ''
:profiles: :profiles:
- :name: tests from t.rb - :name: tests from t.rb
:sha256: 9260af15d2b7568443df4d9d2556f773f425f92491c97eb1d201c535c7a9f5e0 :sha256: 9260af15d2b7568443df4d9d2556f773f425f92491c97eb1d201c535c7a9f5e0

View file

@ -2,6 +2,7 @@
:platform: :platform:
:name: fedora :name: fedora
:release: '28' :release: '28'
:target_id: ''
:profiles: :profiles:
- :name: tests from t.rb - :name: tests from t.rb
:sha256: 9260af15d2b7568443df4d9d2556f773f425f92491c97eb1d201c535c7a9f5e0 :sha256: 9260af15d2b7568443df4d9d2556f773f425f92491c97eb1d201c535c7a9f5e0

View file

@ -2,6 +2,7 @@
:platform: :platform:
:name: fedora :name: fedora
:release: '28' :release: '28'
:target_id: ''
:profiles: :profiles:
- :name: tests from t.rb - :name: tests from t.rb
:sha256: 9260af15d2b7568443df4d9d2556f773f425f92491c97eb1d201c535c7a9f5e0 :sha256: 9260af15d2b7568443df4d9d2556f773f425f92491c97eb1d201c535c7a9f5e0

View file

@ -168,7 +168,7 @@ describe "running profiles with git-based dependencies" do
it "should use default HEAD branch" do it "should use default HEAD branch" do
inspec("exec #{git_default_main_profile_url}") inspec("exec #{git_default_main_profile_url}")
assert_empty stderr assert_empty stderr
assert_includes stdout, "Profile: InSpec Profile (default-main)" assert_includes stdout, "Profile: InSpec Profile (default-main)"
assert_includes stdout, "Profile Summary: 1 successful control, 0 control failures, 0 controls skipped\n" assert_includes stdout, "Profile Summary: 1 successful control, 0 control failures, 0 controls skipped\n"
assert_includes stdout, "Test Summary: 2 successful, 0 failures, 0 skipped\n" assert_includes stdout, "Test Summary: 2 successful, 0 failures, 0 skipped\n"
assert_exit_code 0, out assert_exit_code 0, out

View file

@ -210,7 +210,14 @@ module FunctionalHelper
if opts[:json] && !run_result.stdout.empty? if opts[:json] && !run_result.stdout.empty?
begin begin
@json = JSON.parse(run_result.stdout) out = run_result.stdout.split("\n")
if out.count > 1
@deprication_msg = out[1].include?("The --target-id option is deprecated in InSpec 5") ? out[0] : nil
out = out[1]
else
out = out[0]
end
@json = JSON.parse(out)
rescue JSON::ParserError => e rescue JSON::ParserError => e
warn "JSON PARSE ERROR: %s" % [e.message] warn "JSON PARSE ERROR: %s" % [e.message]
warn "OUT: <<%s>>" % [run_result.stdout] warn "OUT: <<%s>>" % [run_result.stdout]

View file

@ -49,7 +49,8 @@ describe "inspec exec with json formatter" do
it "can execute a profile and validate the json schema and override the tagret id with platform uuid" do it "can execute a profile and validate the json schema and override the tagret id with platform uuid" do
skip_windows! skip_windows!
out = inspec("exec " + complete_profile + " --reporter json --no-create-lockfile --target-id 1d3e399f-4d71-4863-ac54-84d437fbc444") out = inspec("exec " + complete_profile + " --reporter json --no-create-lockfile --target-id 1d3e399f-4d71-4863-ac54-84d437fbc444")
data = JSON.parse(out.stdout) _(out.stdout).must_include "The --target-id option is deprecated in InSpec 5. Its value will be ignored"
data = JSON.parse(out.stdout.split("\n")[1])
_(data["platform"]["target_id"]).wont_equal "1d3e399f-4d71-4863-ac54-84d437fbc444" _(data["platform"]["target_id"]).wont_equal "1d3e399f-4d71-4863-ac54-84d437fbc444"
_(data["platform"]["target_id"]).must_equal platform_uuid _(data["platform"]["target_id"]).must_equal platform_uuid
sout = inspec("schema exec-json") sout = inspec("schema exec-json")

View file

@ -59,15 +59,11 @@ describe "inspec exec" do
it "executes a minimum metadata-only profile" do it "executes a minimum metadata-only profile" do
inspec("exec " + File.join(profile_path, "simple-metadata") + " --no-create-lockfile") inspec("exec " + File.join(profile_path, "simple-metadata") + " --no-create-lockfile")
_(stdout).must_equal " _(stdout).must_include "Profile: yumyum profile"
Profile: yumyum profile _(stdout).must_include "Version: (not specified)"
Version: (not specified) _(stdout).must_include "Target: local://"
Target: local:// _(stdout).must_include "No tests executed."
_(stdout).must_include "Test Summary: 0 successful, 0 failures, 0 skipped"
No tests executed.
Test Summary: 0 successful, 0 failures, 0 skipped
"
_(stderr).must_equal "" _(stderr).must_equal ""
assert_exit_code 0, out assert_exit_code 0, out
@ -115,10 +111,12 @@ Test Summary: 0 successful, 0 failures, 0 skipped
assert_exit_code 0, out assert_exit_code 0, out
end end
it "can execute the profile with a target_id passthrough" do it "shows deprecation warning for --target-id opition ignore the its value." do
skip_windows!
inspec("exec #{complete_profile} --no-create-lockfile --target-id 1d3e399f-4d71-4863-ac54-84d437fbc444") inspec("exec #{complete_profile} --no-create-lockfile --target-id 1d3e399f-4d71-4863-ac54-84d437fbc444")
_(stdout).must_include "Target ID: 1d3e399f-4d71-4863-ac54-84d437fbc444" _(stdout).must_include "The --target-id option is deprecated in InSpec 5. Its value will be ignored."
_(stdout).must_include "Target ID: #{inspec_os_uuid}"
_(stderr).must_equal "" _(stderr).must_equal ""
@ -127,17 +125,11 @@ Test Summary: 0 successful, 0 failures, 0 skipped
it "executes a metadata-only profile" do it "executes a metadata-only profile" do
inspec("exec " + File.join(profile_path, "complete-metadata") + " --no-create-lockfile") inspec("exec " + File.join(profile_path, "complete-metadata") + " --no-create-lockfile")
_(stdout).must_include "Profile: title (name)"
_(stdout).must_equal " _(stdout).must_include "Target: local://"
Profile: title (name) _(stdout).must_include "Version: 1.2.3"
Version: 1.2.3 _(stdout).must_include "No tests executed."
Target: local:// _(stdout).must_include "Test Summary: 0 successful, 0 failures, 0 skipped\n"
No tests executed.
Test Summary: 0 successful, 0 failures, 0 skipped
"
_(stderr).must_equal "" _(stderr).must_equal ""
assert_exit_code 0, out assert_exit_code 0, out
@ -155,7 +147,7 @@ Test Summary: 0 successful, 0 failures, 0 skipped
it "executes a specs-only profile" do it "executes a specs-only profile" do
inspec("exec " + File.join(profile_path, "spec_only") + " --no-create-lockfile") inspec("exec " + File.join(profile_path, "spec_only") + " --no-create-lockfile")
_(stdout).must_include "Target: local://" _(stdout).must_include "Target: local://"
_(stdout).must_include "working" _(stdout).must_include "working"
_(stdout).must_include "✔ is expected to eq \"working\"" _(stdout).must_include "✔ is expected to eq \"working\""
_(stdout).must_include "skippy\n" _(stdout).must_include "skippy\n"
@ -528,17 +520,12 @@ Test Summary: 0 successful, 0 failures, 0 skipped
describe "with a profile that inherits core resource into custom reosuce" do describe "with a profile that inherits core resource into custom reosuce" do
let(:out) { inspec("exec " + File.join(profile_path, "custom-resource-inheritance") + " --no-create-lockfile") } let(:out) { inspec("exec " + File.join(profile_path, "custom-resource-inheritance") + " --no-create-lockfile") }
it "executes the custom resoruc without error" do it "executes the custom resoruc without error" do
_(stdout).must_equal " _(stdout).must_include "Profile: InSpec Profile (custom-resource-inheritance)"
Profile: InSpec Profile (custom-resource-inheritance) _(stdout).must_include "Version: 0.1.0"
Version: 0.1.0 _(stdout).must_include "local://"
Target: local:// _(stdout).must_include "✔ name is expected to eq \"hello\""
_(stdout).must_include "✔ [\"meta\", \"creator\"] is expected to eq \"John Doe\""
Node Json _(stdout).must_include "Test Summary: 2 successful, 0 failures, 0 skipped"
name is expected to eq \"hello\"
[\"meta\", \"creator\"] is expected to eq \"John Doe\"
Test Summary: 2 successful, 0 failures, 0 skipped
"
_(stderr).must_equal "" _(stderr).must_equal ""
assert_exit_code 0, out assert_exit_code 0, out
end end
@ -548,19 +535,13 @@ Test Summary: 2 successful, 0 failures, 0 skipped
let(:out) { inspec("exec " + example_control + " --no-create-lockfile") } let(:out) { inspec("exec " + example_control + " --no-create-lockfile") }
it "prints the control results, then the anonymous describe block results" do it "prints the control results, then the anonymous describe block results" do
_(stdout).must_match(/Profile: tests from .*test.fixtures.profiles.old-examples.profile.controls.example-tmp.rb/) _(stdout).must_include("test.fixtures.profiles.old-examples.profile.controls.example-tmp.rb")
_(stdout).must_include " _(stdout).must_include "Version: (not specified)"
Version: (not specified) _(stdout).must_include "Target: local://"
Target: local:// _(stdout).must_include "✔ tmp-1.0: Create / directory"
_(stdout).must_include "✔ File / is expected to be directory"
\xE2\x9C\x94 tmp-1.0: Create / directory _(stdout).must_include "Profile Summary: 1 successful control, 0 control failures, 0 controls skipped"
\xE2\x9C\x94 File / is expected to be directory _(stdout).must_include "Test Summary: 2 successful, 0 failures, 0 skipped\n"
File /
\xE2\x9C\x94 is expected to be directory
Profile Summary: 1 successful control, 0 control failures, 0 controls skipped
Test Summary: 2 successful, 0 failures, 0 skipped\n"
end end
end end
@ -1003,7 +984,7 @@ Test Summary: 2 successful, 0 failures, 0 skipped\n"
describe "when using the legacy --json-config" do describe "when using the legacy --json-config" do
let(:cli_args) { "--json-config " + File.join(config_dir_path, "json-config", "good.json") } let(:cli_args) { "--json-config " + File.join(config_dir_path, "json-config", "good.json") }
it "should override the custom target ID value with platform uuid" do it "should ignore the custom target ID value and override it with platform uuid" do
skip_windows! skip_windows!
_(stderr).must_be_empty # TODO: one day deprecate the --json-config option _(stderr).must_be_empty # TODO: one day deprecate the --json-config option
_(seen_target_id).wont_equal "from-config-file" _(seen_target_id).wont_equal "from-config-file"
@ -1172,8 +1153,8 @@ Test Summary: 2 successful, 0 failures, 0 skipped\n"
describe "when a target URI with a known credset is used" do describe "when a target URI with a known credset is used" do
let(:cli_args) { "--target mock://mycredset" + " --config " + File.join(config_dir_path, "json-config", "mock-credset.json") } let(:cli_args) { "--target mock://mycredset" + " --config " + File.join(config_dir_path, "json-config", "mock-credset.json") }
it "should connect to the mock platform" do it "should connect to the mock platform and ignore the target_id set in the config file." do
_(seen_platform).must_equal({ "name" => "mock", "release" => "unknown", "target_id" => "from-mock-credset-config-file" }) _(seen_platform).must_equal({ "name" => "mock", "release" => "unknown", "target_id" => "" })
end end
end end
end end

View file

@ -41,13 +41,7 @@ describe Inspec::Reporters::CLI do
describe "#print_profile_header" do describe "#print_profile_header" do
it "confirm header output" do it "confirm header output" do
expected = <<~EOF _(report.send(:print_profile_header, profile)).must_equal "Profile: InSpec Profile (long_commands)\nVersion: 0.1.0\nTarget: local://\nTarget ID: \n\n"
Profile: InSpec Profile (long_commands)
Version: 0.1.0
Target: local://
EOF
_(report.send(:print_profile_header, profile)).must_equal expected
end end
end end

View file

@ -27,7 +27,7 @@ describe Inspec::Reporters::Json do
describe "#platform" do describe "#platform" do
it "confirm platform output" do it "confirm platform output" do
hash = { name: "mac_os_x", release: "17.2.0" } hash = { name: "mac_os_x", release: "17.2.0", target_id: "" }
_(report.send(:platform)).must_equal hash _(report.send(:platform)).must_equal hash
end end
end end