BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
b6c711fd
Commit
b6c711fd
authored
Dec 25, 2017
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disable redirect messages for anonymous clones
parent
a83c41f6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
12 deletions
+8
-12
project_moved.rb
lib/gitlab/checks/project_moved.rb
+7
-10
project_moved_spec.rb
spec/lib/gitlab/checks/project_moved_spec.rb
+1
-2
No files found.
lib/gitlab/checks/project_moved.rb
View file @
b6c711fd
...
...
@@ -2,7 +2,6 @@ module Gitlab
module
Checks
class
ProjectMoved
REDIRECT_NAMESPACE
=
"redirect_namespace"
.
freeze
ANONYMOUS_ID_KEY
=
'anonymous'
.
freeze
def
initialize
(
project
,
user
,
redirected_path
,
protocol
)
@project
=
project
...
...
@@ -22,8 +21,12 @@ 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
_identifier
,
project
.
id
)
key
=
self
.
class
.
redirect_message_key
(
user
.
id
,
project
.
id
)
redis
.
setex
(
key
,
5
.
minutes
,
redirect_message
)
end
end
...
...
@@ -46,14 +49,8 @@ module Gitlab
attr_reader
:project
,
:redirected_path
,
:protocol
,
:user
def
self
.
redirect_message_key
(
user_identifier
,
project_id
)
"
#{
REDIRECT_NAMESPACE
}
:
#{
user_identifier
}
:
#{
project_id
}
"
end
def
user_identifier
return
ANONYMOUS_ID_KEY
unless
user
.
present?
user
.
id
def
self
.
redirect_message_key
(
user_id
,
project_id
)
"
#{
REDIRECT_NAMESPACE
}
:
#{
user_id
}
:
#{
project_id
}
"
end
def
remote_url_message
(
rejected
)
...
...
spec/lib/gitlab/checks/project_moved_spec.rb
View file @
b6c711fd
...
...
@@ -39,8 +39,7 @@ describe Gitlab::Checks::ProjectMoved, :clean_gitlab_redis_shared_state do
it
'should handle anonymous clones'
do
project_moved
=
described_class
.
new
(
project
,
nil
,
'foo/bar'
,
'http'
)
expect
(
project_moved
.
add_redirect_message
).
to
eq
(
"OK"
)
expect
(
Gitlab
::
Redis
::
SharedState
.
with
{
|
redis
|
redis
.
get
(
"redirect_namespace:anonymous:
#{
project
.
id
}
"
)
}).
not_to
be_nil
expect
(
project_moved
.
add_redirect_message
).
to
eq
(
nil
)
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment