2018-09-12 20:42:58 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
require 'functional/helper'
|
|
|
|
|
|
|
|
describe 'attributes' do
|
|
|
|
include FunctionalHelper
|
2019-02-08 23:23:01 +00:00
|
|
|
let(:inputs_profiles_path) { File.join(profile_path, 'inputs') }
|
2018-09-12 20:42:58 +00:00
|
|
|
[
|
|
|
|
'flat',
|
|
|
|
'nested',
|
2019-02-08 23:23:01 +00:00
|
|
|
].each do |input_file|
|
|
|
|
it "runs OK on #{input_file} attributes" 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-02-08 23:23:01 +00:00
|
|
|
cmd += ' --attrs ' + File.join(inputs_profiles_path, 'basic', 'files', "#{input_file}.yaml")
|
|
|
|
cmd += ' --controls ' + input_file
|
2018-09-12 20:42:58 +00:00
|
|
|
out = inspec(cmd)
|
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'run profile with yaml attributes' do
|
|
|
|
it "runs using yml attributes" do
|
|
|
|
cmd = 'exec '
|
2019-02-08 23:23:01 +00:00
|
|
|
cmd += File.join(inputs_profiles_path, 'global')
|
2018-09-12 20:42:58 +00:00
|
|
|
cmd += ' --no-create-lockfile'
|
2019-02-08 23:23:01 +00:00
|
|
|
cmd += ' --attrs ' + File.join(inputs_profiles_path, 'global', 'files', "inputs.yml")
|
2018-09-12 20:42:58 +00:00
|
|
|
out = inspec(cmd)
|
|
|
|
out.stderr.must_equal ''
|
2018-10-03 05:57:25 +00:00
|
|
|
out.stdout.must_include '21 successful'
|
2018-09-12 20:42:58 +00:00
|
|
|
out.exit_status.must_equal 0
|
|
|
|
end
|
|
|
|
|
2018-10-11 13:41:36 +00:00
|
|
|
it "does not error when attributes are empty" do
|
|
|
|
cmd = 'exec '
|
2019-02-08 23:23:01 +00:00
|
|
|
cmd += File.join(inputs_profiles_path, 'metadata-empty')
|
2018-10-11 13:41:36 +00:00
|
|
|
cmd += ' --no-create-lockfile'
|
|
|
|
out = inspec(cmd)
|
2019-02-12 04:13:50 +00:00
|
|
|
out.stdout.must_include 'WARN: Inputs must be defined as an Array. Skipping current definition.'
|
2018-10-11 13:41:36 +00:00
|
|
|
out.exit_status.must_equal 0
|
|
|
|
end
|
|
|
|
|
2018-09-12 20:42:58 +00:00
|
|
|
it "errors with invalid attribute types" do
|
|
|
|
cmd = 'exec '
|
2019-02-08 23:23:01 +00:00
|
|
|
cmd += File.join(inputs_profiles_path, 'metadata-invalid')
|
2018-09-12 20:42:58 +00:00
|
|
|
cmd += ' --no-create-lockfile'
|
|
|
|
out = inspec(cmd)
|
|
|
|
out.stderr.must_equal "Type 'Color' is not a valid attribute type.\n"
|
|
|
|
out.stdout.must_equal ''
|
|
|
|
out.exit_status.must_equal 1
|
|
|
|
end
|
|
|
|
|
|
|
|
it "errors with required attribute not defined" do
|
|
|
|
cmd = 'exec '
|
2019-02-08 23:23:01 +00:00
|
|
|
cmd += File.join(inputs_profiles_path, 'required')
|
2018-09-12 20:42:58 +00:00
|
|
|
cmd += ' --no-create-lockfile'
|
|
|
|
out = inspec(cmd)
|
2019-02-12 04:13:50 +00:00
|
|
|
out.stderr.must_equal "Input 'username' is required and does not have a value.\n"
|
2018-09-12 20:42:58 +00:00
|
|
|
out.stdout.must_equal ''
|
|
|
|
out.exit_status.must_equal 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|