From 70bfdf25cf7862ddb6aa53d17311ea3fe3fabd9c Mon Sep 17 00:00:00 2001 From: John McCrae Date: Mon, 9 May 2022 19:22:57 +0600 Subject: Updated windows_certificate resource to account for bugs and updates in the win32-certstore gem Signed-off-by: John McCrae --- .../resource/windows_certificate_spec.rb | 27 ++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'spec') diff --git a/spec/functional/resource/windows_certificate_spec.rb b/spec/functional/resource/windows_certificate_spec.rb index df2d1cbec8..9552d559b3 100644 --- a/spec/functional/resource/windows_certificate_spec.rb +++ b/spec/functional/resource/windows_certificate_spec.rb @@ -89,7 +89,9 @@ describe Chef::Resource::WindowsCertificate, :windows_only do end - after { delete_store } + after do + delete_store + end describe "action: create" do it "starts with no certificates" do @@ -195,7 +197,7 @@ describe Chef::Resource::WindowsCertificate, :windows_only do create_store end it "fails with no certificates in the store" do - expect(Chef::Log).to receive(:info).with("Certificate not found") + expect(Chef::Log).to receive(:info).with("Certificate not valid") resource.source = tests_thumbprint resource.run_action(:verify) @@ -219,7 +221,7 @@ describe Chef::Resource::WindowsCertificate, :windows_only do end it "fails with an invalid thumbprint" do - expect(Chef::Log).to receive(:info).with("Certificate not found") + expect(Chef::Log).to receive(:info).with("Certificate not valid") resource.source = others_thumbprint resource.run_action(:verify) @@ -253,7 +255,7 @@ describe Chef::Resource::WindowsCertificate, :windows_only do end it "fails with an invalid thumbprint" do - expect(Chef::Log).to receive(:info).with("Certificate not found") + expect(Chef::Log).to receive(:info).with("Certificate not valid") resource.source = others_thumbprint resource.run_action(:verify) @@ -265,11 +267,11 @@ describe Chef::Resource::WindowsCertificate, :windows_only do describe "action: fetch" do context "with no certificate in the store" do - it "throws an error with no certificates in the store" do - expect(Chef::Log).not_to receive(:info) + it "logs a debug error with no certificates in the store" do + expect(Chef::Log).to receive(:debug).with("Certificate Not Found") resource.source = others_thumbprint resource.output_path = cert_output_path - expect { resource.run_action :fetch }.to raise_error(ArgumentError) + resource.run_action(:fetch) end end @@ -288,7 +290,7 @@ describe Chef::Resource::WindowsCertificate, :windows_only do end it "fails with an invalid thumbprint" do - expect(Chef::Log).not_to receive(:info) + expect(Chef::Log).to receive(:debug).with("Certificate Not Found") resource.source = others_thumbprint @@ -296,7 +298,7 @@ describe Chef::Resource::WindowsCertificate, :windows_only do path = File.join(dir, "test.pem") resource.output_path = path - expect { resource.run_action :fetch }.to raise_error(ArgumentError) + resource.run_action(:fetch) end end @@ -340,9 +342,10 @@ describe Chef::Resource::WindowsCertificate, :windows_only do end describe "action: delete" do - it "throws an argument error when attempting to delete a certificate that doesn't exist" do + it "logs an error when attempting to delete a certificate that doesn't exist" do + expect(Chef::Log).to receive(:debug).with("Certificate Not Found") resource.source = tests_thumbprint - expect { resource.run_action :delete }.to raise_error(ArgumentError) + resource.run_action(:delete) end it "deletes an existing certificate while leaving other certificates alone" do @@ -360,7 +363,7 @@ describe Chef::Resource::WindowsCertificate, :windows_only do expect(certificate_count).to eq(1) expect(resource).to be_updated_by_last_action - expect { resource.run_action :delete }.to raise_error(ArgumentError) + expect { resource.run_action :delete }.not_to raise_error expect(certificate_count).to eq(1) expect(resource).not_to be_updated_by_last_action -- cgit v1.2.1