Commit 228f42b5 authored by Grzegorz Bizon's avatar Grzegorz Bizon

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
parents d6e16693 36bdf3dc
---
title: Gracefully handle orphaned write deploy keys in /internal/post_receive
merge_request:
author:
type: fixed
......@@ -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
......
......@@ -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
......
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