mirror of
https://github.com/inspec/inspec
synced 2024-11-23 21:23:29 +00:00
fix metadata validation
This commit is contained in:
parent
cfa2b9a39c
commit
526932584d
2 changed files with 10 additions and 8 deletions
|
@ -95,26 +95,27 @@ module Inspec
|
||||||
}
|
}
|
||||||
|
|
||||||
@logger.info "Checking profile in #{@path}"
|
@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?
|
if Pathname.new(path).join('metadata.rb').exist?
|
||||||
warn.call('The use of `metadata.rb` is deprecated. Use `inspec.yml`.')
|
warn.call('The use of `metadata.rb` is deprecated. Use `inspec.yml`.')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@logger.info 'Metadata OK.' if @metadata.valid?
|
||||||
|
|
||||||
# check if the profile is using the old test directory instead of the
|
# check if the profile is using the old test directory instead of the
|
||||||
# new controls directory
|
# new controls directory
|
||||||
if Pathname.new(path).join('test').exist? && !Pathname.new(path).join('controls').exist?
|
if Pathname.new(path).join('test').exist? && !Pathname.new(path).join('controls').exist?
|
||||||
warn.call('Profile uses deprecated `test` directory, rename it to `controls`')
|
warn.call('Profile uses deprecated `test` directory, rename it to `controls`')
|
||||||
end
|
end
|
||||||
|
|
||||||
no_warnings = true
|
rules_counter = @params[:rules].values.map { |hm| hm.values.length }.inject(:+)
|
||||||
if @params[:rules].empty?
|
if rules_counter.nil? || rules_counter == 0
|
||||||
warn.call('No rules were found.')
|
warn.call('No controls or tests were defined.')
|
||||||
|
else
|
||||||
|
@logger.debug("Found #{rules_counter} rules.")
|
||||||
end
|
end
|
||||||
|
|
||||||
# iterate over hash of groups
|
# iterate over hash of groups
|
||||||
rules_counter = 0
|
|
||||||
@params[:rules].each do |group, rules_array|
|
@params[:rules].each do |group, rules_array|
|
||||||
@logger.debug "Verify all rules in #{group}"
|
@logger.debug "Verify all rules in #{group}"
|
||||||
rules_array.each do |id, rule|
|
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 > 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 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?
|
warn.call("Rule #{id} has no tests defined") if rule[:checks].nil? or rule[:checks].empty?
|
||||||
rules_counter += 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@logger.debug "Found #{rules_counter} rules."
|
|
||||||
|
|
||||||
@logger.info 'Rule definitions OK.' if no_warnings
|
@logger.info 'Rule definitions OK.' if no_warnings
|
||||||
no_errors
|
no_errors
|
||||||
|
|
|
@ -55,6 +55,7 @@ describe Inspec::Profile do
|
||||||
|
|
||||||
it 'prints loads of warnings' do
|
it 'prints loads of warnings' do
|
||||||
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/empty"]
|
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 name in metadata.rb']
|
||||||
logger.expect :error, nil, ['Missing profile version in metadata.rb']
|
logger.expect :error, nil, ['Missing profile version in metadata.rb']
|
||||||
logger.expect :warn, nil, ['Missing profile title 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
|
it 'prints ok messages' do
|
||||||
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/complete-meta"]
|
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 :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.']
|
logger.expect :warn, nil, ['No controls or tests were defined.']
|
||||||
|
|
||||||
profile.check
|
profile.check
|
||||||
|
|
Loading…
Reference in a new issue