Merge branch 'sh-handle-orphaned-deploy-keys' into 'master'

Gracefully handle orphaned write deploy keys in /internal/post_receive

Closes #41466

See merge request gitlab-org/gitlab-ce!16127
This commit is contained in:
Grzegorz Bizon 2017-12-25 07:10:28 +00:00
commit 228f42b58b
3 changed files with 21 additions and 3 deletions

View File

@ -0,0 +1,5 @@
---
title: Gracefully handle orphaned write deploy keys in /internal/post_receive
merge_request:
author:
type: fixed

View File

@ -190,9 +190,12 @@ module API
project = Gitlab::GlRepository.parse(params[:gl_repository]).first
user = identify(params[:identifier])
redirect_message = Gitlab::Checks::ProjectMoved.fetch_redirect_message(user.id, project.id)
if redirect_message
output[:redirected_message] = redirect_message
# A user is not guaranteed to be returned; an orphaned write deploy
# key could be used
if user
redirect_message = Gitlab::Checks::ProjectMoved.fetch_redirect_message(user.id, project.id)
output[:redirected_message] = redirect_message if redirect_message
end
output

View File

@ -784,6 +784,16 @@ describe API::Internal do
expect(json_response["redirected_message"]).to eq(project_moved.redirect_message)
end
end
context 'with an orphaned write deploy key' do
it 'does not try to notify that project moved' do
allow_any_instance_of(Gitlab::Identifier).to receive(:identify).and_return(nil)
post api("/internal/post_receive"), valid_params
expect(response).to have_gitlab_http_status(200)
end
end
end
describe 'POST /internal/pre_receive' do