|
1 | 1 | require 'rails_helper' |
2 | 2 |
|
3 | 3 | describe Doorkeeper::AuthorizationsController, type: :controller do |
4 | | - describe '#new' do |
5 | | - context 'without a prompt parameter' do |
6 | | - it 'renders the authorization form if logged in' do |
7 | | - get :new, current_user: 'Joe' |
| 4 | + let(:user) { create :user } |
8 | 5 |
|
9 | | - expect(response).to be_successful |
10 | | - end |
| 6 | + describe '#resource_owner_authenticator' do |
| 7 | + it 'renders the authorization form if logged in' do |
| 8 | + get :new, current_user: user.id |
11 | 9 |
|
12 | | - it 'redirects to login form when not logged in' do |
13 | | - get :new |
| 10 | + expect(response).to be_successful |
| 11 | + end |
14 | 12 |
|
15 | | - expect(response).to redirect_to '/login' |
16 | | - end |
| 13 | + it 'redirects to login form when not logged in' do |
| 14 | + get :new |
| 15 | + |
| 16 | + expect(response).to redirect_to '/login' |
17 | 17 | end |
| 18 | + end |
18 | 19 |
|
| 20 | + describe '#validate_prompt_param!' do |
19 | 21 | context 'with a prompt=none parameter' do |
20 | 22 | it 'renders the authorization form if logged in' do |
21 | | - get :new, current_user: 'Joe', prompt: 'none' |
| 23 | + get :new, current_user: user.id, prompt: 'none' |
22 | 24 |
|
23 | 25 | expect(response).to be_successful |
24 | 26 | end |
|
34 | 36 | end |
35 | 37 | end |
36 | 38 | end |
| 39 | + |
| 40 | + describe '#validate_max_age_param!' do |
| 41 | + context 'with an invalid max_age parameter' do |
| 42 | + it 'renders the authorization form' do |
| 43 | + %w[ 0 -1 -23 foobar ].each do |max_age| |
| 44 | + get :new, current_user: user.id, max_age: max_age |
| 45 | + |
| 46 | + expect(response).to be_successful |
| 47 | + end |
| 48 | + end |
| 49 | + end |
| 50 | + |
| 51 | + context 'with a max_age=10 parameter' do |
| 52 | + it 'renders the authorization form if the users last login was within 10 seconds' do |
| 53 | + user.update! current_sign_in_at: 5.seconds.ago |
| 54 | + get :new, current_user: user.id, max_age: 10 |
| 55 | + |
| 56 | + expect(response).to be_successful |
| 57 | + end |
| 58 | + |
| 59 | + it 'calls reauthenticate_resource_owner if the last login was longer than 10 seconds ago' do |
| 60 | + user.update! current_sign_in_at: 5.minutes.ago |
| 61 | + get :new, current_user: user.id, max_age: 10 |
| 62 | + |
| 63 | + expect(response).to redirect_to '/reauthenticate' |
| 64 | + end |
| 65 | + |
| 66 | + it 'calls reauthenticate_resource_owner if the last login is unknown' do |
| 67 | + user.update! current_sign_in_at: nil |
| 68 | + get :new, current_user: user.id, max_age: 10 |
| 69 | + |
| 70 | + expect(response).to redirect_to '/reauthenticate' |
| 71 | + end |
| 72 | + end |
| 73 | + end |
37 | 74 | end |
0 commit comments