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

59 lines
1.6 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
2015-09-11 14:41:01 +05:30
get api("/user"), access_token: token.token
2016-08-24 12:49:21 +05:30
expect(response).to have_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'), access_token: token.token
end
end
2015-04-26 12:48:37 +05:30
end
describe "when token invalid" do
it "returns authentication error" do
2015-09-11 14:41:01 +05:30
get api("/user"), access_token: "123a"
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(401)
2015-04-26 12:48:37 +05:30
end
end
describe "authorization by private token" do
it "returns authentication success" do
get api("/user", user)
2016-08-24 12:49:21 +05:30
expect(response).to have_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
it "returns authentication error" do
user.block
get api("/user"), access_token: token.token
expect(response).to have_http_status(401)
end
end
describe "when user is ldap_blocked" do
it "returns authentication error" do
user.ldap_block
get api("/user"), access_token: token.token
expect(response).to have_http_status(401)
end
2015-04-26 12:48:37 +05:30
end
end