Commit 0db28376 authored by Etienne Baqué's avatar Etienne Baqué

Merge branch...

Merge branch '349706-the-users-username-exists-action-shouldn-t-be-available-when-gitlab-instance-doesn-t-allow' into 'master'

Prevent user exists route when GitLab instance doesn't allow registration

See merge request gitlab-org/gitlab!78490
parents be9c1c23 8bb58ac2
...@@ -148,7 +148,11 @@ class UsersController < ApplicationController ...@@ -148,7 +148,11 @@ class UsersController < ApplicationController
end end
def exists def exists
if Gitlab::CurrentSettings.signup_enabled? || current_user
render json: { exists: !!Namespace.find_by_path_or_name(params[:username]) } 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 end
def follow def follow
......
...@@ -41154,6 +41154,9 @@ msgstr "" ...@@ -41154,6 +41154,9 @@ msgstr ""
msgid "You may close the milestone now." msgid "You may close the milestone now."
msgstr "" msgstr ""
msgid "You must be authenticated to access this path."
msgstr ""
msgid "You must be logged in to search across all of GitLab" msgid "You must be logged in to search across all of GitLab"
msgstr "" msgstr ""
......
...@@ -634,13 +634,13 @@ RSpec.describe UsersController do ...@@ -634,13 +634,13 @@ RSpec.describe UsersController do
end end
describe 'GET #exists' do describe 'GET #exists' do
context 'when user exists' do
before do before do
sign_in(user) sign_in(user)
allow(::Gitlab::ApplicationRateLimiter).to receive(:throttled?).and_return(false) allow(::Gitlab::ApplicationRateLimiter).to receive(:throttled?).and_return(false)
end end
context 'when user exists' do
it 'returns JSON indicating the user exists' do it 'returns JSON indicating the user exists' do
get user_exists_url user.username get user_exists_url user.username
...@@ -661,6 +661,15 @@ RSpec.describe UsersController do ...@@ -661,6 +661,15 @@ RSpec.describe UsersController do
end end
context 'when the user does not exist' do 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 it 'returns JSON indicating the user does not exist' do
get user_exists_url 'foo' get user_exists_url 'foo'
......
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