Fix error on empty attributes yaml (#3485)

* Allow empty attributes param.
* Add warning if invalid attributes.

Signed-off-by: Jared Quick <jquick@chef.io>
This commit is contained in:
Jared Quick 2018-10-11 09:41:36 -04:00 committed by GitHub
parent 3780298111
commit ba37ca1875
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View file

@ -126,12 +126,14 @@ module Inspec
end
def register_metadata_attributes
if metadata.params.key?(:attributes)
if metadata.params.key?(:attributes) && metadata.params[:attributes].is_a?(Array)
metadata.params[:attributes].each do |attribute|
attr_dup = attribute.dup
name = attr_dup.delete(:name)
@runner_context.register_attribute(name, attr_dup)
end
elsif metadata.params.key?(:attributes)
Inspec::Log.warn 'Attributes must be defined as an Array. Skipping current definition.'
end
end

View file

@ -33,6 +33,15 @@ describe 'attributes' do
out.exit_status.must_equal 0
end
it "does not error when attributes are empty" do
cmd = 'exec '
cmd += File.join(profile_path, 'profile-with-empty-attributes')
cmd += ' --no-create-lockfile'
out = inspec(cmd)
out.stdout.must_include 'WARN: Attributes must be defined as an Array. Skipping current definition.'
out.exit_status.must_equal 0
end
it "errors with invalid attribute types" do
cmd = 'exec '
cmd += File.join(profile_path, 'invalid_attributes')

View file

@ -0,0 +1,9 @@
name: profile-with-empty-attributes
title: InSpec Profile
maintainer: The Authors
copyright: The Authors
copyright_email: you@example.com
license: Apache-2.0
summary: An InSpec Compliance Profile
version: 0.1.0
attributes: