summaryrefslogtreecommitdiff
path: root/spec/requests/api/oauth_tokens_spec.rb
blob: bdda80cc229d04f543162b4d591d8468538be2bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require 'spec_helper'

describe 'OAuth tokens' do
  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_gitlab_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_gitlab_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_gitlab_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_gitlab_http_status(401)
      end
    end
  end
end