From 25545606b7990b713dd8072e8cf3403f9a14a62a Mon Sep 17 00:00:00 2001 From: John McCrae Date: Wed, 23 Mar 2022 13:17:44 -0700 Subject: updating gemlock files and updating code from feedback Signed-off-by: John McCrae --- spec/unit/client_spec.rb | 13 +++++-------- spec/unit/http/authenticator_spec.rb | 22 +++++----------------- 2 files changed, 10 insertions(+), 25 deletions(-) (limited to 'spec/unit') diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index 1b8775e0d8..199ca7e9b6 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -291,6 +291,7 @@ describe Chef::Client, :windows_only do let(:hostname) { "test" } let(:my_client) { Chef::Client.new } let(:cert_name) { "chef-#{hostname}" } + let(:node_name) { "#{hostname}" } let(:end_date) do d = Time.now end_date = Time.new(d.year, d.month + 3, d.day, d.hour, d.min, d.sec).utc.iso8601 @@ -298,6 +299,7 @@ describe Chef::Client, :windows_only do # include_context "client" before(:each) do Chef::Config[:migrate_key_to_keystore] = true + Chef::Config[:node_name] = node_name end after(:each) do @@ -305,19 +307,14 @@ describe Chef::Client, :windows_only do end context "when the client intially boots the first time" do - it "created a new pfx object" do - expect(my_client.generate_pfx_package(cert_name, end_date)).to be_truthy - end - - it "verfies that a certificate correctly exists in the Cert Store" do + it "verfies that a certificate was correctly created and exists in the Cert Store" do my_client.generate_pfx_package(cert_name, end_date) expect(my_client.check_certstore_for_key(cert_name)).not_to be false end it "correctly returns a new Publc Key" do - my_client.generate_pfx_package(cert_name, end_date) - public_key = my_client.get_public_key(cert_name) - cert_object = OpenSSL::PKey::RSA.new(public_key) + 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/) end diff --git a/spec/unit/http/authenticator_spec.rb b/spec/unit/http/authenticator_spec.rb index 0bb81b8ca5..0ce5448d1a 100644 --- a/spec/unit/http/authenticator_spec.rb +++ b/spec/unit/http/authenticator_spec.rb @@ -28,14 +28,15 @@ describe Chef::HTTP::Authenticator, :windows_only do let(:node_name) { "test" } let(:passwrd) { "some_insecure_password" } - before(:each) do - ::Chef::Config[:node_name] = "test" + before do + Chef::Config[:node_name] = node_name cert_name = "chef-#{node_name}" d = Time.now end_date = Time.new(d.year, d.month + 3, d.day, d.hour, d.min, d.sec).utc.iso8601 my_client = Chef::Client.new - my_client.generate_pfx_package(cert_name, end_date) + pfx = my_client.generate_pfx_package(cert_name, end_date) + my_client.import_pfx_to_store(pfx) end after(:each) do @@ -57,25 +58,16 @@ describe Chef::HTTP::Authenticator, :windows_only do end it "retrieves a certificate password from the registry when the hive exists" do - set_registry_hive + class_instance.get_cert_password expect { class_instance.get_cert_password }.not_to raise_error end - it "correctly retrieves a private key from the certstore" do - cert_name = "chef-#{node_name}" - expect { class_instance.retrieve_certificate_key(cert_name) }.not_to raise_error - end - it "correctly retrieves a valid certificate in pem format from the certstore" do require "openssl" certificate = class_instance.retrieve_certificate_key(node_name) cert_object = OpenSSL::PKey::RSA.new(certificate) expect(cert_object.to_s).to match(/BEGIN RSA PRIVATE KEY/) end - - # does retrieving a cert work - # is the password at least 14 characters - # is the pem a proper cert object end def delete_certificate(cert_name) @@ -93,10 +85,6 @@ describe Chef::HTTP::Authenticator, :windows_only do @win32registry.delete_key(path, true) end end - - def set_registry_hive - class_instance.get_cert_password - end end describe Chef::HTTP::Authenticator do -- cgit v1.2.1