Merge pull request #3770 from inspec/ja/fix-bad-name-check

More meaningful error when including controls from a missing dependency
This commit is contained in:
Clinton Wolfe 2019-01-31 16:14:35 -05:00 committed by GitHub
commit 761944b3ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 5 deletions

View file

@ -56,18 +56,18 @@ module Inspec::DSL
profile_id = opts[:profile_id]
dep_entry = dependencies.list[profile_id]
# do not load any controls if the profile is not supported
return unless dep_entry.profile.supports_platform?
if dep_entry.nil?
raise <<~EOF
Cannot load #{profile_id} since it is not listed as a dependency of #{bind_context.profile_name}.
Cannot load '#{profile_id}' since it is not listed as a dependency of #{bind_context.profile_name}.
Dependencies available from this context are:
#{dependencies.list.keys.join("\n ")}
EOF
end
# Do not load any controls if the profile is not supported
return unless dep_entry.profile.supports_platform?
context = dep_entry.profile.runner_context
# if we don't want all the rules, then just make 1 pass to get all rule_IDs
# that we want to keep from the original

View file

@ -88,6 +88,16 @@ describe 'inspec check' do
out.exit_status.must_equal 1
out.stdout.must_include 'inspec.yml and inspec.lock are out-of-sync. Please re-vendor with `inspec vendor`.'
out.stdout.must_include 'Cannot find linux-baseline in lockfile. Please re-vendor with `inspec vendor`.'
end
end
end
describe 'inspec check with invalid `include_controls` reference' do
it 'raises an error matching /Cannot load \'invalid_name\'/' do
invalid_profile = File.join(profile_path, 'invalid-include-controls')
out = inspec('check ' + invalid_profile)
out.exit_status.must_equal 1
out.stderr.must_match /Cannot load 'no_such_profile'/
out.stderr.must_match /not listed as a dependency/
end
end
end

View file

@ -0,0 +1,4 @@
# encoding: utf-8
# copyright: 2018, The Authors
include_controls 'no_such_profile'

View file

@ -0,0 +1,10 @@
name: invalid-include-controls
title: Invalid Include Controls
maintainer: The Authors
copyright: The Authors
copyright_email: humans@chef.io
license: Apache-2.0
summary: This profile contains an `include_controls` line with a invalid reference
version: 0.1.0
supports:
platform: os