Commit cf6a35f0 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Improve JwtController implementation

parent 0672c5a9
...@@ -11,10 +11,8 @@ class JwtController < ApplicationController ...@@ -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
...@@ -22,6 +20,8 @@ class JwtController < ApplicationController ...@@ -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)
......
...@@ -5,7 +5,7 @@ module Auth ...@@ -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
......
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
...@@ -16,10 +16,12 @@ describe Ci::MaskSecret, lib: true do ...@@ -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
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