Merge pull request #5135 from inspec/ns/input_equal_sign_5131

Allow ‘=‘ character in CLI inputs
This commit is contained in:
James Stocks 2020-07-09 14:36:43 +01:00 committed by GitHub
commit a461d42a85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 1 deletions

View file

@ -165,7 +165,8 @@ module Inspec
raise ArgumentError, "ERROR: An '=' is required when using --input. Usage: --input input_name1=input_value1 input2=value2"
end
end
input_name, input_value = pair.split("=")
pair = pair.match(/(.*?)=(.*)/)
input_name, input_value = pair[1], pair[2]
input_value = parse_cli_input_value(input_name, input_value)
evt = Inspec::Input::Event.new(
value: input_value,

View file

@ -0,0 +1,7 @@
title 'With various values'
control 'with equals sign' do
describe input(:my_input) do
it { should eq 'ab=cde' }
end
end

View file

@ -0,0 +1,8 @@
name: profile
title: InSpec Example Profile
maintainer: Chef Software, Inc.
copyright: Chef Software, Inc.
copyright_email: support@chef.io
license: Apache-2.0
summary: Demonstrates regressions for 5131
version: 1.0.0

View file

@ -32,6 +32,18 @@ describe "inspec exec" do
FileUtils.rm_f "#{prof}/simple-metadata/inspec.lock"
end
it "handles '=' character on input" do
# This test handles a bug discovered at: https://github.com/inspec/inspec/issues/5131
inspec(
"exec " +
File.join(profile_path, "inputs", "with_various_values") +
" --no-create-lockfile" +
" --input my_input='ab=cde'"
)
_(stdout).must_include "0 failures"
end
it "cleanly fails if mixing incompatible resource and transports" do
# TODO: I do not know how to test this more directly. It should be possible.
inspec "exec -t aws:// #{profile_path}/incompatible_resource_for_transport.rb"