summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordheerajd-msys <dheeraj.dubey@msystechnologies.com>2020-12-08 15:56:14 +0530
committerdheerajd-msys <dheeraj.dubey@msystechnologies.com>2020-12-08 15:56:14 +0530
commit1ca6cf92a5db2ba051efbd0f5314d13159101cc0 (patch)
tree2c8a57ad353ca13d6a01e500f7d29595b08bfeef
parent6af069a391a87096c678f63ddb31df2ac496e811 (diff)
downloadchef-1ca6cf92a5db2ba051efbd0f5314d13159101cc0.tar.gz
fix review and test case added
Signed-off-by: dheerajd-msys <dheeraj.dubey@msystechnologies.com>
-rw-r--r--lib/chef/resource/windows_certificate.rb9
-rw-r--r--spec/unit/resource/windows_certificate_spec.rb12
2 files changed, 17 insertions, 4 deletions
diff --git a/lib/chef/resource/windows_certificate.rb b/lib/chef/resource/windows_certificate.rb
index d264b66d8d..f357caf4ba 100644
--- a/lib/chef/resource/windows_certificate.rb
+++ b/lib/chef/resource/windows_certificate.rb
@@ -87,9 +87,9 @@ class Chef
description: "Ensure that sensitive resource data is not logged by the #{ChefUtils::Dist::Infra::CLIENT}.",
default: lazy { pfx_password ? true : false }, skip_docs: true
- property :exportable, Integer,
- description: "Ensure that imported pfx certificate is exportable. Please provide '1' if you want the certificate to be exportable."
- default: 0
+ property :exportable, [TrueClass, FalseClass],
+ description: "Ensure that imported pfx certificate is exportable. Please provide 'true' if you want the certificate to be exportable.",
+ default: false
action :create do
description "Creates or updates a certificate."
@@ -166,8 +166,9 @@ class Chef
end
def add_pfx_cert
+ exportable = new_resource.exportable ? 1 : 0
store = ::Win32::Certstore.open(new_resource.store_name)
- store.add_pfx(new_resource.source, new_resource.pfx_password, new_resource.exportable)
+ store.add_pfx(new_resource.source, new_resource.pfx_password, exportable)
end
def delete_cert
diff --git a/spec/unit/resource/windows_certificate_spec.rb b/spec/unit/resource/windows_certificate_spec.rb
index 7c0df35571..71ef8a9498 100644
--- a/spec/unit/resource/windows_certificate_spec.rb
+++ b/spec/unit/resource/windows_certificate_spec.rb
@@ -80,4 +80,16 @@ describe Chef::Resource::WindowsCertificate do
resource.store_name "MY"
expect { resource.action :create }.not_to raise_error
end
+
+ it "the exportable property defaults to false" do
+ expect(resource.exportable).to be false
+ end
+
+ it "doesn't raise error if exportable option is passed" do
+ resource.pfx_password "chef$123"
+ resource.source "C:\\certs\\test-cert.pfx"
+ resource.store_name "MY"
+ resource.exportable true
+ expect { resource.action :create }.not_to raise_error
+ end
end