debian-mirror-gitlab/spec/requests/api/doorkeeper_access_spec.rb

59 lines
1.7 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
require 'spec_helper'
2017-08-17 22:00:37 +05:30
describe 'doorkeeper access' do
2015-04-26 12:48:37 +05:30
let!(:user) { create(:user) }
2015-09-11 14:41:01 +05:30
let!(:application) { Doorkeeper::Application.create!(name: "MyApp", redirect_uri: "https://app.com", owner: user) }
2017-08-17 22:00:37 +05:30
let!(:token) { Doorkeeper::AccessToken.create! application_id: application.id, resource_owner_id: user.id, scopes: "api" }
2015-09-11 14:41:01 +05:30
2017-08-17 22:00:37 +05:30
describe "unauthenticated" do
2015-04-26 12:48:37 +05:30
it "returns authentication success" do
2019-02-15 15:39:39 +05:30
get api("/user"), params: { access_token: token.token }
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2015-04-26 12:48:37 +05:30
end
2017-08-17 22:00:37 +05:30
include_examples 'user login request with unique ip limit' do
def request
2019-02-15 15:39:39 +05:30
get api('/user'), params: { access_token: token.token }
2017-08-17 22:00:37 +05:30
end
end
2015-04-26 12:48:37 +05:30
end
describe "when token invalid" do
it "returns authentication error" do
2019-02-15 15:39:39 +05:30
get api("/user"), params: { access_token: "123a" }
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(401)
2015-04-26 12:48:37 +05:30
end
end
2018-03-17 18:26:18 +05:30
describe "authorization by OAuth token" do
2015-04-26 12:48:37 +05:30
it "returns authentication success" do
get api("/user", user)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2015-04-26 12:48:37 +05:30
end
2017-08-17 22:00:37 +05:30
include_examples 'user login request with unique ip limit' do
def request
get api('/user', user)
end
end
end
describe "when user is blocked" do
2018-03-17 18:26:18 +05:30
it "returns authorization error" do
2017-08-17 22:00:37 +05:30
user.block
2019-02-15 15:39:39 +05:30
get api("/user"), params: { access_token: token.token }
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(403)
2017-08-17 22:00:37 +05:30
end
end
describe "when user is ldap_blocked" do
2018-03-17 18:26:18 +05:30
it "returns authorization error" do
2017-08-17 22:00:37 +05:30
user.ldap_block
2019-02-15 15:39:39 +05:30
get api("/user"), params: { access_token: token.token }
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(403)
2017-08-17 22:00:37 +05:30
end
2015-04-26 12:48:37 +05:30
end
end