Commit 36bdf3dc authored by Stan Hu's avatar Stan Hu

Gracefully handle orphaned write deploy keys in /internal/post_receive

On GitLab.com, there are write deploy keys with no associated users.
Pushes with these deploy keys end with an Error 500 since we attempt
to look up redirect message. If there is no user, don't attempt
to display a redirect message.

Closes #41466
parent 0c8d7e84
---
title: Gracefully handle orphaned write deploy keys in /internal/post_receive
merge_request:
author:
type: fixed
...@@ -190,9 +190,12 @@ module API ...@@ -190,9 +190,12 @@ module API
project = Gitlab::GlRepository.parse(params[:gl_repository]).first project = Gitlab::GlRepository.parse(params[:gl_repository]).first
user = identify(params[:identifier]) user = identify(params[:identifier])
redirect_message = Gitlab::Checks::ProjectMoved.fetch_redirect_message(user.id, project.id)
if redirect_message # A user is not guaranteed to be returned; an orphaned write deploy
output[:redirected_message] = redirect_message # 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 end
output output
......
...@@ -784,6 +784,16 @@ describe API::Internal do ...@@ -784,6 +784,16 @@ describe API::Internal do
expect(json_response["redirected_message"]).to eq(project_moved.redirect_message) expect(json_response["redirected_message"]).to eq(project_moved.redirect_message)
end end
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 end
describe 'POST /internal/pre_receive' do 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