Small refactor and syntax fixes.
This commit is contained in:
parent
c297800862
commit
a4137411c6
5 changed files with 5 additions and 6 deletions
|
@ -13,7 +13,7 @@ Doorkeeper.configure do
|
||||||
|
|
||||||
resource_owner_from_credentials do |routes|
|
resource_owner_from_credentials do |routes|
|
||||||
user = Gitlab::Auth.find_with_user_password(params[:username], params[:password])
|
user = Gitlab::Auth.find_with_user_password(params[:username], params[:password])
|
||||||
user unless user && user.two_factor_enabled?
|
user unless user.try(:two_factor_enabled?)
|
||||||
end
|
end
|
||||||
|
|
||||||
# If you want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below.
|
# If you want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below.
|
||||||
|
|
|
@ -275,10 +275,6 @@ module API
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_2fa_error!
|
|
||||||
render_api_error!('401 Unauthorized. You have 2FA enabled. Please use a personal access token to access the API', 401)
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_api_error!(message, status)
|
def render_api_error!(message, status)
|
||||||
error!({ 'message' => message }, status)
|
error!({ 'message' => message }, status)
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,7 @@ module API
|
||||||
user = Gitlab::Auth.find_with_user_password(params[:email] || params[:login], params[:password])
|
user = Gitlab::Auth.find_with_user_password(params[:email] || params[:login], params[:password])
|
||||||
|
|
||||||
return unauthorized! unless user
|
return unauthorized! unless user
|
||||||
return render_2fa_error! if user.two_factor_enabled?
|
return render_api_error!('401 Unauthorized. You have 2FA enabled. Please use a personal access token to access the API', 401) if user.two_factor_enabled?
|
||||||
present user, with: Entities::UserLogin
|
present user, with: Entities::UserLogin
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,6 +11,7 @@ describe API::API, api: true do
|
||||||
context 'when user has 2FA enabled' do
|
context 'when user has 2FA enabled' do
|
||||||
it 'does not create an access token' do
|
it 'does not create an access token' do
|
||||||
user = create(:user, :two_factor)
|
user = create(:user, :two_factor)
|
||||||
|
|
||||||
request_oauth_token(user)
|
request_oauth_token(user)
|
||||||
|
|
||||||
expect(response).to have_http_status(401)
|
expect(response).to have_http_status(401)
|
||||||
|
@ -21,6 +22,7 @@ describe API::API, api: true do
|
||||||
context 'when user does not have 2FA enabled' do
|
context 'when user does not have 2FA enabled' do
|
||||||
it 'creates an access token' do
|
it 'creates an access token' do
|
||||||
user = create(:user)
|
user = create(:user)
|
||||||
|
|
||||||
request_oauth_token(user)
|
request_oauth_token(user)
|
||||||
|
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
|
|
|
@ -25,6 +25,7 @@ describe API::API, api: true do
|
||||||
post api('/session'), email: user.email, password: user.password
|
post api('/session'), email: user.email, password: user.password
|
||||||
|
|
||||||
expect(response).to have_http_status(401)
|
expect(response).to have_http_status(401)
|
||||||
|
expect(response.body).to include('You have 2FA enabled.')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue