|
8 | 8 | context 'with default parameters' do
|
9 | 9 | let(:client_application) { FactoryGirl.create :application }
|
10 | 10 | let(:resource_owner) { User.create!(name: 'John', password: 'sekret') }
|
11 |
| - let(:authorization_access_token) do |
| 11 | + let(:access_token) do |
12 | 12 | FactoryGirl.create(:access_token,
|
13 | 13 | application: client_application,
|
14 | 14 | resource_owner_id: resource_owner.id,
|
15 | 15 | use_refresh_token: true)
|
16 | 16 | end
|
17 |
| - let(:headers) { { 'HTTP_AUTHORIZATION' => "Bearer #{authorization_access_token.token}" } } |
18 | 17 |
|
19 |
| - context 'With invalid token to revoke' do |
20 |
| - it 'client wants to revoke the given access token' do |
21 |
| - post revocation_token_endpoint_url, { token: 'I_AM_AN_INVALIDE_TOKEN' }, headers |
22 |
| - |
23 |
| - authorization_access_token.reload |
24 |
| - # The authorization server responds with HTTP status code 200 if the token |
25 |
| - # has been revoked successfully or if the client submitted an invalid token. |
26 |
| - expect(response).to be_success |
27 |
| - expect(authorization_access_token).to_not be_revoked |
| 18 | + context 'with authenticated, confidential OAuth 2.0 client/application' do |
| 19 | + let(:headers) do |
| 20 | + client_id = client_application.uid |
| 21 | + client_secret = client_application.secret |
| 22 | + credentials = Base64.encode64("#{client_id}:#{client_secret}") |
| 23 | + { 'HTTP_AUTHORIZATION' => "Basic #{credentials}" } |
28 | 24 | end
|
29 |
| - end |
30 |
| - |
31 |
| - context 'The access token to revoke is the same than the authorization access token' do |
32 |
| - let(:token_to_revoke) { authorization_access_token } |
33 | 25 |
|
34 |
| - it 'client wants to revoke the given access token' do |
35 |
| - post revocation_token_endpoint_url, { token: token_to_revoke.token }, headers |
| 26 | + it 'should revoke the access token provided' do |
| 27 | + post revocation_token_endpoint_url, { token: access_token.token }, headers |
36 | 28 |
|
37 |
| - token_to_revoke.reload |
38 |
| - authorization_access_token.reload |
| 29 | + access_token.reload |
39 | 30 |
|
40 | 31 | expect(response).to be_success
|
41 |
| - expect(token_to_revoke.revoked?).to be_truthy |
42 |
| - expect(Doorkeeper::AccessToken.by_refresh_token(token_to_revoke.refresh_token).revoked?).to be_truthy |
| 32 | + expect(access_token.revoked?).to be_truthy |
43 | 33 | end
|
44 | 34 |
|
45 |
| - it 'client wants to revoke the given access token using the POST query string' do |
46 |
| - url_with_query_string = revocation_token_endpoint_url + '?' + Rack::Utils.build_query(token: token_to_revoke.token) |
47 |
| - post url_with_query_string, {}, headers |
| 35 | + it 'should revoke the refresh token provided' do |
| 36 | + post revocation_token_endpoint_url, { token: access_token.refresh_token }, headers |
48 | 37 |
|
49 |
| - token_to_revoke.reload |
50 |
| - authorization_access_token.reload |
| 38 | + access_token.reload |
51 | 39 |
|
52 | 40 | expect(response).to be_success
|
53 |
| - expect(token_to_revoke.revoked?).to be_falsey |
54 |
| - expect(Doorkeeper::AccessToken.by_refresh_token(token_to_revoke.refresh_token).revoked?).to be_falsey |
55 |
| - expect(authorization_access_token.revoked?).to be_falsey |
| 41 | + expect(access_token.revoked?).to be_truthy |
56 | 42 | end
|
57 |
| - end |
58 | 43 |
|
59 |
| - context 'The access token to revoke app and owners are the same than the authorization access token' do |
60 |
| - let(:token_to_revoke) do |
61 |
| - FactoryGirl.create(:access_token, |
62 |
| - application: client_application, |
63 |
| - resource_owner_id: resource_owner.id, |
64 |
| - use_refresh_token: true) |
| 44 | + context 'with invalid token to revoke' do |
| 45 | + it 'should not revoke any tokens and respond successfully' do |
| 46 | + num_prev_revoked_tokens = Doorkeeper::AccessToken.where(revoked_at: nil).count |
| 47 | + post revocation_token_endpoint_url, { token: 'I_AM_AN_INVALID_TOKEN' }, headers |
| 48 | + |
| 49 | + # The authorization server responds with HTTP status code 200 even if |
| 50 | + # token is invalid |
| 51 | + expect(response).to be_success |
| 52 | + expect(Doorkeeper::AccessToken.where(revoked_at: nil).count).to eq(num_prev_revoked_tokens) |
| 53 | + end |
65 | 54 | end
|
66 | 55 |
|
67 |
| - it 'client wants to revoke the given access token' do |
68 |
| - post revocation_token_endpoint_url, { token: token_to_revoke.token }, headers |
| 56 | + context 'with bad credentials and a valid token' do |
| 57 | + let(:headers) do |
| 58 | + client_id = client_application.uid |
| 59 | + credentials = Base64.encode64("#{client_id}:poop") |
| 60 | + { 'HTTP_AUTHORIZATION' => "Basic #{credentials}" } |
| 61 | + end |
| 62 | + it 'should not revoke any tokens and respond successfully' do |
| 63 | + post revocation_token_endpoint_url, { token: access_token.token }, headers |
69 | 64 |
|
70 |
| - token_to_revoke.reload |
71 |
| - authorization_access_token.reload |
| 65 | + access_token.reload |
72 | 66 |
|
73 |
| - expect(response).to be_success |
74 |
| - expect(token_to_revoke.revoked?).to be_truthy |
75 |
| - expect(Doorkeeper::AccessToken.by_refresh_token(token_to_revoke.refresh_token).revoked?).to be_truthy |
76 |
| - expect(authorization_access_token.revoked?).to be_falsey |
| 67 | + expect(response).to be_success |
| 68 | + expect(access_token.revoked?).to be_falsey |
| 69 | + end |
77 | 70 | end
|
78 |
| - end |
79 | 71 |
|
80 |
| - context 'The access token to revoke authorization owner is the same than the authorization access token' do |
81 |
| - let(:other_client_application) { FactoryGirl.create :application } |
82 |
| - let(:token_to_revoke) do |
83 |
| - FactoryGirl.create(:access_token, |
84 |
| - application: other_client_application, |
85 |
| - resource_owner_id: resource_owner.id, |
86 |
| - use_refresh_token: true) |
| 72 | + context 'with no credentials and a valid token' do |
| 73 | + it 'should not revoke any tokens and respond successfully' do |
| 74 | + post revocation_token_endpoint_url, { token: access_token.token } |
| 75 | + |
| 76 | + access_token.reload |
| 77 | + |
| 78 | + expect(response).to be_success |
| 79 | + expect(access_token.revoked?).to be_falsey |
| 80 | + end |
87 | 81 | end
|
88 | 82 |
|
89 |
| - it 'client wants to revoke the given access token' do |
90 |
| - post revocation_token_endpoint_url, { token: token_to_revoke.token }, headers |
| 83 | + context 'with valid token for another client application' do |
| 84 | + let(:other_client_application) { FactoryGirl.create :application } |
| 85 | + let(:headers) do |
| 86 | + client_id = other_client_application.uid |
| 87 | + client_secret = other_client_application.secret |
| 88 | + credentials = Base64.encode64("#{client_id}:#{client_secret}") |
| 89 | + { 'HTTP_AUTHORIZATION' => "Basic #{credentials}" } |
| 90 | + end |
91 | 91 |
|
92 |
| - token_to_revoke.reload |
93 |
| - authorization_access_token.reload |
| 92 | + it 'should not revoke the token as its unauthorized' do |
| 93 | + post revocation_token_endpoint_url, { token: access_token.token }, headers |
94 | 94 |
|
95 |
| - expect(response).to be_success |
96 |
| - expect(token_to_revoke.revoked?).to be_falsey |
97 |
| - expect(Doorkeeper::AccessToken.by_refresh_token(token_to_revoke.refresh_token).revoked?).to be_falsey |
98 |
| - expect(authorization_access_token.revoked?).to be_falsey |
| 95 | + access_token.reload |
| 96 | + |
| 97 | + expect(response).to be_success |
| 98 | + expect(access_token.revoked?).to be_falsey |
| 99 | + end |
99 | 100 | end
|
100 | 101 | end
|
101 | 102 |
|
102 |
| - context 'The access token to revoke app is the same than the authorization access token' do |
103 |
| - let(:other_resource_owner) { User.create!(name: 'Matheo', password: 'pareto') } |
104 |
| - let(:token_to_revoke) do |
| 103 | + context 'with public OAuth 2.0 client/application' do |
| 104 | + let(:access_token) do |
105 | 105 | FactoryGirl.create(:access_token,
|
106 |
| - application: client_application, |
107 |
| - resource_owner_id: other_resource_owner.id, |
| 106 | + application: nil, |
| 107 | + resource_owner_id: resource_owner.id, |
108 | 108 | use_refresh_token: true)
|
109 | 109 | end
|
110 | 110 |
|
111 |
| - it 'client wants to revoke the given access token' do |
112 |
| - post revocation_token_endpoint_url, { token: token_to_revoke.token }, headers |
| 111 | + it 'should revoke the access token provided' do |
| 112 | + post revocation_token_endpoint_url, { token: access_token.token } |
113 | 113 |
|
114 |
| - token_to_revoke.reload |
115 |
| - authorization_access_token.reload |
| 114 | + access_token.reload |
116 | 115 |
|
117 | 116 | expect(response).to be_success
|
118 |
| - expect(token_to_revoke.revoked?).to be_falsey |
119 |
| - expect(Doorkeeper::AccessToken.by_refresh_token(token_to_revoke.refresh_token).revoked?).to be_falsey |
120 |
| - expect(authorization_access_token.revoked?).to be_falsey |
| 117 | + expect(access_token.revoked?).to be_truthy |
121 | 118 | end
|
122 |
| - end |
123 | 119 |
|
124 |
| - context 'With valid refresh token to revoke' do |
125 |
| - let(:token_to_revoke) do |
126 |
| - FactoryGirl.create(:access_token, |
127 |
| - application: client_application, |
128 |
| - resource_owner_id: resource_owner.id, |
129 |
| - use_refresh_token: true) |
130 |
| - end |
| 120 | + it 'should revoke the refresh token provided' do |
| 121 | + post revocation_token_endpoint_url, { token: access_token.refresh_token } |
131 | 122 |
|
132 |
| - it 'client wants to revoke the given refresh token' do |
133 |
| - post revocation_token_endpoint_url, { token: token_to_revoke.refresh_token, token_type_hint: 'refresh_token' }, headers |
134 |
| - authorization_access_token.reload |
135 |
| - token_to_revoke.reload |
| 123 | + access_token.reload |
136 | 124 |
|
137 | 125 | expect(response).to be_success
|
138 |
| - expect(Doorkeeper::AccessToken.by_refresh_token(token_to_revoke.refresh_token).revoked?).to be_truthy |
139 |
| - expect(authorization_access_token).to_not be_revoked |
| 126 | + expect(access_token.revoked?).to be_truthy |
| 127 | + end |
| 128 | + |
| 129 | + context 'with a valid token issued for a confidential client' do |
| 130 | + let(:access_token) do |
| 131 | + FactoryGirl.create(:access_token, |
| 132 | + application: client_application, |
| 133 | + resource_owner_id: resource_owner.id, |
| 134 | + use_refresh_token: true) |
| 135 | + end |
| 136 | + |
| 137 | + it 'should not revoke the access token provided' do |
| 138 | + post revocation_token_endpoint_url, { token: access_token.token } |
| 139 | + |
| 140 | + access_token.reload |
| 141 | + |
| 142 | + expect(response).to be_success |
| 143 | + expect(access_token.revoked?).to be_falsey |
| 144 | + end |
| 145 | + |
| 146 | + it 'should not revoke the refresh token provided' do |
| 147 | + post revocation_token_endpoint_url, { token: access_token.token } |
| 148 | + |
| 149 | + access_token.reload |
| 150 | + |
| 151 | + expect(response).to be_success |
| 152 | + expect(access_token.revoked?).to be_falsey |
| 153 | + end |
140 | 154 | end
|
141 | 155 | end
|
142 | 156 | end
|
|
0 commit comments