Commit cf3015c4 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'move_lb_call_auth' into 'master'

Move LB call in Auth to Core

See merge request gitlab-org/gitlab!62750
parents 64729a37 b3164346
...@@ -14,13 +14,6 @@ module EE ...@@ -14,13 +14,6 @@ module EE
super super
end 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 end
end end
...@@ -25,24 +25,4 @@ RSpec.describe Gitlab::Auth do ...@@ -25,24 +25,4 @@ RSpec.describe Gitlab::Auth do
expect( gl_auth.find_with_user_password(username, password) ).to eql user expect( gl_auth.find_with_user_password(username, password) ).to eql user
end end
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 end
...@@ -371,7 +371,9 @@ module Gitlab ...@@ -371,7 +371,9 @@ module Gitlab
end end
def find_build_by_token(token) 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 end
def user_auth_attempt!(user, success:) def user_auth_attempt!(user, success:)
......
...@@ -683,6 +683,28 @@ RSpec.describe Gitlab::Auth, :use_clean_rails_memory_store_caching do ...@@ -683,6 +683,28 @@ RSpec.describe Gitlab::Auth, :use_clean_rails_memory_store_caching do
end end
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 describe 'find_with_user_password' do
let!(:user) do let!(:user) do
create(:user, 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