Merge pull request #5547 from inspec/nm/inspec-shell-depends

Fix related to loading dependent profiles from a profile in shell
This commit is contained in:
Clinton Wolfe 2021-06-03 23:23:48 -04:00 committed by GitHub
commit aaf0177ac8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 4 deletions

View file

@ -3,7 +3,8 @@ require "openssl" unless defined?(OpenSSL)
module Inspec::Fetcher
class Local < Inspec.fetcher(1)
name "local"
priority 0
priority 1
# Priority is used for setting precedence of fetchers. And registry plugin(v1) decides which fetcher to use for loading profiles by using this priority
def self.resolve(target)
if target.is_a?(String)

View file

@ -6,9 +6,11 @@ module Inspec::Fetcher
priority 0
def self.resolve(target)
return nil unless target.is_a? Hash
new(target)
if (target.is_a? Hash) && ((target.keys & %i{cwd path backend}).empty?)
new(target)
else
nil
end
end
def initialize(data)

View file

@ -0,0 +1,2 @@
include_controls 'profile_a'
include_controls 'profile_b'

View file

@ -0,0 +1,12 @@
name: Shell Inheritance
title: InSpec example of using inheritance profile in shell
maintainer: Chef Software, Inc.
copyright: Chef Software, Inc.
copyright_email: support@chef.io
license: Apache 2 license
version: 1.0.0
depends:
- name: profile_a
path: test/fixtures/profiles/dependencies/profile_a
- name: profile_b
path: test/fixtures/profiles/dependencies/profile_b

View file

@ -34,6 +34,7 @@ module FunctionalHelper
let(:meta_profile) { File.join(examples_path, "meta-profile") }
let(:example_control) { File.join(example_profile, "controls", "example-tmp.rb") }
let(:inheritance_profile) { File.join(examples_path, "inheritance") }
let(:shell_inheritance_profile) { File.join(repo_path, "test", "fixtures", "profiles", "dependencies", "shell-inheritance") }
let(:failure_control) { File.join(profile_path, "failures", "controls", "failures.rb") }
let(:simple_inheritance) { File.join(profile_path, "simple-inheritance") }
let(:sensitive_profile) { File.join(examples_path, "profile-sensitive") }

View file

@ -49,6 +49,16 @@ describe "inspec shell tests" do
assert_exit_code 0, res
end
it "loads a profile and its dependencies" do
res = inspec("shell -c 'example_config' --depends #{shell_inheritance_profile}")
_(res.stdout.chop).must_equal "example_config"
_(res.stderr).must_equal ""
assert_exit_code 0, res
end
it "confirm file caching is disabled" do
out = assert_shell_c("inspec.backend.cache_enabled?(:file)", 0)
@ -243,6 +253,15 @@ describe "inspec shell tests" do
assert_exit_code 0, res
end
it "loads a profile and its dependencies" do
cmd = "echo 'example_config' | #{exec_inspec} shell --depends #{shell_inheritance_profile}"
res = CMD.run_command(cmd)
_(res.stdout).must_include "=> example_config"
assert_exit_code 0, res
end
it "displays the target device information for the user without requiring the help command" do
out = do_shell("1+1")
_(out.stdout).must_include "You are currently running on:"