Commit b3164346 authored by Thong Kuah's avatar Thong Kuah

Move LB call in Auth to Core

parent 7ff1e6f8
......@@ -14,13 +14,6 @@ module EE
super
end
override :find_build_by_token
def find_build_by_token(token)
::Gitlab::Database::LoadBalancing::Session.current.use_primary do
super
end
end
end
end
end
......@@ -25,24 +25,4 @@ RSpec.describe Gitlab::Auth do
expect( gl_auth.find_with_user_password(username, password) ).to eql user
end
end
describe '#build_access_token_check' do
subject { gl_auth.find_for_git_client('gitlab-ci-token', build.token, project: build.project, ip: '1.2.3.4') }
context 'for running build' do
let!(:build) { create(:ci_build, :running, user: user) }
it 'executes query using primary database' do
expect(Ci::Build).to receive(:find_by_token).with(build.token).and_wrap_original do |m, *args|
expect(::Gitlab::Database::LoadBalancing::Session.current.use_primary?).to eq(true)
m.call(*args)
end
expect(subject).to be_a(Gitlab::Auth::Result)
expect(subject.actor).to eq(user)
expect(subject.project).to eq(build.project)
expect(subject.type).to eq(:build)
end
end
end
end
......@@ -371,7 +371,9 @@ module Gitlab
end
def find_build_by_token(token)
::Ci::AuthJobFinder.new(token: token).execute
::Gitlab::Database::LoadBalancing::Session.current.use_primary do
::Ci::AuthJobFinder.new(token: token).execute
end
end
def user_auth_attempt!(user, success:)
......
......@@ -683,6 +683,28 @@ RSpec.describe Gitlab::Auth, :use_clean_rails_memory_store_caching do
end
end
describe '#build_access_token_check' do
subject { gl_auth.find_for_git_client('gitlab-ci-token', build.token, project: build.project, ip: '1.2.3.4') }
let_it_be(:user) { create(:user) }
context 'for running build' do
let!(:build) { create(:ci_build, :running, user: user) }
it 'executes query using primary database' do
expect(Ci::Build).to receive(:find_by_token).with(build.token).and_wrap_original do |m, *args|
expect(::Gitlab::Database::LoadBalancing::Session.current.use_primary?).to eq(true)
m.call(*args)
end
expect(subject).to be_a(Gitlab::Auth::Result)
expect(subject.actor).to eq(user)
expect(subject.project).to eq(build.project)
expect(subject.type).to eq(:build)
end
end
end
describe 'find_with_user_password' do
let!(:user) do
create(:user,
......
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