2014-12-19 09:15:29 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-04-25 08:28:55 -04:00
|
|
|
describe 'doorkeeper access' do
|
2014-12-19 09:15:29 -05:00
|
|
|
let!(:user) { create(:user) }
|
2017-02-21 16:17:23 -05:00
|
|
|
let!(:application) { Doorkeeper::Application.create!(name: "MyApp", redirect_uri: "https://app.com", owner: user) }
|
|
|
|
let!(:token) { Doorkeeper::AccessToken.create! application_id: application.id, resource_owner_id: user.id, scopes: "api" }
|
2015-06-22 09:05:19 -04:00
|
|
|
|
2017-02-21 16:17:23 -05:00
|
|
|
describe "unauthenticated" do
|
|
|
|
it "returns authentication success" do
|
|
|
|
get api("/user"), access_token: token.token
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2014-12-19 09:15:29 -05:00
|
|
|
end
|
2017-02-17 06:52:27 -05:00
|
|
|
|
2017-02-17 07:24:32 -05:00
|
|
|
include_examples 'user login request with unique ip limit' do
|
|
|
|
def request
|
2017-02-17 06:52:27 -05:00
|
|
|
get api('/user'), access_token: token.token
|
|
|
|
end
|
|
|
|
end
|
2014-12-19 09:15:29 -05:00
|
|
|
end
|
|
|
|
|
2017-02-21 16:17:23 -05:00
|
|
|
describe "when token invalid" do
|
|
|
|
it "returns authentication error" do
|
|
|
|
get api("/user"), access_token: "123a"
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(401)
|
2014-12-19 09:15:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-21 16:17:23 -05:00
|
|
|
describe "authorization by private token" do
|
|
|
|
it "returns authentication success" do
|
|
|
|
get api("/user", user)
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2014-12-19 09:15:29 -05:00
|
|
|
end
|
2017-02-17 06:52:27 -05:00
|
|
|
|
2017-02-17 07:24:32 -05:00
|
|
|
include_examples 'user login request with unique ip limit' do
|
|
|
|
def request
|
2017-02-17 06:52:27 -05:00
|
|
|
get api('/user', user)
|
|
|
|
end
|
|
|
|
end
|
2014-12-19 09:15:29 -05:00
|
|
|
end
|
2017-01-18 05:23:25 -05:00
|
|
|
|
|
|
|
describe "when user is blocked" do
|
|
|
|
it "returns authentication error" do
|
|
|
|
user.block
|
|
|
|
get api("/user"), access_token: token.token
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(401)
|
2017-01-18 05:23:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when user is ldap_blocked" do
|
|
|
|
it "returns authentication error" do
|
|
|
|
user.ldap_block
|
|
|
|
get api("/user"), access_token: token.token
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(401)
|
2017-01-18 05:23:25 -05:00
|
|
|
end
|
|
|
|
end
|
2014-12-19 09:15:29 -05:00
|
|
|
end
|