2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-28 08:45:18 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Oauth::AuthorizationsController do
|
|
|
|
let(:user) { create(:user) }
|
2018-06-29 04:15:42 -04:00
|
|
|
let!(:application) { create(:oauth_application, scopes: 'api read_user', redirect_uri: 'http://example.com') }
|
2017-04-28 08:45:18 -04:00
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
response_type: "code",
|
2018-06-29 04:15:42 -04:00
|
|
|
client_id: application.uid,
|
|
|
|
redirect_uri: application.redirect_uri,
|
2017-04-28 08:45:18 -04:00
|
|
|
state: 'state'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #new' do
|
|
|
|
context 'without valid params' do
|
|
|
|
it 'returns 200 code and renders error view' do
|
|
|
|
get :new
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-04-28 08:45:18 -04:00
|
|
|
expect(response).to render_template('doorkeeper/authorizations/error')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with valid params' do
|
2018-02-27 06:03:22 -05:00
|
|
|
render_views
|
|
|
|
|
2017-04-28 08:45:18 -04:00
|
|
|
it 'returns 200 code and renders view' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :new, params: params
|
2017-04-28 08:45:18 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-04-28 08:45:18 -04:00
|
|
|
expect(response).to render_template('doorkeeper/authorizations/new')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'deletes session.user_return_to and redirects when skip authorization' do
|
2018-06-29 04:15:42 -04:00
|
|
|
application.update(trusted: true)
|
2017-04-28 08:45:18 -04:00
|
|
|
request.session['user_return_to'] = 'http://example.com'
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
get :new, params: params
|
2017-04-28 08:45:18 -04:00
|
|
|
|
|
|
|
expect(request.session['user_return_to']).to be_nil
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(302)
|
2017-04-28 08:45:18 -04:00
|
|
|
end
|
2018-06-29 04:15:42 -04:00
|
|
|
|
|
|
|
context 'when there is already an access token for the application' do
|
|
|
|
context 'when the request scope matches any of the created token scopes' do
|
|
|
|
before do
|
|
|
|
scopes = Doorkeeper::OAuth::Scopes.from_string('api')
|
|
|
|
|
|
|
|
allow(Doorkeeper.configuration).to receive(:scopes).and_return(scopes)
|
|
|
|
|
|
|
|
create :oauth_access_token, application: application, resource_owner_id: user.id, scopes: scopes
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'authorizes the request and redirects' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :new, params: params
|
2018-06-29 04:15:42 -04:00
|
|
|
|
|
|
|
expect(request.session['user_return_to']).to be_nil
|
|
|
|
expect(response).to have_gitlab_http_status(302)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-04-28 08:45:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|