Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
1fa306fb
Commit
1fa306fb
authored
Jan 12, 2022
by
Gary Holtz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding a conditional to prevent an unauthorized route
Changelog: security
parent
61d3b8fd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
6 deletions
+19
-6
app/controllers/users_controller.rb
app/controllers/users_controller.rb
+5
-1
spec/requests/users_controller_spec.rb
spec/requests/users_controller_spec.rb
+14
-5
No files found.
app/controllers/users_controller.rb
View file @
1fa306fb
...
...
@@ -148,7 +148,11 @@ class UsersController < ApplicationController
end
def
exists
render
json:
{
exists:
!!
Namespace
.
find_by_path_or_name
(
params
[
:username
])
}
if
Gitlab
::
CurrentSettings
.
signup_enabled?
||
current_user
render
json:
{
exists:
!!
Namespace
.
find_by_path_or_name
(
params
[
:username
])
}
else
render
json:
{
error:
"You must be authenticated to access this path"
},
status: :unauthorized
end
end
def
follow
...
...
spec/requests/users_controller_spec.rb
View file @
1fa306fb
...
...
@@ -634,13 +634,13 @@ RSpec.describe UsersController do
end
describe
'GET #exists'
do
before
do
sign_in
(
user
)
context
'when user exists'
do
before
do
sign_in
(
user
)
allow
(
::
Gitlab
::
ApplicationRateLimiter
).
to
receive
(
:throttled?
).
and_return
(
false
)
end
allow
(
::
Gitlab
::
ApplicationRateLimiter
).
to
receive
(
:throttled?
).
and_return
(
false
)
end
context
'when user exists'
do
it
'returns JSON indicating the user exists'
do
get
user_exists_url
user
.
username
...
...
@@ -661,6 +661,15 @@ RSpec.describe UsersController do
end
context
'when the user does not exist'
do
it
'will not show a signup page if registration is disabled'
do
stub_application_setting
(
signup_enabled:
false
)
get
user_exists_url
'foo'
expected_json
=
{
error:
"You must be authenticated to access this path"
}.
to_json
expect
(
response
).
to
have_gitlab_http_status
(
:unauthorized
)
expect
(
response
.
body
).
to
eq
(
expected_json
)
end
it
'returns JSON indicating the user does not exist'
do
get
user_exists_url
'foo'
...
...
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