Use special characters for lfs+deploy-key to prevent a someone from creating a user with this username, and method name refactoring.

This commit is contained in:
Patricio Cano 2016-09-07 11:55:54 -05:00
parent c144db2935
commit 71aff7f6a3
7 changed files with 9 additions and 9 deletions

View file

@ -22,7 +22,7 @@ class Projects::GitHttpClientController < Projects::ApplicationController
if allow_basic_auth? && basic_auth_provided?
login, password = user_name_and_password(request)
handle_authentication(login, password)
handle_basic_authentication(login, password)
if ci? || user
return # Allow access
@ -110,7 +110,7 @@ class Projects::GitHttpClientController < Projects::ApplicationController
@ci.present?
end
def handle_authentication(login, password)
def handle_basic_authentication(login, password)
auth_result = Gitlab::Auth.find_for_git_client(login, password, project: project, ip: request.ip)
case auth_result.type

View file

@ -115,7 +115,7 @@ module Gitlab
def lfs_token_check(login, password)
actor =
if login =~ /\Alfs-deploy-key-\d+\Z/
if login =~ /\Alfs\+deploy-key-\d+\Z/
/\d+\Z/.match(login) do |id|
DeployKey.find(id[0])
end

View file

@ -30,7 +30,7 @@ module Gitlab
end
def actor_name
actor.is_a?(User) ? actor.username : "lfs-deploy-key-#{actor.id}"
actor.is_a?(User) ? actor.username : "lfs+deploy-key-#{actor.id}"
end
private

View file

@ -37,8 +37,8 @@ describe Gitlab::Auth, lib: true do
ip = 'ip'
token = Gitlab::LfsToken.new(key).generate
expect(gl_auth).to receive(:rate_limit!).with(ip, success: true, login: "lfs-deploy-key-#{key.id}")
expect(gl_auth.find_for_git_client("lfs-deploy-key-#{key.id}", token, project: nil, ip: ip)).to eq(Gitlab::Auth::Result.new(key, :lfs_deploy_token))
expect(gl_auth).to receive(:rate_limit!).with(ip, success: true, login: "lfs+deploy-key-#{key.id}")
expect(gl_auth.find_for_git_client("lfs+deploy-key-#{key.id}", token, project: nil, ip: ip)).to eq(Gitlab::Auth::Result.new(key, :lfs_deploy_token))
end
it 'recognizes OAuth tokens' do

View file

@ -40,7 +40,7 @@ describe Gitlab::LfsToken, lib: true do
it_behaves_like 'an LFS token generator'
it 'returns the correct username' do
expect(handler.actor_name).to eq("lfs-deploy-key-#{actor.id}")
expect(handler.actor_name).to eq("lfs+deploy-key-#{actor.id}")
end
it 'returns the correct token type' do

View file

@ -124,7 +124,7 @@ describe API::API, api: true do
lfs_auth(key, project)
expect(response).to have_http_status(200)
expect(json_response['username']).to eq("lfs-deploy-key-#{key.id}")
expect(json_response['username']).to eq("lfs+deploy-key-#{key.id}")
expect(json_response['lfs_token']).to eq(Gitlab::LfsToken.new(key).value)
expect(json_response['repository_http_path']).to eq(project.http_url_to_repo)
end

View file

@ -917,7 +917,7 @@ describe 'Git LFS API and storage' do
end
def authorize_deploy_key
ActionController::HttpAuthentication::Basic.encode_credentials("lfs-deploy-key-#{key.id}", Gitlab::LfsToken.new(key).generate)
ActionController::HttpAuthentication::Basic.encode_credentials("lfs+deploy-key-#{key.id}", Gitlab::LfsToken.new(key).generate)
end
def fork_project(project, user, object = nil)