diff --git a/test/fixtures/profiles/inputs/required/controls/required.rb b/test/fixtures/profiles/inputs/required/controls/required.rb new file mode 100644 index 000000000..438b51a0e --- /dev/null +++ b/test/fixtures/profiles/inputs/required/controls/required.rb @@ -0,0 +1,14 @@ + +control 'start_marker' do + describe('dummy_test_01') do + it { should cmp 'dummy_test_01'} + end +end + +discard_me = input('required_01') + +control 'end_marker' do + describe('dummy_test_04') do + it { should cmp 'dummy_test_04'} + end +end diff --git a/test/fixtures/profiles/inputs/required/files/inputs.yaml b/test/fixtures/profiles/inputs/required/files/inputs.yaml new file mode 100644 index 000000000..46945bfcf --- /dev/null +++ b/test/fixtures/profiles/inputs/required/files/inputs.yaml @@ -0,0 +1 @@ +required_01: "required_01" diff --git a/test/fixtures/profiles/inputs/required/inspec.yml b/test/fixtures/profiles/inputs/required/inspec.yml new file mode 100644 index 000000000..f0009c8c9 --- /dev/null +++ b/test/fixtures/profiles/inputs/required/inspec.yml @@ -0,0 +1,13 @@ +name: required_inputs +title: InSpec Profile +maintainer: The Authors +copyright: The Authors +copyright_email: you@example.com +license: Apache-2.0 +summary: A profile mentioning an input in a control file that is required +version: 0.1.0 + +inputs: + - name: required_01 + required: true + type: string diff --git a/test/fixtures/profiles/inputs/undeclared/files/inputs.yaml b/test/fixtures/profiles/inputs/undeclared/files/inputs.yaml deleted file mode 100644 index 8e52f0c69..000000000 --- a/test/fixtures/profiles/inputs/undeclared/files/inputs.yaml +++ /dev/null @@ -1,5 +0,0 @@ -undeclared_00: "undeclared_00" -undeclared_01: "undeclared_01" -undeclared_02: "undeclared_02" -undeclared_03: "undeclared_03" -undeclared_04: "undeclared_04" diff --git a/test/fixtures/profiles/inputs/undeclared/inspec.yml b/test/fixtures/profiles/inputs/undeclared/inspec.yml index 178286276..32725e419 100644 --- a/test/fixtures/profiles/inputs/undeclared/inspec.yml +++ b/test/fixtures/profiles/inputs/undeclared/inspec.yml @@ -6,20 +6,3 @@ copyright_email: you@example.com license: Apache-2.0 summary: A profile mentioning an attribute in a control file that has not otherwise been mentioned version: 0.1.0 - -inputs: - - name: undeclared_00 - required: true - type: string - - name: undeclared_01 - required: true - type: string - - name: undeclared_02 - required: true - type: string - - name: undeclared_03 - required: true - type: string - - name: undeclared_04 - required: true - type: string diff --git a/test/functional/inputs_test.rb b/test/functional/inputs_test.rb index 2644cf864..f13cd122b 100644 --- a/test/functional/inputs_test.rb +++ b/test/functional/inputs_test.rb @@ -293,16 +293,39 @@ describe "inputs" do assert_json_controls_passing(result) end end + # Addresses https://github.com/inspec/inspec/issues/4769 - describe "when using a profile with undeclared (valueless) inputs and an input file" do - it "should not warn and run normally" do - cmd = "exec #{inputs_profiles_path}/undeclared --input-file #{inputs_profiles_path}/undeclared/files/inputs.yaml" + describe "when using a profile with required inputs" do + describe "when the values are not provided" do + it "should emit an error and exit code 1" do + cmd = "exec #{inputs_profiles_path}/required" - result = run_inspec_process(cmd, json: true) + result = run_inspec_process(cmd, json: true) - _(result.stderr).must_be_empty - assert_json_controls_passing(result) + _(result.stderr).must_include "Input 'required_01'" + _(result.stderr).must_include "does not have a value" + assert_exit_code 1, result + end + end + describe "when the values are provided by an input file" do + it "should not warn and run normally" do + cmd = "exec #{inputs_profiles_path}/required --input-file #{inputs_profiles_path}/required/files/inputs.yaml" + + result = run_inspec_process(cmd, json: true) + + _(result.stderr).must_be_empty + assert_json_controls_passing(result) + end + end + describe "when the values are provided by a CLI flag" do + it "should not warn and run normally" do + cmd = "exec #{inputs_profiles_path}/required --input required_01=anything" + + result = run_inspec_process(cmd, json: true) + + _(result.stderr).must_be_empty + assert_json_controls_passing(result) + end end end - end