mirror of
https://github.com/inspec/inspec
synced 2024-09-21 15:02:01 +00:00
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:
commit
aaf0177ac8
6 changed files with 41 additions and 4 deletions
|
@ -3,7 +3,8 @@ require "openssl" unless defined?(OpenSSL)
|
||||||
module Inspec::Fetcher
|
module Inspec::Fetcher
|
||||||
class Local < Inspec.fetcher(1)
|
class Local < Inspec.fetcher(1)
|
||||||
name "local"
|
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)
|
def self.resolve(target)
|
||||||
if target.is_a?(String)
|
if target.is_a?(String)
|
||||||
|
|
|
@ -6,9 +6,11 @@ module Inspec::Fetcher
|
||||||
priority 0
|
priority 0
|
||||||
|
|
||||||
def self.resolve(target)
|
def self.resolve(target)
|
||||||
return nil unless target.is_a? Hash
|
if (target.is_a? Hash) && ((target.keys & %i{cwd path backend}).empty?)
|
||||||
|
new(target)
|
||||||
new(target)
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(data)
|
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(:meta_profile) { File.join(examples_path, "meta-profile") }
|
||||||
let(:example_control) { File.join(example_profile, "controls", "example-tmp.rb") }
|
let(:example_control) { File.join(example_profile, "controls", "example-tmp.rb") }
|
||||||
let(:inheritance_profile) { File.join(examples_path, "inheritance") }
|
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(:failure_control) { File.join(profile_path, "failures", "controls", "failures.rb") }
|
||||||
let(:simple_inheritance) { File.join(profile_path, "simple-inheritance") }
|
let(:simple_inheritance) { File.join(profile_path, "simple-inheritance") }
|
||||||
let(:sensitive_profile) { File.join(examples_path, "profile-sensitive") }
|
let(:sensitive_profile) { File.join(examples_path, "profile-sensitive") }
|
||||||
|
|
|
@ -49,6 +49,16 @@ describe "inspec shell tests" do
|
||||||
assert_exit_code 0, res
|
assert_exit_code 0, res
|
||||||
end
|
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
|
it "confirm file caching is disabled" do
|
||||||
out = assert_shell_c("inspec.backend.cache_enabled?(:file)", 0)
|
out = assert_shell_c("inspec.backend.cache_enabled?(:file)", 0)
|
||||||
|
|
||||||
|
@ -243,6 +253,15 @@ describe "inspec shell tests" do
|
||||||
assert_exit_code 0, res
|
assert_exit_code 0, res
|
||||||
end
|
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
|
it "displays the target device information for the user without requiring the help command" do
|
||||||
out = do_shell("1+1")
|
out = do_shell("1+1")
|
||||||
_(out.stdout).must_include "You are currently running on:"
|
_(out.stdout).must_include "You are currently running on:"
|
||||||
|
|
Loading…
Reference in a new issue