diff options
-rw-r--r-- | lib/chef/compliance/runner.rb | 4 | ||||
-rw-r--r-- | spec/unit/compliance/runner_spec.rb | 7 |
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 |