Commit 0a9cd146 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'mc_rocha-find-user-by-email' into 'master'

Search the user by username or email

See merge request gitlab-org/gitlab!83871
parents 6f3e8921 e993ebc2
...@@ -24,7 +24,7 @@ module API ...@@ -24,7 +24,7 @@ module API
if rate_limit_reached if rate_limit_reached
present({ result: true }, with: Entities::CaptchaCheck) present({ result: true }, with: Entities::CaptchaCheck)
else else
user = User.find_by_username(params[:username]) user = ::User.by_login(params[:username])
not_found! 'User' unless user not_found! 'User' unless user
present(::Users::CaptchaChallengeService.new(user, request.ip).execute, with: Entities::CaptchaCheck) present(::Users::CaptchaChallengeService.new(user, request.ip).execute, with: Entities::CaptchaCheck)
end end
......
...@@ -4,7 +4,8 @@ require 'spec_helper' ...@@ -4,7 +4,8 @@ require 'spec_helper'
RSpec.describe API::CaptchaCheck do RSpec.describe API::CaptchaCheck do
let_it_be(:username) { 'TestCaptcha' } let_it_be(:username) { 'TestCaptcha' }
let_it_be_with_reload(:user) { create(:user, username: username) } let_it_be(:email) { 'test_email@email.com' }
let_it_be_with_reload(:user) { create(:user, username: username, email: email) }
describe 'GET users/:username/captcha_check' do describe 'GET users/:username/captcha_check' do
context 'when the feature flag arkose_labs_login_challenge is disabled' do context 'when the feature flag arkose_labs_login_challenge is disabled' do
...@@ -41,6 +42,34 @@ RSpec.describe API::CaptchaCheck do ...@@ -41,6 +42,34 @@ RSpec.describe API::CaptchaCheck do
end end
end end
context 'when the email is valid' do
it 'returns status ok' do
get api("/users/#{email}/captcha_check")
expect(response).to have_gitlab_http_status(:ok)
end
end
context 'when the email is unknown' do
let(:unknown_email) { 'unknown_email@email.com' }
it 'returns status not_found' do
get api("/users/#{unknown_email}/captcha_check")
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'when the email is invalid' do
let(:invalid_email) { 'invalid_email@' }
it 'returns status not_found' do
get api("/users/#{invalid_email}/captcha_check")
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'when the user meets the criteria for the captcha check' do context 'when the user meets the criteria for the captcha check' do
before do before do
user.last_sign_in_at = nil user.last_sign_in_at = nil
......
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