summaryrefslogtreecommitdiff
path: root/spec/unit/client_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/client_spec.rb')
-rw-r--r--spec/unit/client_spec.rb28
1 files changed, 26 insertions, 2 deletions
diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb
index 7f02eacb39..ae11fd9793 100644
--- a/spec/unit/client_spec.rb
+++ b/spec/unit/client_spec.rb
@@ -310,25 +310,49 @@ describe Chef::Client, :windows_only do
end
context "when the client intially boots the first time" do
- it "verfies that a certificate was correctly created and exists in the Cert Store" do
+ it "verfies that a certificate was correctly created and exists in the LocalMachine Cert Store" do
+ Chef::Config[:node_name] = "test"
new_pfx = my_client.generate_pfx_package(cert_name, end_date)
my_client.import_pfx_to_store(new_pfx)
expect(my_client.check_certstore_for_key(cert_name)).not_to be false
+ delete_certificate(cert_name)
end
it "correctly returns a new Publc Key" do
new_pfx = my_client.generate_pfx_package(cert_name, end_date)
cert_object = new_pfx.certificate.public_key.to_pem
expect(cert_object.to_s).to match(/PUBLIC KEY/)
+ delete_certificate(cert_name)
+ end
+
+ end
+
+ context "when the client intially boots the first time and auth_key_registry_type is set to 'user' " do
+ it "verfies that a certificate was correctly created and exists in the CurrentUser Cert Store" do
+ Chef::Config[:node_name] = "test"
+ Chef::Config[:auth_key_registry_type] = "user"
+ new_pfx = my_client.generate_pfx_package(cert_name, end_date)
+ my_client.import_pfx_to_store(new_pfx)
+ expect(my_client.check_certstore_for_key(cert_name)).not_to be false
+ delete_certificate(cert_name)
+ end
+
+ it "correctly returns a new Publc Key" do
+ Chef::Config[:auth_key_registry_type] = "user"
+ new_pfx = my_client.generate_pfx_package(cert_name, end_date)
+ cert_object = new_pfx.certificate.public_key.to_pem
+ expect(cert_object.to_s).to match(/PUBLIC KEY/)
+ delete_certificate(cert_name)
end
end
def delete_certificate(cert_name)
+ Chef::Config[:auth_key_registry_type] == "user" ? store = "CurrentUser" : store = "LocalMachine"
require "chef/mixin/powershell_exec"
extend Chef::Mixin::PowershellExec
powershell_code = <<~CODE
- Get-ChildItem -path cert:\\LocalMachine\\My -Recurse -Force | Where-Object { $_.Subject -Match "#{cert_name}" } | Remove-item
+ Get-ChildItem -path cert:\\#{store}\\My -Recurse -Force | Where-Object { $_.Subject -Match "#{cert_name}" } | Remove-item
CODE
powershell_exec!(powershell_code)
end