Skip to content

Commit

Permalink
Add specs covering .verify_credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Mar 2, 2023
1 parent ce5a66f commit ffef9e4
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion spec/models/manageiq/providers/ovirt/infra_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
end
end

describe "verify_credentials" do
describe "#verify_credentials" do
let(:ems) { FactoryBot.create(:ems_ovirt) }

context "metrics" do
Expand Down Expand Up @@ -164,6 +164,61 @@
end
end

context ".verify_credentials" do
let(:default_authentication) { {"userid" => "user", "password" => "pword"} }
let(:default_endpoint) { {"hostname" => "ovirt.localdomain", "port" => 443} }
let(:metrics_authentication) { nil }
let(:metrics_endpoint) { nil }

let(:params) do
{
"endpoints" => {
"default" => default_endpoint,
"metrics" => metrics_endpoint
},
"authentications" => {
"default" => default_authentication,
"metrics" => metrics_authentication
}
}
end

it "calls check_connect_api" do
expect(described_class).to receive(:check_connect_api).with(hash_including(:username => "user", :password => "pword", :server => "ovirt.localdomain", :port => 443)).and_return(true)
described_class.verify_credentials(params)
end

context "with verify_ssl VERIFY_PEER" do
let(:default_endpoint) { {"hostname" => "ovirt.localdomain", "port" => 443, "verify_ssl" => OpenSSL::SSL::VERIFY_PEER} }

it "calls check_connect_api with verify_ssl" do
expect(described_class).to receive(:check_connect_api).with(hash_including(:verify_ssl => OpenSSL::SSL::VERIFY_PEER)).and_return(true)
described_class.verify_credentials(params)
end
end

context "with trusted CA certificates" do
let(:default_endpoint) { {"hostname" => "ovirt.localdomain", "port" => 443, "verify_ssl" => OpenSSL::SSL::VERIFY_PEER, "certificate_authority" => ca} }
let(:ca) { "----- BEGIN CERTIFICATE -----\n----- END CERTIFICATE -----\n" }

it "calls check_connect_api with verify_ssl" do
expect(described_class).to receive(:check_connect_api).with(hash_including(:verify_ssl => OpenSSL::SSL::VERIFY_PEER, :ca_certs => ca)).and_return(true)
described_class.verify_credentials(params)
end
end

context "with a metrics endpoint" do
let(:metrics_authentication) { {"userid" => "psql", "password" => "postgres"} }
let(:metrics_endpoint) { {"hostname" => "ovirt.localdomain", "port" => 5432, "path" => "ovirt_engine_history"} }

it "calls check_connect_api and check_connect_metrics" do
expect(described_class).to receive(:check_connect_api).with(hash_including(:username => "user", :password => "pword", :server => "ovirt.localdomain", :port => 443)).and_return(true)
expect(described_class).to receive(:check_connect_metrics).with(hash_including(:metrics_username => "psql", :metrics_password => "postgres", :metrics_server => "ovirt.localdomain", :metrics_port => 5432)).and_return(true)
described_class.verify_credentials(params)
end
end
end

context ".raw_connect" do
let(:options) do
{
Expand Down

0 comments on commit ffef9e4

Please sign in to comment.