mirror of
https://github.com/inspec/inspec
synced 2024-11-23 05:03:07 +00:00
explicitly ignore supports for inspec check
This commit is contained in:
parent
a26dbe146d
commit
a1ddbe4cf2
5 changed files with 22 additions and 22 deletions
|
@ -73,6 +73,7 @@ class InspecCLI < Thor # rubocop:disable Metrics/ClassLength
|
|||
|
||||
o = opts.dup
|
||||
o[:logger] = Logger.new(STDOUT)
|
||||
o[:ignore_supports] = true # we check for integrety only
|
||||
profile = Inspec::Profile.from_path(path, o)
|
||||
exit 1 unless profile.check
|
||||
end
|
||||
|
|
|
@ -86,10 +86,6 @@ module Inspec
|
|||
end
|
||||
|
||||
def supports_transport?(backend)
|
||||
# make a happy face when presented the mock backend
|
||||
# FIXME(sr) this is not beautiful
|
||||
return true if backend.backend.is_a? Train::Transports::Mock::Connection
|
||||
|
||||
# make sure the supports field is always an array
|
||||
supp = params[:supports]
|
||||
supp = supp.is_a?(Hash) ? [supp] : Array(supp)
|
||||
|
|
|
@ -38,8 +38,7 @@ module Inspec
|
|||
id: @profile_id,
|
||||
backend: :mock,
|
||||
)
|
||||
|
||||
@runner.add_tests([@path])
|
||||
@runner.add_tests([@path], @options)
|
||||
@runner.rules.each do |id, rule|
|
||||
file = rule.instance_variable_get(:@__file)
|
||||
rules[file] ||= {}
|
||||
|
|
|
@ -47,22 +47,22 @@ module Inspec
|
|||
@backend = Inspec::Backend.create(@conf)
|
||||
end
|
||||
|
||||
def add_test_profile(test)
|
||||
def add_test_profile(test, ignore_supports = false)
|
||||
assets = Inspec::Targets.resolve(test, @conf)
|
||||
meta_assets = assets.find_all { |a| a[:type] == :metadata }
|
||||
metas = meta_assets.map do |x|
|
||||
Inspec::Metadata.from_ref(x[:ref], x[:content], @profile_id, @conf[:logger])
|
||||
end
|
||||
metas.each do |meta|
|
||||
return [] unless meta.supports_transport?(@backend)
|
||||
return [] if !ignore_supports && !meta.supports_transport?(@backend)
|
||||
end
|
||||
assets
|
||||
end
|
||||
|
||||
def add_tests(tests)
|
||||
def add_tests(tests, options = {})
|
||||
# retrieve the raw ruby code of all tests
|
||||
items = tests.map do |test|
|
||||
add_test_profile(test)
|
||||
add_test_profile(test, options[:ignore_supports])
|
||||
end.flatten
|
||||
|
||||
tests = items.find_all { |i| i[:type] == :test }
|
||||
|
|
|
@ -11,7 +11,7 @@ describe Inspec::Profile do
|
|||
# currently it's stopped at test runner conflicts
|
||||
class Inspec::Profile::Runner
|
||||
def initialize(opts) end
|
||||
def add_tests(tests) end
|
||||
def add_tests(tests, options=nil) end
|
||||
def rules
|
||||
{}
|
||||
end
|
||||
|
@ -85,18 +85,22 @@ describe Inspec::Profile do
|
|||
end
|
||||
|
||||
describe 'a complete metadata profile with controls' do
|
||||
let(:profile) { load_profile('complete-profile', {logger: logger}) }
|
||||
let(:profile) { load_profile('complete-profile', {logger: logger, ignore_supports: true}) }
|
||||
|
||||
# TODO(sr): this test fails, while it works on the command line
|
||||
# it 'prints ok messages and counts the rules' do
|
||||
# logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/complete-profile"]
|
||||
# logger.expect :info, nil, ['Metadata OK.']
|
||||
it 'prints ok messages and counts the rules' do
|
||||
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/complete-profile"]
|
||||
logger.expect :info, nil, ['Metadata OK.']
|
||||
|
||||
# TODO: cannot load rspec in unit tests, therefore we get a loading warn
|
||||
# RSpec does not work with minitest tests
|
||||
logger.expect :warn, nil, ['No controls or tests were defined.']
|
||||
# we expect that this should work:
|
||||
# logger.expect :info, nil, ['Found 1 rules.']
|
||||
# logger.expect :info, nil, ['Rule definitions OK.']
|
||||
#
|
||||
# profile.check
|
||||
# logger.verify
|
||||
# end
|
||||
|
||||
profile.check
|
||||
logger.verify
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue