93daeee164
Gitlab::Auth.find_with_user_password is currently used in these places: - resource_owner_from_credentials in config/initializers/doorkeeper.rb, which is used for the OAuth Resource Owner Password Credentials flow - the /session API call in lib/api/session.rb, which is used to reveal the user's current authentication_token In both cases users should only be authenticated if they're in the active state.
55 lines
1.3 KiB
Ruby
55 lines
1.3 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe API::API, api: true do
|
|
include ApiHelpers
|
|
|
|
context 'Resource Owner Password Credentials' do
|
|
def request_oauth_token(user)
|
|
post '/oauth/token', username: user.username, password: user.password, grant_type: 'password'
|
|
end
|
|
|
|
context 'when user has 2FA enabled' do
|
|
it 'does not create an access token' do
|
|
user = create(:user, :two_factor)
|
|
|
|
request_oauth_token(user)
|
|
|
|
expect(response).to have_http_status(401)
|
|
expect(json_response['error']).to eq('invalid_grant')
|
|
end
|
|
end
|
|
|
|
context 'when user does not have 2FA enabled' do
|
|
it 'creates an access token' do
|
|
user = create(:user)
|
|
|
|
request_oauth_token(user)
|
|
|
|
expect(response).to have_http_status(200)
|
|
expect(json_response['access_token']).not_to be_nil
|
|
end
|
|
end
|
|
|
|
context "when user is blocked" do
|
|
it "does not create an access token" do
|
|
user = create(:user)
|
|
user.block
|
|
|
|
request_oauth_token(user)
|
|
|
|
expect(response).to have_http_status(401)
|
|
end
|
|
end
|
|
|
|
context "when user is ldap_blocked" do
|
|
it "does not create an access token" do
|
|
user = create(:user)
|
|
user.ldap_block
|
|
|
|
request_oauth_token(user)
|
|
|
|
expect(response).to have_http_status(401)
|
|
end
|
|
end
|
|
end
|
|
end
|