summaryrefslogtreecommitdiff
path: root/spec/functional
diff options
context:
space:
mode:
authorNimesh-Msys <nimesh.patni@msystechnologies.com>2019-01-30 15:01:55 +0530
committerTim Smith <tsmith@chef.io>2019-02-05 15:12:24 -0800
commit11aeff603ac2e2a494021e58979e6dc1eb78e5e1 (patch)
treebc6fd74137c3064ecce62d816fcfdb96faacab2f /spec/functional
parentb7f36e0937f3fe554aa750b563a00c988cf3fc83 (diff)
downloadchef-11aeff603ac2e2a494021e58979e6dc1eb78e5e1.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.rb61
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