2018-09-12 20:42:58 +00:00
|
|
|
|
|
|
|
require 'functional/helper'
|
|
|
|
|
2019-02-12 23:02:54 +00:00
|
|
|
describe 'inputs' do
|
2018-09-12 20:42:58 +00:00
|
|
|
include FunctionalHelper
|
2019-02-08 23:23:01 +00:00
|
|
|
let(:inputs_profiles_path) { File.join(profile_path, 'inputs') }
|
2019-03-07 18:52:03 +00:00
|
|
|
|
|
|
|
# This tests being able to load complex structures from
|
|
|
|
# cli option-specified files.
|
2018-09-12 20:42:58 +00:00
|
|
|
[
|
|
|
|
'flat',
|
2019-03-07 18:52:03 +00:00
|
|
|
'nested',
|
2019-02-08 23:23:01 +00:00
|
|
|
].each do |input_file|
|
2019-02-12 23:02:54 +00:00
|
|
|
it "runs OK on #{input_file} inputs" do
|
2018-09-12 20:42:58 +00:00
|
|
|
cmd = 'exec '
|
2019-02-08 23:23:01 +00:00
|
|
|
cmd += File.join(inputs_profiles_path, 'basic')
|
2018-09-12 20:42:58 +00:00
|
|
|
cmd += ' --no-create-lockfile'
|
2019-03-08 16:37:38 +00:00
|
|
|
cmd += ' --input-file ' + File.join(inputs_profiles_path, 'basic', 'files', "#{input_file}.yaml")
|
2019-02-08 23:23:01 +00:00
|
|
|
cmd += ' --controls ' + input_file
|
2019-02-26 02:05:18 +00:00
|
|
|
result = run_inspec_process(cmd)
|
|
|
|
result.stderr.must_equal ''
|
|
|
|
result.exit_status.must_equal 0
|
2018-09-12 20:42:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-08 16:37:38 +00:00
|
|
|
describe 'when asking for usage help' do
|
|
|
|
it 'includes the new --input-file option' do
|
|
|
|
result = run_inspec_process('exec help', lock: true) # --no-create-lockfile option breaks usage help
|
|
|
|
lines = result.stdout.split("\n")
|
|
|
|
line = lines.detect { |l| l.include? '--input-file' }
|
|
|
|
line.wont_be_nil
|
|
|
|
end
|
|
|
|
it 'includes the legacy --attrs option' do
|
|
|
|
result = run_inspec_process('exec help', lock: true)
|
|
|
|
lines = result.stdout.split("\n")
|
|
|
|
line = lines.detect { |l| l.include? '--attrs' }
|
|
|
|
line.wont_be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when using a cli-specified file' do
|
|
|
|
let(:result) do
|
|
|
|
cmd = 'exec '
|
|
|
|
cmd += File.join(inputs_profiles_path, 'basic') + ' '
|
|
|
|
cmd += flag + ' ' + File.join(inputs_profiles_path, 'basic', 'files', 'flat.yaml')
|
|
|
|
cmd += ' --controls flat'
|
|
|
|
run_inspec_process(cmd)
|
|
|
|
end
|
|
|
|
describe 'when the --input-file flag is used' do
|
|
|
|
let(:flag) { '--input-file' }
|
|
|
|
it 'works' do
|
|
|
|
result.exit_status.must_equal 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
describe 'when the --attrs flag is used' do
|
|
|
|
let(:flag) { '--attrs' }
|
|
|
|
it 'works' do
|
|
|
|
result.exit_status.must_equal 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-01 03:46:20 +00:00
|
|
|
describe 'when accessing inputs in a variety of scopes using the DSL' do
|
|
|
|
it "is able to read the inputs using the input keyword" do
|
|
|
|
cmd = "exec #{inputs_profiles_path}/scoping"
|
|
|
|
result = run_inspec_process(cmd, json: true)
|
|
|
|
result.must_have_all_controls_passing
|
|
|
|
end
|
|
|
|
it "is able to read the inputs using the legacy attribute keyword" do
|
|
|
|
cmd = "exec #{inputs_profiles_path}/legacy-attributes-dsl"
|
2019-03-07 18:52:03 +00:00
|
|
|
result = run_inspec_process(cmd, json: true)
|
|
|
|
result.must_have_all_controls_passing
|
2018-09-12 20:42:58 +00:00
|
|
|
end
|
2019-03-07 18:52:03 +00:00
|
|
|
end
|
2018-09-12 20:42:58 +00:00
|
|
|
|
2019-03-07 18:52:03 +00:00
|
|
|
describe 'run profile with metadata inputs' do
|
2019-02-12 23:02:54 +00:00
|
|
|
it "does not error when inputs are empty" do
|
2018-10-11 13:41:36 +00:00
|
|
|
cmd = 'exec '
|
2019-02-08 23:23:01 +00:00
|
|
|
cmd += File.join(inputs_profiles_path, 'metadata-empty')
|
2019-02-26 02:05:18 +00:00
|
|
|
result = run_inspec_process(cmd, json: true)
|
2019-03-07 18:52:03 +00:00
|
|
|
result.stderr.must_include 'WARN: Inputs must be defined as an Array. Skipping current definition.'
|
2019-02-26 02:05:18 +00:00
|
|
|
result.exit_status.must_equal 0
|
2018-10-11 13:41:36 +00:00
|
|
|
end
|
|
|
|
|
2019-02-12 23:02:54 +00:00
|
|
|
it "errors with invalid input types" do
|
2018-09-12 20:42:58 +00:00
|
|
|
cmd = 'exec '
|
2019-02-08 23:23:01 +00:00
|
|
|
cmd += File.join(inputs_profiles_path, 'metadata-invalid')
|
2019-02-26 02:05:18 +00:00
|
|
|
result = run_inspec_process(cmd, json: true)
|
|
|
|
result.stderr.must_equal "Type 'Color' is not a valid input type.\n"
|
|
|
|
result.exit_status.must_equal 1
|
2018-09-12 20:42:58 +00:00
|
|
|
end
|
|
|
|
|
2019-02-12 23:02:54 +00:00
|
|
|
it "errors with required input not defined" do
|
2018-09-12 20:42:58 +00:00
|
|
|
cmd = 'exec '
|
2019-03-07 18:52:03 +00:00
|
|
|
cmd += File.join(inputs_profiles_path, 'metadata-required')
|
2019-02-26 02:05:18 +00:00
|
|
|
result = run_inspec_process(cmd, json: true)
|
2019-03-07 18:52:03 +00:00
|
|
|
result.stderr.must_include "Input 'a_required_input' is required and does not have a value.\n"
|
2019-02-26 02:05:18 +00:00
|
|
|
result.exit_status.must_equal 1
|
2018-09-12 20:42:58 +00:00
|
|
|
end
|
2019-02-12 23:02:54 +00:00
|
|
|
|
2019-03-07 18:52:03 +00:00
|
|
|
describe 'when profile inheritance is used' do
|
|
|
|
it 'should correctly assign input values using namespacing' do
|
|
|
|
cmd = 'exec ' + File.join(inputs_profiles_path, 'inheritance', 'wrapper')
|
|
|
|
result = run_inspec_process(cmd, json: true)
|
|
|
|
result.must_have_all_controls_passing
|
|
|
|
end
|
|
|
|
end
|
2018-09-12 20:42:58 +00:00
|
|
|
end
|
2019-03-07 18:52:03 +00:00
|
|
|
|
2019-05-01 02:51:56 +00:00
|
|
|
describe 'when using a profile with undeclared (valueless) inputs' do
|
|
|
|
it 'should warn about them and not abort the run' do
|
|
|
|
cmd = "exec #{inputs_profiles_path}/undeclared"
|
|
|
|
result = run_inspec_process(cmd, json: true)
|
|
|
|
result.stderr.must_include "WARN: Input 'undeclared_01'"
|
|
|
|
result.stderr.must_include 'does not have a value'
|
|
|
|
result.must_have_all_controls_passing
|
|
|
|
end
|
2018-09-12 20:42:58 +00:00
|
|
|
end
|
|
|
|
end
|