fix metadata validation

This commit is contained in:
Dominik Richter 2015-12-28 13:30:42 +01:00
parent cfa2b9a39c
commit 526932584d
2 changed files with 10 additions and 8 deletions

View file

@ -95,26 +95,27 @@ module Inspec
}
@logger.info "Checking profile in #{@path}"
@logger.info 'Metadata OK.' if @metadata.valid?
# check if deprecated metadata.rb exists
if Pathname.new(path).join('metadata.rb').exist?
warn.call('The use of `metadata.rb` is deprecated. Use `inspec.yml`.')
end
@logger.info 'Metadata OK.' if @metadata.valid?
# check if the profile is using the old test directory instead of the
# new controls directory
if Pathname.new(path).join('test').exist? && !Pathname.new(path).join('controls').exist?
warn.call('Profile uses deprecated `test` directory, rename it to `controls`')
end
no_warnings = true
if @params[:rules].empty?
warn.call('No rules were found.')
rules_counter = @params[:rules].values.map { |hm| hm.values.length }.inject(:+)
if rules_counter.nil? || rules_counter == 0
warn.call('No controls or tests were defined.')
else
@logger.debug("Found #{rules_counter} rules.")
end
# iterate over hash of groups
rules_counter = 0
@params[:rules].each do |group, rules_array|
@logger.debug "Verify all rules in #{group}"
rules_array.each do |id, rule|
@ -125,10 +126,8 @@ module Inspec
warn.call("Rule #{id} has impact > 1.0") if rule[:impact].to_f > 1.0
warn.call("Rule #{id} has impact < 0.0") if rule[:impact].to_f < 0.0
warn.call("Rule #{id} has no tests defined") if rule[:checks].nil? or rule[:checks].empty?
rules_counter += 1
end
end
@logger.debug "Found #{rules_counter} rules."
@logger.info 'Rule definitions OK.' if no_warnings
no_errors

View file

@ -55,6 +55,7 @@ describe Inspec::Profile do
it 'prints loads of warnings' do
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/empty"]
logger.expect :warn, nil, ['The use of `metadata.rb` is deprecated. Use `inspec.yml`.']
logger.expect :error, nil, ['Missing profile name in metadata.rb']
logger.expect :error, nil, ['Missing profile version in metadata.rb']
logger.expect :warn, nil, ['Missing profile title in metadata.rb']
@ -73,7 +74,9 @@ describe Inspec::Profile do
it 'prints ok messages' do
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/complete-meta"]
logger.expect :warn, nil, ['The use of `metadata.rb` is deprecated. Use `inspec.yml`.']
logger.expect :info, nil, ['Metadata OK.']
logger.expect :warn, nil, ["Profile uses deprecated `test` directory, rename it to `controls`"]
logger.expect :warn, nil, ['No controls or tests were defined.']
profile.check