summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2021-01-14 09:40:26 -0800
committerGitHub <noreply@github.com>2021-01-14 09:40:26 -0800
commit6260497fc626ae173f894271410e6780e7d66544 (patch)
treeb0f2d4d72d2c4e000aa5e6b16318720cd3d51b25
parentdf81bcb2268574f4fee613d9ead64994ccccb561 (diff)
parent7419a2dca82c5f168da97c0f84cabeb5078b9411 (diff)
downloadchef-6260497fc626ae173f894271410e6780e7d66544.tar.gz
Merge pull request #10882 from chef/lcg/better-auditcb-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