2019-10-28 20:06:10 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-12-19 09:15:29 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.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
|
2022-08-12 17:11:43 -04:00
|
|
|
get api("/user"), params: { access_token: token.plaintext_token }
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
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
|
2022-08-12 17:11:43 -04:00
|
|
|
get api('/user'), params: { access_token: token.plaintext_token }
|
2017-02-17 06:52:27 -05:00
|
|
|
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
|
2018-12-17 17:52:17 -05:00
|
|
|
get api("/user"), params: { access_token: "123a" }
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2014-12-19 09:15:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-12 05:01:12 -04:00
|
|
|
describe "authorization by OAuth token" do
|
2017-02-21 16:17:23 -05:00
|
|
|
it "returns authentication success" do
|
|
|
|
get api("/user", user)
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
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
|
|
|
|
2019-10-09 20:06:44 -04:00
|
|
|
shared_examples 'forbidden request' do
|
|
|
|
it 'returns 403 response' do
|
2022-08-12 17:11:43 -04:00
|
|
|
get api("/user"), params: { access_token: token.plaintext_token }
|
2017-01-18 05:23:25 -05:00
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2017-01-18 05:23:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-09 20:06:44 -04: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 05:23:25 -05:00
|
|
|
user.ldap_block
|
2019-10-09 20:06:44 -04:00
|
|
|
end
|
2017-01-18 05:23:25 -05:00
|
|
|
|
2019-10-09 20:06:44 -04:00
|
|
|
it_behaves_like 'forbidden request'
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when user is deactivated" do
|
|
|
|
before do
|
|
|
|
user.deactivate
|
2017-01-18 05:23:25 -05:00
|
|
|
end
|
2019-10-09 20:06:44 -04:00
|
|
|
|
|
|
|
it_behaves_like 'forbidden request'
|
2017-01-18 05:23:25 -05:00
|
|
|
end
|
2020-10-06 08:08:38 -04:00
|
|
|
|
|
|
|
context 'when user is blocked pending approval' do
|
|
|
|
before do
|
|
|
|
user.block_pending_approval
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'forbidden request'
|
|
|
|
end
|
2014-12-19 09:15:29 -05:00
|
|
|
end
|