Commit a3023011 authored by Alex Kalderimis's avatar Alex Kalderimis

Deal with dynamic method dispatch

parent 8f0eabed
......@@ -46,6 +46,10 @@ class Integration < ApplicationRecord
datadog discord drone_ci
].to_set.freeze
def self.renamed?(name)
RENAMED_TO_INTEGRATION.include?(name)
end
serialize :properties, JSON # rubocop:disable Cop/ActiveRecordSerialize
attribute :type, Gitlab::Integrations::StiType.new
......
......@@ -146,6 +146,14 @@ class Project < ApplicationRecord
has_one :last_event, -> {order 'events.created_at DESC'}, class_name: 'Event'
has_many :boards
def self.integration_association(name)
if ::Integration.renamed?(name)
"#{name}_integration"
else
"#{name}_service"
end
end
# Project integrations
has_one :asana_integration, class_name: 'Integrations::Asana'
has_one :assembla_integration, class_name: 'Integrations::Assembla'
......
......@@ -156,15 +156,15 @@ module Gitlab
underscored_service = matched_login['service'].underscore
if Integration.available_services_names.include?(underscored_service)
# We treat underscored_service as a trusted input because it is included
# in the Integration.available_services_names allowlist.
service = project.public_send("#{underscored_service}_service") # rubocop:disable GitlabSecurity/PublicSend
return unless Integration.available_services_names.include?(underscored_service)
if service && service.activated? && service.valid_token?(password)
Gitlab::Auth::Result.new(nil, project, :ci, build_authentication_abilities)
end
end
# We treat underscored_service as a trusted input because it is included
# in the Integration.available_services_names allowlist.
service = project.public_send(Project.integration_association(underscored_service)) # rubocop:disable GitlabSecurity/PublicSend
return unless service && service.activated? && service.valid_token?(password)
Gitlab::Auth::Result.new(nil, project, :ci, build_authentication_abilities)
end
def user_with_password_for_git(login, password)
......
......@@ -197,7 +197,7 @@ RSpec.describe Gitlab::Auth, :use_clean_rails_memory_store_caching do
it 'recognizes other ci services' do
project.create_drone_ci_integration(active: true)
project.drone_ci_integration.update!(token: 'token')
project.drone_ci_integration.update(token: 'token')
expect(gl_auth.find_for_git_client('drone-ci-token', 'token', project: project, ip: 'ip')).to eq(Gitlab::Auth::Result.new(nil, project, :ci, described_class.build_authentication_abilities))
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment