Skip to content

Commit

Permalink
Updating validation when creating or editing a provider's endpoint.
Browse files Browse the repository at this point in the history
A regression was created when introducing multiple provider endpoints.
The function for updating authentications was not updated to update when changing
the endpoints and authentications.
This commit updates the authentication is this cases.

Issue:
ManageIQ#7256
  • Loading branch information
Yaacov Zamir authored and yaacov committed Sep 9, 2016
1 parent 0a518f3 commit 7840799
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/models/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ def add_connection_configuration_by_role(connection)
connection.delete(:authentication)
else
unless connection[:authentication].key?(:role)
connection[:authentication][:role] ||= "default"
endpoint_role = connection[:endpoint][:role]
authentication_role = endpoint_role == "default" ? default_authentication_type.to_s : endpoint_role
connection[:authentication][:role] ||= authentication_role
end
end

Expand Down
28 changes: 27 additions & 1 deletion spec/models/ext_management_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,44 @@
end
end

context "with multiple endpoints using default authtype" do
context "with multiple endpoints using explicit authtype" do
let(:ems) do
FactoryGirl.build(:ems_openshift,
:connection_configurations => [{:endpoint => {:role => "default",
:hostname => "openshift.example.org"},
:authentication => {:role => "bearer",
:auth_key => "SomeSecret"}},
{:endpoint => {:role => "hawkular",
:hostname => "openshift.example.org"},
:authentication => {:role => "hawkular",
:auth_key => "SomeSecret"}}])
end

it "will contain the bearer authentication as default" do
expect(ems.connection_configuration_by_role("default").authentication.authtype).to eq("bearer")
end
it "will contain the hawkular authentication as hawkular" do
expect(ems.connection_configuration_by_role("hawkular").authentication.authtype).to eq("hawkular")
end
end

context "with multiple endpoints using implicit default authtype" do
let(:ems) do
FactoryGirl.build(:ems_openshift,
:connection_configurations => [{:endpoint => {:role => "default",
:hostname => "openshift.example.org"},
:authentication => {:auth_key => "SomeSecret"}},
{:endpoint => {:role => "hawkular",
:hostname => "openshift.example.org"},
:authentication => {:auth_key => "SomeSecret"}}])
end

it "will contain the default authentication (bearer) for default endpoint" do
expect(ems.connection_configuration_by_role("default").authentication.authtype).to eq("bearer")
end
it "will contain the hawkular authentication for the hawkular endpoint" do
expect(ems.connection_configuration_by_role("hawkular").authentication.authtype).to eq("hawkular")
end
end

context "with two small envs" do
Expand Down
52 changes: 52 additions & 0 deletions spec/requests/api/providers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@
}
}
end
let(:updated_connection) do
{
"endpoint" => {
"role" => "default",
"hostname" => "sample_openshift_multi_end_point.provider.com",
"port" => "8443"
},
"authentication" => {
"role" => "bearer",
"auth_key" => SecureRandom.hex
}
}
end
let(:hawkular_connection) do
{
"endpoint" => {
Expand Down Expand Up @@ -340,6 +353,45 @@ def token(connection)
expect(provider.authentication_userid).to eq("superadmin")
end

it "does not schedule a new credentials check if endpoint does not change" do
api_basic_authorize collection_action_identifier(:providers, :edit)

provider = FactoryGirl.create(:ext_management_system, sample_openshift_multi_end_point)
MiqQueue.where(:method_name => "authentication_check_types",
:class_name => "ExtManagementSystem",
:instance_id => provider.id).delete_all

run_post(providers_url(provider.id), gen_request(:edit,
"connection_configurations" => [default_connection,
hawkular_connection]))

queue_jobs = MiqQueue.where(:method_name => "authentication_check_types",
:class_name => "ExtManagementSystem",
:instance_id => provider.id)
expect(queue_jobs).to be
expect(queue_jobs.length).to eq(0)
end

it "schedules a new credentials check if endpoint change" do
api_basic_authorize collection_action_identifier(:providers, :edit)

provider = FactoryGirl.create(:ext_management_system, sample_openshift_multi_end_point)
MiqQueue.where(:method_name => "authentication_check_types",
:class_name => "ExtManagementSystem",
:instance_id => provider.id).delete_all

run_post(providers_url(provider.id), gen_request(:edit,
"connection_configurations" => [updated_connection,
hawkular_connection]))

queue_jobs = MiqQueue.where(:method_name => "authentication_check_types",
:class_name => "ExtManagementSystem",
:instance_id => provider.id)
expect(queue_jobs).to be
expect(queue_jobs.length).to eq(1)
expect(queue_jobs[0].args[0][0]).to eq(:bearer)
end

it "supports additions of credentials" do
api_basic_authorize collection_action_identifier(:providers, :edit)

Expand Down

0 comments on commit 7840799

Please sign in to comment.