Skip to content
代码片段 群组 项目
未验证 提交 e6cc4e90 编辑于 作者: Drew Blessing's avatar Drew Blessing
浏览文件

Refactor git http controllers to rely on auth results differently

Auth results can return an ambiguous actor, either user or
deploy token. Refactor to explicitly get user or deploy token
rather than accessing the actor directly.
上级 c3033257
No related branches found
No related tags found
无相关合并请求
...@@ -8,12 +8,9 @@ class GitHttpClientController < Repositories::ApplicationController ...@@ -8,12 +8,9 @@ class GitHttpClientController < Repositories::ApplicationController
attr_reader :authentication_result, :redirected_path attr_reader :authentication_result, :redirected_path
delegate :actor, :authentication_abilities, to: :authentication_result, allow_nil: true delegate :authentication_abilities, to: :authentication_result, allow_nil: true
delegate :type, to: :authentication_result, allow_nil: true, prefix: :auth_result delegate :type, to: :authentication_result, allow_nil: true, prefix: :auth_result
alias_method :user, :actor
alias_method :authenticated_user, :actor
# Git clients will not know what authenticity token to send along # Git clients will not know what authenticity token to send along
skip_around_action :set_session_storage skip_around_action :set_session_storage
skip_before_action :verify_authenticity_token skip_before_action :verify_authenticity_token
...@@ -22,8 +19,16 @@ class GitHttpClientController < Repositories::ApplicationController ...@@ -22,8 +19,16 @@ class GitHttpClientController < Repositories::ApplicationController
feature_category :source_code_management feature_category :source_code_management
def authenticated_user
authentication_result&.user || authentication_result&.deploy_token
end
private private
def user
authenticated_user
end
def download_request? def download_request?
raise NotImplementedError raise NotImplementedError
end end
......
...@@ -30,6 +30,7 @@ def git_receive_pack ...@@ -30,6 +30,7 @@ def git_receive_pack
private private
override :user
def user def user
super || geo_push_user&.user super || geo_push_user&.user
end end
......
...@@ -90,6 +90,14 @@ def send_request ...@@ -90,6 +90,14 @@ def send_request
end end
end end
end end
context 'when the user is a deploy token' do
it_behaves_like Repositories::GitHttpController do
let(:container) { project }
let(:user) { create(:deploy_token, :project, projects: [project]) }
let(:access_checker_class) { Gitlab::GitAccess }
end
end
end end
context 'when repository container is a project wiki' do context 'when repository container is a project wiki' do
......
...@@ -50,7 +50,8 @@ ...@@ -50,7 +50,8 @@
context 'with authorized user' do context 'with authorized user' do
before do before do
request.headers.merge! auth_env(user.username, user.password, nil) password = user.try(:password) || user.try(:token)
request.headers.merge! auth_env(user.username, password, nil)
end end
it 'returns 200' do it 'returns 200' do
...@@ -71,9 +72,10 @@ ...@@ -71,9 +72,10 @@
it 'adds user info to the logs' do it 'adds user info to the logs' do
get :info_refs, params: params get :info_refs, params: params
expect(log_data).to include('username' => user.username, user_log_data = { 'username' => user.username, 'user_id' => user.id }
'user_id' => user.id, user_log_data['meta.user'] = user.username if user.is_a?(User)
'meta.user' => user.username)
expect(log_data).to include(user_log_data)
end end
end end
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册