mirror of
https://github.com/inspec/inspec
synced 2024-11-10 15:14:23 +00:00
Fix related to loading dependent profiles from a profile in shell
Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
This commit is contained in:
parent
b84d4607d6
commit
3eea2b055a
6 changed files with 40 additions and 4 deletions
|
@ -3,7 +3,7 @@ require "openssl" unless defined?(OpenSSL)
|
|||
module Inspec::Fetcher
|
||||
class Local < Inspec.fetcher(1)
|
||||
name "local"
|
||||
priority 0
|
||||
priority 1
|
||||
|
||||
def self.resolve(target)
|
||||
if target.is_a?(String)
|
||||
|
|
|
@ -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)
|
||||
|
|
2
test/fixtures/profiles/dependencies/shell-inheritance/controls/example.rb
vendored
Normal file
2
test/fixtures/profiles/dependencies/shell-inheritance/controls/example.rb
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
include_controls 'profile_a'
|
||||
include_controls 'profile_b'
|
12
test/fixtures/profiles/dependencies/shell-inheritance/inspec.yml
vendored
Normal file
12
test/fixtures/profiles/dependencies/shell-inheritance/inspec.yml
vendored
Normal 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
|
|
@ -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") }
|
||||
|
|
|
@ -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:"
|
||||
|
|
Loading…
Reference in a new issue