diff options
author | Pete Higgins <pete@peterhiggins.org> | 2020-11-05 16:28:58 -0800 |
---|---|---|
committer | Pete Higgins <pete@peterhiggins.org> | 2020-12-01 16:05:17 -0800 |
commit | 9ef4b3620de3f085aeb042ec2ec7582621c319a7 (patch) | |
tree | aec76fd51bbef07cf18a623c0d3523dbc1c3f799 | |
parent | 800204e692552746c18c2176909691f96ad4e684 (diff) | |
download | chef-9ef4b3620de3f085aeb042ec2ec7582621c319a7.tar.gz |
Fill in pending specs for audit runner's #enabled? method.
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
-rw-r--r-- | spec/unit/audit/runner_spec.rb | 61 |
1 files changed, 55 insertions, 6 deletions
diff --git a/spec/unit/audit/runner_spec.rb b/spec/unit/audit/runner_spec.rb index 2b100a33a8..fadfceb3c0 100644 --- a/spec/unit/audit/runner_spec.rb +++ b/spec/unit/audit/runner_spec.rb @@ -1,14 +1,63 @@ require "spec_helper" describe Chef::Audit::Runner do + let(:test_class) do + Class.new(Chef::Audit::Runner) do + def initialize(run_status = nil) + @run_status = run_status + end + end + end + describe "#enabled?" do - before do - # stub logger + let(:cookbook_collection) { Chef::CookbookCollection.new } + let(:event_dispatcher) { Chef::EventDispatch::Dispatcher.new } + let(:node) { Chef::Node.new(logger: double(:logger).as_null_object) } + let(:run_context) { Chef::RunContext.new(node, cookbook_collection, event_dispatcher) } + let(:run_status) do + Chef::RunStatus.new(node, event_dispatcher).tap do |rs| + rs.run_context = run_context + end + end + + let(:runner) { test_class.new(run_status) } + + it "is true if the node attributes have audit profiles and the audit cookbook is not present" do + node.default["audit"] = {} + node.default["audit"]["profiles"] = {} + node.default["audit"]["profiles"]["ssh"] = { 'compliance': "base/ssh" } + + expect(runner).to be_enabled end - it "is true if the node attributes have audit profiles and the audit cookbook is not present" - it "is false if the node attributes have audit profiles and the audit cookbook is present" - it "is false if the node attributes do not have audit profiles and the audit cookbook is not present" - it "is false if the node attributes do not have audit profiles and the audit cookbook is present" + it "is false if the node attributes have audit profiles and the audit cookbook is present" do + node.default["audit"] = {} + node.default["audit"]["profiles"] = {} + node.default["audit"]["profiles"]["ssh"] = { 'compliance': "base/ssh" } + + cookbook_collection["audit"] = double(:audit_cookbook, version: "1.2.3") + + 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.default["audit"] = {} + node.default["audit"]["profiles"] = {} + + 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.default["audit"] = {} + node.default["audit"]["profiles"] = {} + + cookbook_collection["audit"] = double(:audit_cookbook, version: "1.2.3") + + expect(runner).not_to be_enabled + end + + it "is false if the node attributes do not have audit attributes and the audit cookbook is not present" do + expect(runner).not_to be_enabled + end end end |