Skip to content

Commit

Permalink
Replace instance_of(URI::HTTPS) with URI::HTTPS.build()
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Mar 6, 2024
1 parent dba6a48 commit 4988370
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,10 @@
let(:security_protocol) { "ssl-with-validation" }

before do
expected_uri = URI::HTTPS.build(:host => "kubernetes.local", :port => 6443)

allow(kubeclient_client).to receive(:discover)
allow(Kubeclient::Client).to receive(:new).with(instance_of(URI::HTTPS), "v1", anything).and_return(kubeclient_client)
allow(Kubeclient::Client).to receive(:new).with(expected_uri, "v1", anything).and_return(kubeclient_client)
end

context "with valid parameters" do
Expand All @@ -307,7 +309,8 @@
end

it "verifies ssl" do
expect(Kubeclient::Client).to receive(:new).with(instance_of(URI::HTTPS), "v1", hash_including(:ssl_options => hash_including(:verify_ssl => OpenSSL::SSL::VERIFY_PEER))).and_return(kubeclient_client)
expected_uri = URI::HTTPS.build(:host => "kubernetes.local", :port => 6443)
expect(Kubeclient::Client).to receive(:new).with(expected_uri, "v1", hash_including(:ssl_options => hash_including(:verify_ssl => OpenSSL::SSL::VERIFY_PEER))).and_return(kubeclient_client)

described_class.verify_credentials(params)
end
Expand All @@ -316,7 +319,8 @@
let(:security_protocol) { "ssl-without-validation" }

it "doesn't verify ssl" do
expect(Kubeclient::Client).to receive(:new).with(instance_of(URI::HTTPS), "v1", hash_including(:ssl_options => hash_including(:verify_ssl => OpenSSL::SSL::VERIFY_NONE))).and_return(kubeclient_client)
expected_uri = URI::HTTPS.build(:host => "kubernetes.local", :port => 6443)
expect(Kubeclient::Client).to receive(:new).with(expected_uri, "v1", hash_including(:ssl_options => hash_including(:verify_ssl => OpenSSL::SSL::VERIFY_NONE))).and_return(kubeclient_client)

described_class.verify_credentials(params)
end
Expand All @@ -328,10 +332,12 @@
let(:certificate_authority) { "-----BEGIN CERTIFICATE-----\n-----END CERTIFICATE-----" }

it "verifies ssl with a custom certificate_authority" do
expected_uri = URI::HTTPS.build(:host => "kubernetes.local", :port => 6443)

expect(Kubeclient::Client)
.to receive(:new)
.with(
instance_of(URI::HTTPS),
expected_uri,
"v1",
hash_including(:ssl_options => hash_including(:verify_ssl => OpenSSL::SSL::VERIFY_PEER, :ca_file => certificate_authority))
)
Expand All @@ -347,7 +353,8 @@
end

it "doesn't pass a proxy to Kubeclient" do
expect(Kubeclient::Client).to receive(:new).with(instance_of(URI::HTTPS), "v1", hash_including(:http_proxy_uri => nil)).and_return(kubeclient_client)
expected_uri = URI::HTTPS.build(:host => "kubernetes.local", :port => 6443)
expect(Kubeclient::Client).to receive(:new).with(expected_uri, "v1", hash_including(:http_proxy_uri => nil)).and_return(kubeclient_client)

described_class.verify_credentials(params)
end
Expand All @@ -359,7 +366,8 @@
end

it "passes the proxy info to Kubeclient" do
expect(Kubeclient::Client).to receive(:new).with(instance_of(URI::HTTPS), "v1", hash_including(:http_proxy_uri => instance_of(URI::Generic))).and_return(kubeclient_client)
expected_uri = URI::HTTPS.build(:host => "kubernetes.local", :port => 6443)
expect(Kubeclient::Client).to receive(:new).with(expected_uri, "v1", hash_including(:http_proxy_uri => instance_of(URI::Generic))).and_return(kubeclient_client)

described_class.verify_credentials(params)
end
Expand Down

0 comments on commit 4988370

Please sign in to comment.