|
5 | 5 | RSpec.describe Oauth::AuthorizationsController, type: :controller do |
6 | 6 | render_views |
7 | 7 |
|
8 | | - let(:app) { Doorkeeper::Application.create!(name: 'test', redirect_uri: 'http://localhost/') } |
| 8 | + let(:app) { Doorkeeper::Application.create!(name: 'test', redirect_uri: 'http://localhost/', scopes: 'read') } |
9 | 9 |
|
10 | 10 | describe 'GET #new' do |
11 | 11 | subject do |
12 | | - get :new, params: { client_id: app.uid, response_type: 'code', redirect_uri: 'http://localhost/' } |
| 12 | + get :new, params: { client_id: app.uid, response_type: 'code', redirect_uri: 'http://localhost/', scope: 'read' } |
13 | 13 | end |
14 | 14 |
|
15 | 15 | shared_examples 'stores location for user' do |
16 | 16 | it 'stores location for user' do |
17 | 17 | subject |
18 | | - expect(controller.stored_location_for(:user)).to eq "/oauth/authorize?client_id=#{app.uid}&redirect_uri=http%3A%2F%2Flocalhost%2F&response_type=code" |
| 18 | + expect(controller.stored_location_for(:user)).to eq "/oauth/authorize?client_id=#{app.uid}&redirect_uri=http%3A%2F%2Flocalhost%2F&response_type=code&scope=read" |
19 | 19 | end |
20 | 20 | end |
21 | 21 |
|
22 | 22 | context 'when signed in' do |
| 23 | + let!(:user) { Fabricate(:user) } |
| 24 | + |
23 | 25 | before do |
24 | | - sign_in Fabricate(:user), scope: :user |
| 26 | + sign_in user, scope: :user |
25 | 27 | end |
26 | 28 |
|
27 | 29 | it 'returns http success' do |
|
35 | 37 | end |
36 | 38 |
|
37 | 39 | include_examples 'stores location for user' |
| 40 | + |
| 41 | + context 'when app is already authorized' do |
| 42 | + before do |
| 43 | + Doorkeeper::AccessToken.find_or_create_for( |
| 44 | + app, |
| 45 | + user.id, |
| 46 | + app.scopes, |
| 47 | + Doorkeeper.configuration.access_token_expires_in, |
| 48 | + Doorkeeper.configuration.refresh_token_enabled? |
| 49 | + ) |
| 50 | + end |
| 51 | + |
| 52 | + it 'redirects to callback' do |
| 53 | + subject |
| 54 | + expect(response).to redirect_to(/\A#{app.redirect_uri}/) |
| 55 | + end |
| 56 | + |
| 57 | + it 'does not redirect to callback with force_login=true' do |
| 58 | + get :new, params: { client_id: app.uid, response_type: 'code', redirect_uri: 'http://localhost/', scope: 'read', force_login: 'true' } |
| 59 | + expect(response.body).to match(/Authorize/) |
| 60 | + end |
| 61 | + end |
38 | 62 | end |
39 | 63 |
|
40 | 64 | context 'when not signed in' do |
|
0 commit comments