mirror of
https://github.com/inspec/inspec
synced 2024-11-10 23:24:18 +00:00
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:
parent
3780298111
commit
ba37ca1875
3 changed files with 21 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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:
|
Loading…
Reference in a new issue