diff options
author | Nimesh-Msys <nimesh.patni@msystechnologies.com> | 2019-01-30 15:01:55 +0530 |
---|---|---|
committer | Nimesh-Msys <nimesh.patni@msystechnologies.com> | 2019-02-04 23:39:23 +0530 |
commit | b2f4b3daa75141580b45db91106f3ab51848c495 (patch) | |
tree | de95931bda1a57fd647012e8f2f0ef1079afae97 /spec/functional | |
parent | 0f4bd34e95111d755b646d85150698626e27fa3d (diff) | |
download | chef-b2f4b3daa75141580b45db91106f3ab51848c495.tar.gz |
Import PFX certificates with their private keys
- Using `add_pfx` of Win32::Certstore to import a PFX certificate with its thumbprint
- Using correct version of `win32-certstore` to support these changes
- Added Test cases
- Minor cleanup and opimization
Signed-off-by: Nimesh-Msys <nimesh.patni@msystechnologies.com>
Diffstat (limited to 'spec/functional')
-rw-r--r-- | spec/functional/resource/windows_certificate_spec.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/functional/resource/windows_certificate_spec.rb b/spec/functional/resource/windows_certificate_spec.rb index 188a0dc28d..f60b63ade9 100644 --- a/spec/functional/resource/windows_certificate_spec.rb +++ b/spec/functional/resource/windows_certificate_spec.rb @@ -61,6 +61,7 @@ describe Chef::Resource::WindowsCertificate, :windows_only, :appveyor_only do let(:certificate_path) { File.expand_path(File.join(CHEF_SPEC_DATA, "windows_certificates")) } let(:cer_path) { File.join(certificate_path, "test.cer") } let(:pem_path) { File.join(certificate_path, "test.pem") } + let(:pfx_path) { File.join(certificate_path, "test.pfx") } let(:out_path) { File.join(certificate_path, "testout.pem") } let(:tests_thumbprint) { "3180B3E3217862600BD7B2D28067B03D41576A4F" } let(:other_cer_path) { File.join(certificate_path, "othertest.cer") } @@ -157,6 +158,66 @@ describe Chef::Resource::WindowsCertificate, :windows_only, :appveyor_only do end end + describe "Works for various formats" do + context "Adds CER" do + before do + win_certificate.source = cer_path + win_certificate.run_action(:create) + end + it "Imports certificate into store" do + expect(no_of_certificates).to eq(1) + end + it "Idempotent: Does not converge while adding again" do + win_certificate.run_action(:create) + expect(no_of_certificates).to eq(1) + expect(win_certificate).not_to be_updated_by_last_action + end + end + + context "Adds PEM" do + before do + win_certificate.source = pem_path + win_certificate.run_action(:create) + end + it "Imports certificate into store" do + expect(no_of_certificates).to eq(1) + end + it "Idempotent: Does not converge while adding again" do + win_certificate.run_action(:create) + expect(no_of_certificates).to eq(1) + expect(win_certificate).not_to be_updated_by_last_action + end + end + + context "Adds PFX" do + context "With valid password" do + before do + win_certificate.source = pfx_path + win_certificate.pfx_password = password + win_certificate.run_action(:create) + end + it "Imports certificate into store" do + expect(no_of_certificates).to eq(1) + end + it "Idempotent: Does not converge while adding again" do + win_certificate.run_action(:create) + expect(no_of_certificates).to eq(1) + expect(win_certificate).not_to be_updated_by_last_action + end + end + + context "With Invalid password" do + before do + win_certificate.source = pfx_path + win_certificate.pfx_password = "Invalid password" + end + it "Raises an error" do + expect { win_certificate.run_action(:create) }.to raise_error(RuntimeError) + end + end + end + end + describe "action: verify" do context "When a certificate is not present" do before do |