2014-12-19 14:15:29 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-04-25 12:28:55 +00:00
|
|
|
describe 'doorkeeper access' do
|
2014-12-19 14:15:29 +00:00
|
|
|
let!(:user) { create(:user) }
|
2017-02-21 21:17:23 +00: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 13:05:19 +00:00
|
|
|
|
2017-02-21 21:17:23 +00:00
|
|
|
describe "unauthenticated" do
|
|
|
|
it "returns authentication success" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get api("/user"), params: { access_token: token.token }
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2014-12-19 14:15:29 +00:00
|
|
|
end
|
2017-02-17 11:52:27 +00:00
|
|
|
|
2017-02-17 12:24:32 +00:00
|
|
|
include_examples 'user login request with unique ip limit' do
|
|
|
|
def request
|
2018-12-17 22:52:17 +00:00
|
|
|
get api('/user'), params: { access_token: token.token }
|
2017-02-17 11:52:27 +00:00
|
|
|
end
|
|
|
|
end
|
2014-12-19 14:15:29 +00:00
|
|
|
end
|
|
|
|
|
2017-02-21 21:17:23 +00:00
|
|
|
describe "when token invalid" do
|
|
|
|
it "returns authentication error" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get api("/user"), params: { access_token: "123a" }
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(401)
|
2014-12-19 14:15:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-12 09:01:12 +00:00
|
|
|
describe "authorization by OAuth token" do
|
2017-02-21 21:17:23 +00:00
|
|
|
it "returns authentication success" do
|
|
|
|
get api("/user", user)
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2014-12-19 14:15:29 +00:00
|
|
|
end
|
2017-02-17 11:52:27 +00:00
|
|
|
|
2017-02-17 12:24:32 +00:00
|
|
|
include_examples 'user login request with unique ip limit' do
|
|
|
|
def request
|
2017-02-17 11:52:27 +00:00
|
|
|
get api('/user', user)
|
|
|
|
end
|
|
|
|
end
|
2014-12-19 14:15:29 +00:00
|
|
|
end
|
2017-01-18 10:23:25 +00:00
|
|
|
|
2019-10-10 00:06:44 +00:00
|
|
|
shared_examples 'forbidden request' do
|
|
|
|
it 'returns 403 response' do
|
2018-12-17 22:52:17 +00:00
|
|
|
get api("/user"), params: { access_token: token.token }
|
2017-01-18 10:23:25 +00:00
|
|
|
|
2017-10-12 12:38:39 +00:00
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2017-01-18 10:23:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-10 00:06:44 +00:00
|
|
|
context "when user is blocked" do
|
|
|
|
before do
|
|
|
|
user.block
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'forbidden request'
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when user is ldap_blocked" do
|
|
|
|
before do
|
2017-01-18 10:23:25 +00:00
|
|
|
user.ldap_block
|
2019-10-10 00:06:44 +00:00
|
|
|
end
|
2017-01-18 10:23:25 +00:00
|
|
|
|
2019-10-10 00:06:44 +00:00
|
|
|
it_behaves_like 'forbidden request'
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when user is deactivated" do
|
|
|
|
before do
|
|
|
|
user.deactivate
|
2017-01-18 10:23:25 +00:00
|
|
|
end
|
2019-10-10 00:06:44 +00:00
|
|
|
|
|
|
|
it_behaves_like 'forbidden request'
|
2017-01-18 10:23:25 +00:00
|
|
|
end
|
2014-12-19 14:15:29 +00:00
|
|
|
end
|