summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2021-01-19 20:47:36 -0800
committerGitHub <noreply@github.com>2021-01-19 20:47:36 -0800
commit3f4a16b4f037c19b745e01ee8c5dde4f5edee56a (patch)
tree134ba6dceb7d5cd470ad4c8bfed6c1b3651e3c2e
parent0e837894ed2bf801edffa1165f2be1e34d03d024 (diff)
parent3ebd3d7583f2cd4a625fb53454822aba55cf91ce (diff)
downloadchef-3f4a16b4f037c19b745e01ee8c5dde4f5edee56a.tar.gz
Merge pull request #10900 from chef/compliance_detection
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/compliance/runner.rb4
-rw-r--r--spec/unit/compliance/runner_spec.rb7
2 files changed, 6 insertions, 5 deletions
diff --git a/lib/chef/compliance/runner.rb b/lib/chef/compliance/runner.rb
index 5b7049e435..8ab80e11ff 100644
--- a/lib/chef/compliance/runner.rb
+++ b/lib/chef/compliance/runner.rb
@@ -16,7 +16,9 @@ class Chef
def_delegators :node, :logger
def enabled?
- audit_cookbook_present = node["recipes"].include?("audit::default")
+ # Did we parse the libraries file from the audit cookbook? This class dates back to when Chef Automate was
+ # renamed from Chef Visibility in 2017, so should capture all modern versions of the audit cookbook.
+ audit_cookbook_present = defined?(::Reporter::ChefAutomate)
logger.info("#{self.class}##{__method__}: #{Inspec::Dist::PRODUCT_NAME} profiles? #{inspec_profiles.any?}")
logger.info("#{self.class}##{__method__}: audit cookbook? #{audit_cookbook_present}")
diff --git a/spec/unit/compliance/runner_spec.rb b/spec/unit/compliance/runner_spec.rb
index 26c7008ccd..d982174e67 100644
--- a/spec/unit/compliance/runner_spec.rb
+++ b/spec/unit/compliance/runner_spec.rb
@@ -12,29 +12,28 @@ describe Chef::Compliance::Runner do
end
describe "#enabled?" do
+
it "is true if the node attributes have audit profiles and the audit cookbook is not present" do
node.normal["audit"]["profiles"]["ssh"] = { 'compliance': "base/ssh" }
- node.automatic["recipes"] = %w{ fancy_cookbook::fanciness tacobell::nachos }
expect(runner).to be_enabled
end
it "is false if the node attributes have audit profiles and the audit cookbook is present" do
+ stub_const("::Reporter::ChefAutomate", true)
node.normal["audit"]["profiles"]["ssh"] = { 'compliance': "base/ssh" }
- node.automatic["recipes"] = %w{ audit::default fancy_cookbook::fanciness tacobell::nachos }
expect(runner).not_to be_enabled
end
it "is false if the node attributes do not have audit profiles and the audit cookbook is not present" do
node.normal["audit"]["profiles"] = {}
- node.automatic["recipes"] = %w{ fancy_cookbook::fanciness tacobell::nachos }
expect(runner).not_to be_enabled
end
it "is false if the node attributes do not have audit profiles and the audit cookbook is present" do
- node.normal["audit"]["profiles"] = {}
+ stub_const("::Reporter::ChefAutomate", true)
node.automatic["recipes"] = %w{ audit::default fancy_cookbook::fanciness tacobell::nachos }
expect(runner).not_to be_enabled