2016-09-13 17:45:13 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe 'OAuth tokens' do
|
2016-09-13 17:45:13 +05:30
|
|
|
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)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(401)
|
2016-09-13 17:45:13 +05:30
|
|
|
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)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-09-13 17:45:13 +05:30
|
|
|
expect(json_response['access_token']).not_to be_nil
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
context "when user is blocked" do
|
|
|
|
it "does not create an access token" do
|
|
|
|
user = create(:user)
|
|
|
|
user.block
|
|
|
|
|
|
|
|
request_oauth_token(user)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(401)
|
2017-08-17 22:00:37 +05:30
|
|
|
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)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(401)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|