diff options
author | Marc A. Paradise <marc.paradise@gmail.com> | 2021-04-02 16:30:18 -0400 |
---|---|---|
committer | Marc A. Paradise <marc.paradise@gmail.com> | 2021-04-02 16:52:58 -0400 |
commit | 28b72c7b232ed273311e12b934f712e312a55437 (patch) | |
tree | d7c5863ee1fe962549dca1f86fd7782d934e4320 | |
parent | 1b24e25317391db444a4e2fc2e11e01b026ffe2c (diff) | |
download | chef-28b72c7b232ed273311e12b934f712e312a55437.tar.gz |
Report not enabled if the node is not available
The #enabled? method needs a node object to answer the question,
and the node object is not always available to it
(for example, run_failed when config is wrong).
Signed-off-by: Marc A. Paradise <marc.paradise@gmail.com>
-rw-r--r-- | lib/chef/compliance/runner.rb | 2 | ||||
-rw-r--r-- | spec/unit/compliance/runner_spec.rb | 6 |
2 files changed, 8 insertions, 0 deletions
diff --git a/lib/chef/compliance/runner.rb b/lib/chef/compliance/runner.rb index 50b8ff561a..c083109875 100644 --- a/lib/chef/compliance/runner.rb +++ b/lib/chef/compliance/runner.rb @@ -17,6 +17,8 @@ class Chef def_delegators :node, :logger def enabled? + return false if @node.nil? + # 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) diff --git a/spec/unit/compliance/runner_spec.rb b/spec/unit/compliance/runner_spec.rb index 66e21eb12e..c100029a2c 100644 --- a/spec/unit/compliance/runner_spec.rb +++ b/spec/unit/compliance/runner_spec.rb @@ -12,6 +12,12 @@ describe Chef::Compliance::Runner do end describe "#enabled?" do + context "when the node is not available" do + let(:runner) { described_class.new } + it "is false because it needs the node to answer that question" do + expect(runner).not_to be_enabled + end + end it "is true if the node attributes have audit profiles and the audit cookbook is not present, and the compliance mode attribute is nil" do node.normal["audit"]["profiles"]["ssh"] = { 'compliance': "base/ssh" } |