doorkeeper 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of doorkeeper might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/CHANGELOG.md +14 -2
- data/README.md +93 -42
- data/app/controllers/doorkeeper/application_controller.rb +1 -1
- data/app/controllers/doorkeeper/applications_controller.rb +4 -4
- data/app/controllers/doorkeeper/authorizations_controller.rb +3 -3
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
- data/app/controllers/doorkeeper/token_info_controller.rb +3 -3
- data/app/controllers/doorkeeper/tokens_controller.rb +29 -2
- data/app/helpers/doorkeeper/form_errors_helper.rb +2 -2
- data/app/validators/redirect_uri_validator.rb +1 -1
- data/app/views/doorkeeper/applications/_form.html.erb +3 -3
- data/app/views/doorkeeper/applications/edit.html.erb +1 -1
- data/app/views/doorkeeper/applications/new.html.erb +1 -1
- data/app/views/doorkeeper/applications/show.html.erb +1 -1
- data/app/views/doorkeeper/authorizations/new.html.erb +5 -5
- data/doorkeeper.gemspec +1 -1
- data/lib/doorkeeper.rb +31 -31
- data/lib/doorkeeper/config.rb +66 -37
- data/lib/doorkeeper/doorkeeper_for.rb +6 -3
- data/lib/doorkeeper/engine.rb +2 -2
- data/lib/doorkeeper/helpers/controller.rb +9 -9
- data/lib/doorkeeper/helpers/filter.rb +1 -1
- data/lib/doorkeeper/models/access_grant.rb +5 -5
- data/lib/doorkeeper/models/access_token.rb +22 -18
- data/lib/doorkeeper/models/active_record/access_token.rb +8 -8
- data/lib/doorkeeper/models/active_record/application.rb +5 -5
- data/lib/doorkeeper/models/application.rb +8 -9
- data/lib/doorkeeper/models/expirable.rb +1 -1
- data/lib/doorkeeper/models/mongo_mapper/access_grant.rb +2 -2
- data/lib/doorkeeper/models/mongo_mapper/access_token.rb +11 -11
- data/lib/doorkeeper/models/mongo_mapper/application.rb +4 -4
- data/lib/doorkeeper/models/mongoid/version.rb +2 -2
- data/lib/doorkeeper/models/mongoid2/access_grant.rb +7 -7
- data/lib/doorkeeper/models/mongoid2/access_token.rb +14 -14
- data/lib/doorkeeper/models/mongoid2/application.rb +7 -7
- data/lib/doorkeeper/models/mongoid3_4/access_grant.rb +7 -7
- data/lib/doorkeeper/models/mongoid3_4/access_token.rb +13 -13
- data/lib/doorkeeper/models/mongoid3_4/application.rb +6 -6
- data/lib/doorkeeper/models/ownership.rb +5 -5
- data/lib/doorkeeper/oauth/authorization/code.rb +5 -5
- data/lib/doorkeeper/oauth/authorization/token.rb +7 -7
- data/lib/doorkeeper/oauth/authorization_code_request.rb +18 -19
- data/lib/doorkeeper/oauth/client.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +4 -4
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +6 -4
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +2 -2
- data/lib/doorkeeper/oauth/client_credentials_request.rb +11 -15
- data/lib/doorkeeper/oauth/code_request.rb +5 -4
- data/lib/doorkeeper/oauth/code_response.rb +8 -7
- data/lib/doorkeeper/oauth/error.rb +1 -1
- data/lib/doorkeeper/oauth/error_response.rb +5 -5
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +1 -1
- data/lib/doorkeeper/oauth/invalid_token_response.rb +10 -10
- data/lib/doorkeeper/oauth/password_access_token_request.rb +57 -54
- data/lib/doorkeeper/oauth/pre_authorization.rb +7 -7
- data/lib/doorkeeper/oauth/refresh_token_request.rb +27 -24
- data/lib/doorkeeper/oauth/scopes.rb +3 -3
- data/lib/doorkeeper/oauth/token.rb +27 -1
- data/lib/doorkeeper/oauth/token_request.rb +14 -4
- data/lib/doorkeeper/rails/routes.rb +31 -22
- data/lib/doorkeeper/rails/routes/mapping.rb +11 -12
- data/lib/doorkeeper/request.rb +5 -5
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/generators/doorkeeper/application_owner_generator.rb +1 -1
- data/lib/generators/doorkeeper/install_generator.rb +5 -5
- data/lib/generators/doorkeeper/migration_generator.rb +1 -1
- data/lib/generators/doorkeeper/mongo_mapper/indexes_generator.rb +2 -2
- data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb +2 -2
- data/lib/generators/doorkeeper/templates/initializer.rb +16 -3
- data/lib/generators/doorkeeper/templates/migration.rb +16 -17
- data/lib/generators/doorkeeper/views_generator.rb +1 -1
- data/spec/controllers/applications_controller_spec.rb +7 -7
- data/spec/controllers/authorizations_controller_spec.rb +48 -48
- data/spec/controllers/protected_resources_controller_spec.rb +108 -107
- data/spec/controllers/token_info_controller_spec.rb +11 -11
- data/spec/controllers/tokens_controller_spec.rb +8 -8
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +2 -2
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +3 -3
- data/spec/dummy/app/controllers/home_controller.rb +5 -5
- data/spec/dummy/app/controllers/metal_controller.rb +1 -1
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +2 -2
- data/spec/dummy/app/models/user.rb +3 -3
- data/spec/dummy/config/application.rb +8 -9
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/config/initializers/doorkeeper.rb +5 -5
- data/spec/dummy/config/initializers/session_store.rb +1 -1
- data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
- data/spec/dummy/config/routes.rb +27 -27
- data/spec/dummy/db/migrate/20130902165751_create_doorkeeper_tables.rb +16 -17
- data/spec/dummy/db/migrate/20130902175349_add_owner_to_application.rb +3 -3
- data/spec/dummy/db/schema.rb +39 -39
- data/spec/factories/access_grant.rb +3 -3
- data/spec/factories/access_token.rb +1 -1
- data/spec/factories/application.rb +3 -3
- data/spec/generators/application_owner_generator_spec.rb +6 -7
- data/spec/generators/install_generator_spec.rb +9 -9
- data/spec/generators/migration_generator_spec.rb +4 -4
- data/spec/lib/config_spec.rb +136 -44
- data/spec/lib/models/expirable_spec.rb +9 -9
- data/spec/lib/models/revocable_spec.rb +4 -4
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +4 -4
- data/spec/lib/oauth/authorization_code_request_spec.rb +2 -2
- data/spec/lib/oauth/client/credentials_spec.rb +4 -4
- data/spec/lib/oauth/client/methods_spec.rb +10 -10
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +9 -7
- data/spec/lib/oauth/client_credentials/validation_spec.rb +2 -2
- data/spec/lib/oauth/client_credentials_request_spec.rb +6 -6
- data/spec/lib/oauth/client_spec.rb +4 -4
- data/spec/lib/oauth/code_request_spec.rb +10 -9
- data/spec/lib/oauth/error_response_spec.rb +8 -8
- data/spec/lib/oauth/error_spec.rb +1 -1
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +17 -17
- data/spec/lib/oauth/helpers/unique_token_spec.rb +7 -7
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +33 -33
- data/spec/lib/oauth/invalid_token_response_spec.rb +4 -4
- data/spec/lib/oauth/password_access_token_request_spec.rb +13 -13
- data/spec/lib/oauth/pre_authorization_spec.rb +47 -7
- data/spec/lib/oauth/refresh_token_request_spec.rb +11 -21
- data/spec/lib/oauth/scopes_spec.rb +32 -32
- data/spec/lib/oauth/token_request_spec.rb +10 -9
- data/spec/lib/oauth/token_response_spec.rb +13 -15
- data/spec/lib/oauth/token_spec.rb +24 -10
- data/spec/lib/server_spec.rb +24 -2
- data/spec/models/doorkeeper/access_grant_spec.rb +8 -8
- data/spec/models/doorkeeper/access_token_spec.rb +79 -33
- data/spec/models/doorkeeper/application_spec.rb +29 -29
- data/spec/requests/applications/applications_request_spec.rb +15 -15
- data/spec/requests/applications/authorized_applications_spec.rb +7 -7
- data/spec/requests/endpoints/authorization_spec.rb +19 -12
- data/spec/requests/endpoints/token_spec.rb +26 -8
- data/spec/requests/flows/authorization_code_errors_spec.rb +17 -17
- data/spec/requests/flows/authorization_code_spec.rb +28 -28
- data/spec/requests/flows/client_credentials_spec.rb +3 -3
- data/spec/requests/flows/implicit_grant_errors_spec.rb +5 -5
- data/spec/requests/flows/implicit_grant_spec.rb +2 -2
- data/spec/requests/flows/password_spec.rb +32 -32
- data/spec/requests/flows/refresh_token_spec.rb +23 -23
- data/spec/requests/flows/revoke_token_spec.rb +165 -0
- data/spec/requests/flows/skip_authorization_spec.rb +10 -10
- data/spec/requests/protected_resources/metal_spec.rb +1 -1
- data/spec/requests/protected_resources/private_api_spec.rb +5 -5
- data/spec/routing/custom_controller_routes_spec.rb +4 -0
- data/spec/routing/default_routes_spec.rb +5 -1
- data/spec/spec_helper.rb +2 -2
- data/spec/spec_helper_integration.rb +8 -10
- data/spec/support/helpers/access_token_request_helper.rb +3 -3
- data/spec/support/helpers/authorization_request_helper.rb +3 -3
- data/spec/support/helpers/config_helper.rb +1 -1
- data/spec/support/helpers/model_helper.rb +2 -2
- data/spec/support/helpers/request_spec_helper.rb +3 -3
- data/spec/support/helpers/url_helper.rb +25 -21
- data/spec/support/orm/active_record.rb +4 -4
- data/spec/support/orm/mongo_mapper.rb +2 -3
- data/spec/support/orm/mongoid.rb +5 -6
- data/spec/support/shared/controllers_shared_context.rb +15 -15
- data/spec/support/shared/models_shared_examples.rb +13 -13
- data/spec/validators/redirect_uri_validator_spec.rb +9 -9
- metadata +5 -4
@@ -2,207 +2,207 @@ require 'spec_helper_integration'
|
|
2
2
|
|
3
3
|
module ControllerActions
|
4
4
|
def index
|
5
|
-
render :
|
5
|
+
render text: 'index'
|
6
6
|
end
|
7
7
|
|
8
8
|
def show
|
9
|
-
render :
|
9
|
+
render text: 'show'
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
shared_examples
|
14
|
-
context
|
15
|
-
it
|
16
|
-
get :index, :
|
13
|
+
shared_examples 'specified for particular actions' do
|
14
|
+
context 'with valid token', token: :valid do
|
15
|
+
it 'allows into index action' do
|
16
|
+
get :index, access_token: token_string
|
17
17
|
expect(response).to be_success
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
get :show, :
|
20
|
+
it 'allows into show action' do
|
21
|
+
get :show, id: '3', access_token: token_string
|
22
22
|
expect(response).to be_success
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
context
|
27
|
-
include_context
|
26
|
+
context 'with invalid token', token: :invalid do
|
27
|
+
include_context 'invalid token'
|
28
28
|
|
29
|
-
it
|
30
|
-
get :index, :
|
29
|
+
it 'does not allow into index action' do
|
30
|
+
get :index, access_token: token_string
|
31
31
|
expect(response.status).to eq 401
|
32
|
-
expect(response.headers[
|
32
|
+
expect(response.headers['WWW-Authenticate']).to match(/^Bearer/)
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
36
|
-
get :show, :
|
35
|
+
it 'allows into show action' do
|
36
|
+
get :show, id: '5', access_token: token_string
|
37
37
|
expect(response).to be_success
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
shared_examples
|
43
|
-
context
|
44
|
-
it
|
45
|
-
get :index, :
|
42
|
+
shared_examples 'specified with except' do
|
43
|
+
context 'with valid token', token: :valid do
|
44
|
+
it 'allows into index action' do
|
45
|
+
get :index, access_token: token_string
|
46
46
|
expect(response).to be_success
|
47
47
|
end
|
48
48
|
|
49
|
-
it
|
50
|
-
get :show, :
|
49
|
+
it 'allows into show action' do
|
50
|
+
get :show, id: '4', access_token: token_string
|
51
51
|
expect(response).to be_success
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
context
|
56
|
-
it
|
57
|
-
get :index, :
|
55
|
+
context 'with invalid token', token: :invalid do
|
56
|
+
it 'allows into index action' do
|
57
|
+
get :index, access_token: token_string
|
58
58
|
expect(response).to be_success
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
62
|
-
get :show, :
|
61
|
+
it 'does not allow into show action' do
|
62
|
+
get :show, id: '14', access_token: token_string
|
63
63
|
expect(response.status).to eq 401
|
64
|
-
expect(response.headers[
|
64
|
+
expect(response.headers['WWW-Authenticate']).to match(/^Bearer/)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
describe
|
70
|
-
context
|
69
|
+
describe 'Doorkeeper_for helper' do
|
70
|
+
context 'accepts token code specified as' do
|
71
71
|
controller do
|
72
72
|
doorkeeper_for :all
|
73
73
|
|
74
74
|
def index
|
75
|
-
render :
|
75
|
+
render text: 'index'
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
let(:token_string) {
|
79
|
+
let(:token_string) { '1A2BC3' }
|
80
80
|
|
81
|
-
it
|
81
|
+
it 'access_token param' do
|
82
82
|
expect(Doorkeeper::AccessToken).to receive(:authenticate).with(token_string)
|
83
|
-
get :index, :
|
83
|
+
get :index, access_token: token_string
|
84
84
|
end
|
85
85
|
|
86
|
-
it
|
86
|
+
it 'bearer_token param' do
|
87
87
|
expect(Doorkeeper::AccessToken).to receive(:authenticate).with(token_string)
|
88
|
-
get :index, :
|
88
|
+
get :index, bearer_token: token_string
|
89
89
|
end
|
90
90
|
|
91
|
-
it
|
91
|
+
it 'Authorization header' do
|
92
92
|
expect(Doorkeeper::AccessToken).to receive(:authenticate).with(token_string)
|
93
|
-
request.env[
|
93
|
+
request.env['HTTP_AUTHORIZATION'] = "Bearer #{token_string}"
|
94
94
|
get :index
|
95
95
|
end
|
96
96
|
|
97
|
-
it
|
97
|
+
it 'different kind of Authorization header' do
|
98
98
|
expect(Doorkeeper::AccessToken).not_to receive(:authenticate)
|
99
|
-
request.env[
|
99
|
+
request.env['HTTP_AUTHORIZATION'] = "MAC #{token_string}"
|
100
100
|
get :index
|
101
101
|
end
|
102
102
|
|
103
|
-
it
|
103
|
+
it 'does not change Authorization header value' do
|
104
104
|
expect(Doorkeeper::AccessToken).to receive(:authenticate).exactly(2).times
|
105
|
-
request.env[
|
105
|
+
request.env['HTTP_AUTHORIZATION'] = "Bearer #{token_string}"
|
106
106
|
get :index
|
107
107
|
controller.send(:remove_instance_variable, :@token)
|
108
108
|
get :index
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
-
context
|
112
|
+
context 'defined for all actions' do
|
113
113
|
controller do
|
114
114
|
doorkeeper_for :all
|
115
115
|
|
116
116
|
include ControllerActions
|
117
117
|
end
|
118
118
|
|
119
|
-
context
|
120
|
-
it
|
121
|
-
get :index, :
|
119
|
+
context 'with valid token', token: :valid do
|
120
|
+
it 'allows into index action' do
|
121
|
+
get :index, access_token: token_string
|
122
122
|
expect(response).to be_success
|
123
123
|
end
|
124
124
|
|
125
|
-
it
|
126
|
-
get :show, :
|
125
|
+
it 'allows into show action' do
|
126
|
+
get :show, id: '4', access_token: token_string
|
127
127
|
expect(response).to be_success
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
-
context
|
132
|
-
it
|
133
|
-
get :index, :
|
131
|
+
context 'with invalid token', token: :invalid do
|
132
|
+
it 'does not allow into index action' do
|
133
|
+
get :index, access_token: token_string
|
134
134
|
expect(response.status).to eq 401
|
135
|
-
expect(response.header[
|
135
|
+
expect(response.header['WWW-Authenticate']).to match(/^Bearer/)
|
136
136
|
end
|
137
137
|
|
138
|
-
it
|
139
|
-
get :show, :
|
138
|
+
it 'does not allow into show action' do
|
139
|
+
get :show, id: '4', access_token: token_string
|
140
140
|
expect(response.status).to eq 401
|
141
|
-
expect(response.header[
|
141
|
+
expect(response.header['WWW-Authenticate']).to match(/^Bearer/)
|
142
142
|
end
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
|
-
context
|
146
|
+
context 'defined only for index action' do
|
147
147
|
controller do
|
148
148
|
doorkeeper_for :index
|
149
149
|
|
150
150
|
include ControllerActions
|
151
151
|
end
|
152
|
-
include_examples
|
152
|
+
include_examples 'specified for particular actions'
|
153
153
|
end
|
154
154
|
|
155
|
-
context
|
155
|
+
context 'defined for actions except index' do
|
156
156
|
controller do
|
157
|
-
doorkeeper_for :all, :
|
157
|
+
doorkeeper_for :all, except: :index
|
158
158
|
|
159
159
|
include ControllerActions
|
160
160
|
end
|
161
|
-
include_examples
|
161
|
+
include_examples 'specified with except'
|
162
162
|
end
|
163
163
|
|
164
|
-
context
|
164
|
+
context 'defined with scopes' do
|
165
165
|
controller do
|
166
|
-
doorkeeper_for :all, :
|
166
|
+
doorkeeper_for :all, scopes: [:write]
|
167
167
|
|
168
168
|
include ControllerActions
|
169
169
|
end
|
170
170
|
|
171
|
-
let(:token_string) {
|
171
|
+
let(:token_string) { '1A2DUWE' }
|
172
172
|
|
173
|
-
it
|
174
|
-
token = double(Doorkeeper::AccessToken,
|
173
|
+
it 'allows if the token has particular scopes' do
|
174
|
+
token = double(Doorkeeper::AccessToken, accessible?: true, scopes: %w(write public))
|
175
175
|
expect(Doorkeeper::AccessToken).to receive(:authenticate).with(token_string).and_return(token)
|
176
|
-
get :index, :
|
176
|
+
get :index, access_token: token_string
|
177
177
|
expect(response).to be_success
|
178
178
|
end
|
179
179
|
|
180
|
-
it
|
181
|
-
token = double(Doorkeeper::AccessToken,
|
180
|
+
it 'does not allow if the token does not include given scope' do
|
181
|
+
token = double(Doorkeeper::AccessToken, accessible?: true, scopes: ['public'], revoked?: false, expired?: false)
|
182
182
|
expect(Doorkeeper::AccessToken).to receive(:authenticate).with(token_string).and_return(token)
|
183
|
-
get :index, :
|
183
|
+
get :index, access_token: token_string
|
184
184
|
expect(response.status).to eq 401
|
185
|
-
expect(response.header[
|
185
|
+
expect(response.header['WWW-Authenticate']).to match(/^Bearer/)
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
|
-
context
|
189
|
+
context 'when custom unauthorized render options are configured' do
|
190
190
|
controller do
|
191
191
|
doorkeeper_for :all
|
192
192
|
|
193
193
|
include ControllerActions
|
194
194
|
end
|
195
195
|
|
196
|
-
context
|
196
|
+
context 'with a JSON custom render', token: :invalid do
|
197
197
|
before do
|
198
|
-
expect(controller).to receive(:doorkeeper_unauthorized_render_options).and_return(
|
198
|
+
expect(controller).to receive(:doorkeeper_unauthorized_render_options).and_return(json: ActiveSupport::JSON.encode(error: 'Unauthorized'))
|
199
199
|
end
|
200
200
|
|
201
|
-
it
|
202
|
-
get :index, :
|
201
|
+
it 'it renders a custom JSON response', token: :invalid do
|
202
|
+
get :index, access_token: token_string
|
203
203
|
expect(response.status).to eq 401
|
204
204
|
expect(response.content_type).to eq('application/json')
|
205
|
-
expect(response.header[
|
205
|
+
expect(response.header['WWW-Authenticate']).to match(/^Bearer/)
|
206
206
|
parsed_body = JSON.parse(response.body)
|
207
207
|
expect(parsed_body).not_to be_nil
|
208
208
|
expect(parsed_body['error']).to eq('Unauthorized')
|
@@ -210,29 +210,30 @@ describe "Doorkeeper_for helper" do
|
|
210
210
|
|
211
211
|
end
|
212
212
|
|
213
|
-
context
|
213
|
+
context 'with a text custom render', token: :invalid do
|
214
214
|
before do
|
215
|
-
expect(controller).to receive(:doorkeeper_unauthorized_render_options).and_return(
|
215
|
+
expect(controller).to receive(:doorkeeper_unauthorized_render_options).and_return(text: 'Unauthorized')
|
216
216
|
end
|
217
217
|
|
218
|
-
it
|
219
|
-
get :index, :
|
218
|
+
it 'it renders a custom JSON response', token: :invalid do
|
219
|
+
get :index, access_token: token_string
|
220
220
|
expect(response.status).to eq 401
|
221
221
|
expect(response.content_type).to eq('text/html')
|
222
|
-
expect(response.header[
|
222
|
+
expect(response.header['WWW-Authenticate']).to match(/^Bearer/)
|
223
223
|
expect(response.body).to eq('Unauthorized')
|
224
224
|
end
|
225
225
|
end
|
226
226
|
end
|
227
227
|
|
228
|
-
context
|
228
|
+
context 'when defined with conditional if block' do
|
229
229
|
controller do
|
230
|
-
doorkeeper_for :index, :
|
231
|
-
doorkeeper_for :show,
|
230
|
+
doorkeeper_for :index, if: -> { the_false }
|
231
|
+
doorkeeper_for :show, if: -> { the_true }
|
232
232
|
|
233
233
|
include ControllerActions
|
234
234
|
|
235
235
|
private
|
236
|
+
|
236
237
|
def the_true
|
237
238
|
true
|
238
239
|
end
|
@@ -242,36 +243,36 @@ describe "Doorkeeper_for helper" do
|
|
242
243
|
end
|
243
244
|
end
|
244
245
|
|
245
|
-
context
|
246
|
-
it
|
247
|
-
get :index, :
|
246
|
+
context 'with valid token', token: :valid do
|
247
|
+
it 'enables access if passed block evaluates to false' do
|
248
|
+
get :index, access_token: token_string
|
248
249
|
expect(response).to be_success
|
249
250
|
end
|
250
251
|
|
251
|
-
it
|
252
|
-
get :show, :
|
252
|
+
it 'enables access if passed block evaluates to true' do
|
253
|
+
get :show, id: 1, access_token: token_string
|
253
254
|
expect(response).to be_success
|
254
255
|
end
|
255
256
|
end
|
256
257
|
|
257
|
-
context
|
258
|
-
it
|
259
|
-
get :index, :
|
258
|
+
context 'with invalid token', token: :invalid do
|
259
|
+
it 'enables access if passed block evaluates to false' do
|
260
|
+
get :index, access_token: token_string
|
260
261
|
expect(response).to be_success
|
261
262
|
end
|
262
263
|
|
263
|
-
it
|
264
|
-
get :show, :
|
264
|
+
it 'does not enable access if passed block evaluates to true' do
|
265
|
+
get :show, id: 3, access_token: token_string
|
265
266
|
expect(response.status).to eq 401
|
266
|
-
expect(response.header[
|
267
|
+
expect(response.header['WWW-Authenticate']).to match(/^Bearer/)
|
267
268
|
end
|
268
269
|
end
|
269
270
|
end
|
270
271
|
|
271
|
-
context
|
272
|
+
context 'when defined with conditional unless block' do
|
272
273
|
controller do
|
273
|
-
doorkeeper_for :index, :
|
274
|
-
doorkeeper_for :show, :
|
274
|
+
doorkeeper_for :index, unless: -> { the_false }
|
275
|
+
doorkeeper_for :show, unless: -> { the_true }
|
275
276
|
|
276
277
|
include ControllerActions
|
277
278
|
|
@@ -286,25 +287,25 @@ describe "Doorkeeper_for helper" do
|
|
286
287
|
end
|
287
288
|
end
|
288
289
|
|
289
|
-
context
|
290
|
-
it
|
291
|
-
get :index, :
|
290
|
+
context 'with valid token', token: :valid do
|
291
|
+
it 'allows access if passed block evaluates to false' do
|
292
|
+
get :index, access_token: token_string
|
292
293
|
expect(response).to be_success
|
293
294
|
end
|
294
295
|
|
295
|
-
it
|
296
|
-
get :show, :
|
296
|
+
it 'allows access if passed block evaluates to true' do
|
297
|
+
get :show, id: 1, access_token: token_string
|
297
298
|
expect(response).to be_success
|
298
299
|
end
|
299
300
|
end
|
300
301
|
|
301
|
-
context
|
302
|
-
it
|
303
|
-
get :index, :
|
302
|
+
context 'with invalid token', token: :invalid do
|
303
|
+
it 'does not allow access if passed block evaluates to false' do
|
304
|
+
get :index, access_token: token_string
|
304
305
|
end
|
305
306
|
|
306
|
-
it
|
307
|
-
get :show, :
|
307
|
+
it 'allows access if passed block evaluates to true' do
|
308
|
+
get :show, id: 3, access_token: token_string
|
308
309
|
expect(response).to be_success
|
309
310
|
end
|
310
311
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper_integration'
|
|
2
2
|
|
3
3
|
describe Doorkeeper::TokenInfoController do
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe 'when requesting tokeninfo with valid token' do
|
6
6
|
|
7
7
|
let(:doorkeeper_token) { FactoryGirl.create(:access_token) }
|
8
8
|
|
@@ -14,40 +14,40 @@ describe Doorkeeper::TokenInfoController do
|
|
14
14
|
get :show
|
15
15
|
end
|
16
16
|
|
17
|
-
describe
|
17
|
+
describe 'successful request' do
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'responds with tokeninfo' do
|
20
20
|
do_get
|
21
21
|
expect(response.body).to eq(doorkeeper_token.to_json)
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it 'responds with a 200 status' do
|
25
25
|
do_get
|
26
26
|
expect(response.status).to eq 200
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
describe
|
30
|
+
describe 'invalid token response' do
|
31
31
|
before(:each) do
|
32
32
|
allow(controller).to receive(:doorkeeper_token).and_return(nil)
|
33
33
|
end
|
34
|
-
it
|
34
|
+
it 'responds with 401 when doorkeeper_token is not valid' do
|
35
35
|
do_get
|
36
36
|
expect(response.status).to eq 401
|
37
|
-
expect(response.headers[
|
37
|
+
expect(response.headers['WWW-Authenticate']).to match(/^Bearer/)
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
40
|
+
it 'responds with 401 when doorkeeper_token is invalid, expired or revoked' do
|
41
41
|
allow(controller).to receive(:doorkeeper_token).and_return(doorkeeper_token)
|
42
42
|
allow(doorkeeper_token).to receive(:accessible?).and_return(false)
|
43
43
|
do_get
|
44
44
|
expect(response.status).to eq 401
|
45
|
-
expect(response.headers[
|
45
|
+
expect(response.headers['WWW-Authenticate']).to match(/^Bearer/)
|
46
46
|
end
|
47
47
|
|
48
|
-
it
|
48
|
+
it 'responds body message for error' do
|
49
49
|
do_get
|
50
|
-
expect(response.body).to eq(Doorkeeper::OAuth::ErrorResponse.new(:
|
50
|
+
expect(response.body).to eq(Doorkeeper::OAuth::ErrorResponse.new(name: :invalid_request, status: :unauthorized).body.to_json)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|