Skip to content
Snippets Groups Projects
Commit cf6a35f0 authored by Kamil Trzcinski's avatar Kamil Trzcinski
Browse files

Improve JwtController implementation

parent 0672c5a9
No related branches found
No related tags found
1 merge request!6432Post-merge improve of CI permissions
Pipeline #
Loading
@@ -11,10 +11,8 @@ class JwtController < ApplicationController
Loading
@@ -11,10 +11,8 @@ class JwtController < ApplicationController
service = SERVICES[params[:service]] service = SERVICES[params[:service]]
return head :not_found unless service return head :not_found unless service
   
@authentication_result ||= Gitlab::Auth::Result.new
result = service.new(@authentication_result.project, @authentication_result.actor, auth_params). result = service.new(@authentication_result.project, @authentication_result.actor, auth_params).
execute(authentication_abilities: @authentication_result.authentication_abilities) execute(authentication_abilities: @authentication_result.authentication_abilities || [])
   
render json: result, status: result[:http_status] render json: result, status: result[:http_status]
end end
Loading
@@ -22,6 +20,8 @@ class JwtController < ApplicationController
Loading
@@ -22,6 +20,8 @@ class JwtController < ApplicationController
private private
   
def authenticate_project_or_user def authenticate_project_or_user
@authentication_result = Gitlab::Auth::Result.new
authenticate_with_http_basic do |login, password| authenticate_with_http_basic do |login, password|
@authentication_result = Gitlab::Auth.find_for_git_client(login, password, project: nil, ip: request.ip) @authentication_result = Gitlab::Auth.find_for_git_client(login, password, project: nil, ip: request.ip)
   
Loading
Loading
Loading
@@ -5,7 +5,7 @@ module Auth
Loading
@@ -5,7 +5,7 @@ module Auth
AUDIENCE = 'container_registry' AUDIENCE = 'container_registry'
   
def execute(authentication_abilities:) def execute(authentication_abilities:)
@authentication_abilities = authentication_abilities || [] @authentication_abilities = authentication_abilities
   
return error('not found', 404) unless registry.enabled return error('not found', 404) unless registry.enabled
   
Loading
Loading
module Ci::MaskSecret module Ci::MaskSecret
class << self class << self
def mask!(value, token) def mask!(value, token)
return unless value.present? && token.present? return value unless value.present? && token.present?
   
value.gsub!(token, 'x' * token.length) value.gsub!(token, 'x' * token.length)
value
end end
end end
end end
Loading
@@ -16,10 +16,12 @@ describe Ci::MaskSecret, lib: true do
Loading
@@ -16,10 +16,12 @@ describe Ci::MaskSecret, lib: true do
expect(mask('token', 'not')).to eq('token') expect(mask('token', 'not')).to eq('token')
end end
   
it 'does support null token' do
expect(mask('token', nil)).to eq('token')
end
def mask(value, token) def mask(value, token)
value = value.dup subject.mask!(value.dup, token)
subject.mask!(value, token)
value
end end
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment