gitlab-org--gitlab-foss/spec/requests/api/doorkeeper_access_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2014-12-19 09:15:29 -05:00
require 'spec_helper'
RSpec.describe 'doorkeeper access' do
2014-12-19 09:15:29 -05:00
let!(:user) { create(:user) }
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" }
describe "unauthenticated" do
it "returns authentication success" do
get api("/user"), params: { access_token: token.plaintext_token }
expect(response).to have_gitlab_http_status(:ok)
2014-12-19 09:15:29 -05:00
end
2017-02-17 07:24:32 -05:00
include_examples 'user login request with unique ip limit' do
def request
get api('/user'), params: { access_token: token.plaintext_token }
end
end
2014-12-19 09:15:29 -05:00
end
describe "when token invalid" do
it "returns authentication error" do
get api("/user"), params: { access_token: "123a" }
expect(response).to have_gitlab_http_status(:unauthorized)
2014-12-19 09:15:29 -05:00
end
end
describe "authorization by OAuth token" do
it "returns authentication success" do
get api("/user", user)
expect(response).to have_gitlab_http_status(:ok)
2014-12-19 09:15:29 -05:00
end
2017-02-17 07:24:32 -05:00
include_examples 'user login request with unique ip limit' do
def request
get api('/user', user)
end
end
2014-12-19 09:15:29 -05:00
end
shared_examples 'forbidden request' do
it 'returns 403 response' do
get api("/user"), params: { access_token: token.plaintext_token }
expect(response).to have_gitlab_http_status(:forbidden)
end
end
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
user.ldap_block
end
it_behaves_like 'forbidden request'
end
context "when user is deactivated" do
before do
user.deactivate
end
it_behaves_like 'forbidden request'
end
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