explicitly ignore supports for inspec check

This commit is contained in:
Christoph Hartmann 2016-01-10 23:59:57 -05:00
parent a26dbe146d
commit a1ddbe4cf2
5 changed files with 22 additions and 22 deletions

View file

@ -73,6 +73,7 @@ class InspecCLI < Thor # rubocop:disable Metrics/ClassLength
o = opts.dup o = opts.dup
o[:logger] = Logger.new(STDOUT) o[:logger] = Logger.new(STDOUT)
o[:ignore_supports] = true # we check for integrety only
profile = Inspec::Profile.from_path(path, o) profile = Inspec::Profile.from_path(path, o)
exit 1 unless profile.check exit 1 unless profile.check
end end

View file

@ -86,10 +86,6 @@ module Inspec
end end
def supports_transport?(backend) 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 # make sure the supports field is always an array
supp = params[:supports] supp = params[:supports]
supp = supp.is_a?(Hash) ? [supp] : Array(supp) supp = supp.is_a?(Hash) ? [supp] : Array(supp)

View file

@ -38,8 +38,7 @@ module Inspec
id: @profile_id, id: @profile_id,
backend: :mock, backend: :mock,
) )
@runner.add_tests([@path], @options)
@runner.add_tests([@path])
@runner.rules.each do |id, rule| @runner.rules.each do |id, rule|
file = rule.instance_variable_get(:@__file) file = rule.instance_variable_get(:@__file)
rules[file] ||= {} rules[file] ||= {}

View file

@ -47,22 +47,22 @@ module Inspec
@backend = Inspec::Backend.create(@conf) @backend = Inspec::Backend.create(@conf)
end end
def add_test_profile(test) def add_test_profile(test, ignore_supports = false)
assets = Inspec::Targets.resolve(test, @conf) assets = Inspec::Targets.resolve(test, @conf)
meta_assets = assets.find_all { |a| a[:type] == :metadata } meta_assets = assets.find_all { |a| a[:type] == :metadata }
metas = meta_assets.map do |x| metas = meta_assets.map do |x|
Inspec::Metadata.from_ref(x[:ref], x[:content], @profile_id, @conf[:logger]) Inspec::Metadata.from_ref(x[:ref], x[:content], @profile_id, @conf[:logger])
end end
metas.each do |meta| metas.each do |meta|
return [] unless meta.supports_transport?(@backend) return [] if !ignore_supports && !meta.supports_transport?(@backend)
end end
assets assets
end end
def add_tests(tests) def add_tests(tests, options = {})
# retrieve the raw ruby code of all tests # retrieve the raw ruby code of all tests
items = tests.map do |test| items = tests.map do |test|
add_test_profile(test) add_test_profile(test, options[:ignore_supports])
end.flatten end.flatten
tests = items.find_all { |i| i[:type] == :test } tests = items.find_all { |i| i[:type] == :test }

View file

@ -11,7 +11,7 @@ describe Inspec::Profile do
# currently it's stopped at test runner conflicts # currently it's stopped at test runner conflicts
class Inspec::Profile::Runner class Inspec::Profile::Runner
def initialize(opts) end def initialize(opts) end
def add_tests(tests) end def add_tests(tests, options=nil) end
def rules def rules
{} {}
end end
@ -85,18 +85,22 @@ describe Inspec::Profile do
end end
describe 'a complete metadata profile with controls' do 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
# 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, ["Checking profile in #{home}/mock/profiles/complete-profile"] logger.expect :info, nil, ['Metadata OK.']
# 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, ['Found 1 rules.']
# logger.expect :info, nil, ['Rule definitions OK.'] # logger.expect :info, nil, ['Rule definitions OK.']
#
# profile.check profile.check
# logger.verify logger.verify
# end end
end end
end end
end end