Merge branch 'sh-handle-anonymous-clones-project-moved' into 'master'

Fix Error 500s with anonymous clones for a project that has moved

Closes #41457

See merge request gitlab-org/gitlab-ce!16128
This commit is contained in:
Grzegorz Bizon 2017-12-26 12:46:07 +00:00
commit a5a0f3f725
3 changed files with 15 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
title: Fix Error 500s with anonymous clones for a project that has moved
merge_request:
author:
type: fixed

View File

@ -21,6 +21,10 @@ module Gitlab
end
def add_redirect_message
# Don't bother with sending a redirect message for anonymous clones
# because they never see it via the `/internal/post_receive` endpoint
return unless user.present? && project.present?
Gitlab::Redis::SharedState.with do |redis|
key = self.class.redirect_message_key(user.id, project.id)
redis.setex(key, 5.minutes, redirect_message)

View File

@ -35,6 +35,12 @@ describe Gitlab::Checks::ProjectMoved, :clean_gitlab_redis_shared_state do
project_moved = described_class.new(project, user, 'foo/bar', 'http')
expect(project_moved.add_redirect_message).to eq("OK")
end
it 'should handle anonymous clones' do
project_moved = described_class.new(project, nil, 'foo/bar', 'http')
expect(project_moved.add_redirect_message).to eq(nil)
end
end
describe '#redirect_message' do