doorkeeper 1.4.2 → 2.0.0.alpha1
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/.hound.yml +3 -0
- data/CHANGELOG.md +18 -11
- data/Gemfile +7 -7
- data/README.md +20 -41
- data/app/controllers/doorkeeper/application_controller.rb +1 -7
- data/app/controllers/doorkeeper/applications_controller.rb +4 -5
- data/app/controllers/doorkeeper/tokens_controller.rb +2 -2
- data/app/helpers/doorkeeper/{form_errors_helper.rb → dashboard_helper.rb} +5 -1
- data/app/views/doorkeeper/applications/_delete_form.html.erb +1 -1
- data/app/views/doorkeeper/applications/_form.html.erb +1 -1
- data/app/views/doorkeeper/applications/index.html.erb +1 -1
- data/config/locales/en.yml +3 -3
- data/lib/doorkeeper.rb +15 -6
- data/lib/doorkeeper/config.rb +18 -24
- data/lib/doorkeeper/engine.rb +1 -6
- data/lib/doorkeeper/generators/doorkeeper/mongo_mapper/indexes_generator.rb +12 -0
- data/lib/{generators/doorkeeper → doorkeeper/generators/doorkeeper/mongo_mapper}/templates/indexes.rb +0 -0
- data/lib/doorkeeper/models/access_grant_mixin.rb +36 -0
- data/lib/doorkeeper/models/access_token_mixin.rb +121 -0
- data/lib/doorkeeper/models/application_mixin.rb +42 -0
- data/lib/doorkeeper/models/{accessible.rb → concerns/accessible.rb} +0 -0
- data/lib/doorkeeper/models/{expirable.rb → concerns/expirable.rb} +6 -5
- data/lib/doorkeeper/models/{ownership.rb → concerns/ownership.rb} +7 -7
- data/lib/doorkeeper/models/{revocable.rb → concerns/revocable.rb} +1 -1
- data/lib/doorkeeper/models/concerns/scopes.rb +17 -0
- data/lib/doorkeeper/oauth/authorization/token.rb +6 -6
- data/lib/doorkeeper/oauth/client.rb +1 -1
- data/lib/doorkeeper/oauth/password_access_token_request.rb +3 -3
- data/lib/doorkeeper/oauth/refresh_token_request.rb +6 -6
- data/lib/doorkeeper/oauth/token.rb +3 -2
- data/lib/doorkeeper/orm/active_record.rb +17 -0
- data/lib/doorkeeper/orm/active_record/access_grant.rb +7 -0
- data/lib/doorkeeper/orm/active_record/access_token.rb +20 -0
- data/lib/doorkeeper/{models → orm}/active_record/application.rb +1 -3
- data/lib/doorkeeper/orm/mongo_mapper.rb +11 -0
- data/lib/doorkeeper/{models → orm}/mongo_mapper/access_grant.rb +4 -5
- data/lib/doorkeeper/{models → orm}/mongo_mapper/access_token.rb +5 -8
- data/lib/doorkeeper/{models → orm}/mongo_mapper/application.rb +3 -4
- data/lib/doorkeeper/orm/mongoid2.rb +11 -0
- data/lib/doorkeeper/{models → orm}/mongoid2/access_grant.rb +5 -3
- data/lib/doorkeeper/{models → orm}/mongoid2/access_token.rb +10 -13
- data/lib/doorkeeper/{models → orm}/mongoid2/application.rb +2 -0
- data/lib/doorkeeper/orm/mongoid2/concerns/scopes.rb +30 -0
- data/lib/doorkeeper/orm/mongoid3.rb +11 -0
- data/lib/doorkeeper/orm/mongoid3/access_grant.rb +22 -0
- data/lib/doorkeeper/orm/mongoid3/access_token.rb +36 -0
- data/lib/doorkeeper/{models/mongoid3_4 → orm/mongoid3}/application.rb +2 -0
- data/lib/doorkeeper/orm/mongoid3/concerns/scopes.rb +30 -0
- data/lib/doorkeeper/orm/mongoid4.rb +11 -0
- data/lib/doorkeeper/orm/mongoid4/access_grant.rb +22 -0
- data/lib/doorkeeper/orm/mongoid4/access_token.rb +36 -0
- data/lib/doorkeeper/orm/mongoid4/application.rb +24 -0
- data/lib/doorkeeper/orm/mongoid4/concerns/scopes.rb +17 -0
- data/lib/doorkeeper/rails/helpers.rb +63 -0
- data/lib/doorkeeper/rails/routes.rb +1 -12
- data/lib/doorkeeper/request/code.rb +0 -1
- data/lib/doorkeeper/request/token.rb +0 -1
- data/lib/doorkeeper/server.rb +1 -1
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/generators/doorkeeper/templates/initializer.rb +2 -1
- data/spec/controllers/applications_controller_spec.rb +4 -4
- data/spec/controllers/protected_resources_controller_spec.rb +25 -175
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +2 -2
- data/spec/dummy/app/controllers/metal_controller.rb +2 -2
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +2 -2
- data/spec/dummy/config/application.rb +2 -0
- data/spec/lib/config_spec.rb +16 -10
- data/spec/lib/models/expirable_spec.rb +1 -1
- data/spec/lib/models/revocable_spec.rb +8 -3
- data/spec/lib/models/scopes_spec.rb +3 -3
- data/spec/lib/oauth/password_access_token_request_spec.rb +1 -1
- data/spec/lib/oauth/token_request_spec.rb +28 -1
- data/spec/lib/oauth/token_spec.rb +1 -1
- data/spec/models/doorkeeper/application_spec.rb +1 -1
- data/spec/requests/applications/applications_request_spec.rb +4 -4
- data/spec/requests/endpoints/authorization_spec.rb +0 -23
- data/spec/requests/flows/implicit_grant_spec.rb +32 -0
- data/spec/support/shared/controllers_shared_context.rb +2 -2
- metadata +40 -35
- data/lib/doorkeeper/doorkeeper_for.rb +0 -69
- data/lib/doorkeeper/helpers/filter.rb +0 -64
- data/lib/doorkeeper/models/access_grant.rb +0 -30
- data/lib/doorkeeper/models/access_token.rb +0 -106
- data/lib/doorkeeper/models/active_record/access_grant.rb +0 -9
- data/lib/doorkeeper/models/active_record/access_token.rb +0 -25
- data/lib/doorkeeper/models/application.rb +0 -40
- data/lib/doorkeeper/models/mongoid/scopes.rb +0 -15
- data/lib/doorkeeper/models/mongoid/version.rb +0 -15
- data/lib/doorkeeper/models/mongoid3_4/access_grant.rb +0 -27
- data/lib/doorkeeper/models/mongoid3_4/access_token.rb +0 -46
- data/lib/doorkeeper/models/scopes.rb +0 -21
- data/lib/generators/doorkeeper/mongo_mapper/indexes_generator.rb +0 -12
- data/script/rails +0 -5
- data/script/run_all +0 -14
@@ -0,0 +1,63 @@
|
|
1
|
+
module Doorkeeper
|
2
|
+
module Rails
|
3
|
+
module Helpers
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def doorkeeper_for(*args, &block)
|
8
|
+
fail Errors::DoorkeeperError, "`doorkeeper_for` no longer available", <<-eos
|
9
|
+
\nStarting in version 2.0.0 of doorkeeper gem, `doorkeeper_for` is no longer
|
10
|
+
available. Please change `doorkeeper_for` calls in your application with:
|
11
|
+
|
12
|
+
before_action :doorkeeper_authorize!
|
13
|
+
|
14
|
+
For more information check the README:
|
15
|
+
https://github.com/doorkeeper-gem/doorkeeper#protecting-resources-with-oauth-aka-your-api-endpoint\n
|
16
|
+
eos
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def doorkeeper_token
|
21
|
+
@_doorkeeper_token ||= OAuth::Token.authenticate request, *Doorkeeper.configuration.access_token_methods
|
22
|
+
end
|
23
|
+
|
24
|
+
def valid_doorkeeper_token?(*scopes)
|
25
|
+
doorkeeper_token && doorkeeper_token.acceptable?(scopes)
|
26
|
+
end
|
27
|
+
|
28
|
+
def doorkeeper_authorize!(*scopes)
|
29
|
+
scopes ||= Doorkeeper.configuration.default_scopes
|
30
|
+
|
31
|
+
unless valid_doorkeeper_token?(*scopes)
|
32
|
+
if !doorkeeper_token || !doorkeeper_token.accessible?
|
33
|
+
error = OAuth::InvalidTokenResponse.from_access_token(doorkeeper_token)
|
34
|
+
options = doorkeeper_unauthorized_render_options
|
35
|
+
else
|
36
|
+
error = OAuth::ForbiddenTokenResponse.from_scopes(scopes)
|
37
|
+
options = doorkeeper_forbidden_render_options
|
38
|
+
end
|
39
|
+
headers.merge!(error.headers.reject { |k| ['Content-Type'].include? k })
|
40
|
+
doorkeeper_error_renderer(error, options)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def doorkeeper_unauthorized_render_options
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
|
48
|
+
def doorkeeper_forbidden_render_options
|
49
|
+
nil
|
50
|
+
end
|
51
|
+
|
52
|
+
def doorkeeper_error_renderer(error, options = {})
|
53
|
+
if options.blank?
|
54
|
+
head error.status
|
55
|
+
else
|
56
|
+
options[:status] = error.status
|
57
|
+
options[:layout] = false if options[:layout].nil?
|
58
|
+
render options
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -15,17 +15,6 @@ module Doorkeeper
|
|
15
15
|
ActionDispatch::Routing::Mapper.send :include, Doorkeeper::Rails::Routes::Helper
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.warn_if_using_mount_method!
|
19
|
-
paths = ::Rails.application.config.paths['config/routes'] ||
|
20
|
-
::Rails.application.config.paths['config/routes.rb']
|
21
|
-
|
22
|
-
paths.each do |path|
|
23
|
-
if File.read(::Rails.root.join(path)) =~ %r{mount Doorkeeper::Engine}
|
24
|
-
warn "\n[DOORKEEPER] `mount Doorkeeper::Engine` is not being used anymore. Please replace it with `use_doorkeeper` in your #{path} file\n"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
18
|
attr_accessor :routes
|
30
19
|
|
31
20
|
def initialize(routes, &block)
|
@@ -88,7 +77,7 @@ module Doorkeeper
|
|
88
77
|
end
|
89
78
|
|
90
79
|
def application_routes(mapping)
|
91
|
-
routes.resources :
|
80
|
+
routes.resources :doorkeeper_applications, controller: mapping[:controllers], as: :applications, path: 'applications'
|
92
81
|
end
|
93
82
|
|
94
83
|
def authorized_applications_routes(mapping)
|
data/lib/doorkeeper/server.rb
CHANGED
data/lib/doorkeeper/version.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
Doorkeeper.configure do
|
2
2
|
# Change the ORM that doorkeeper will use.
|
3
|
-
# Currently supported options are :active_record, :mongoid2, :mongoid3,
|
3
|
+
# Currently supported options are :active_record, :mongoid2, :mongoid3,
|
4
|
+
# :mongoid4, :mongo_mapper
|
4
5
|
orm :active_record
|
5
6
|
|
6
7
|
# This block will be called to check whether the resource owner is authenticated or not.
|
@@ -16,7 +16,7 @@ module Doorkeeper
|
|
16
16
|
|
17
17
|
it 'does not create application' do
|
18
18
|
expect do
|
19
|
-
post :create,
|
19
|
+
post :create, doorkeeper_application: {
|
20
20
|
name: 'Example',
|
21
21
|
redirect_uri: 'http://example.com' }
|
22
22
|
end.to_not change { Doorkeeper::Application.count }
|
@@ -30,7 +30,7 @@ module Doorkeeper
|
|
30
30
|
|
31
31
|
it 'creates application' do
|
32
32
|
expect do
|
33
|
-
post :create,
|
33
|
+
post :create, doorkeeper_application: {
|
34
34
|
name: 'Example',
|
35
35
|
redirect_uri: 'http://example.com' }
|
36
36
|
end.to change { Doorkeeper::Application.count }.by(1)
|
@@ -39,7 +39,7 @@ module Doorkeeper
|
|
39
39
|
|
40
40
|
it 'does not allow mass assignment of uid or secret' do
|
41
41
|
application = FactoryGirl.create(:application)
|
42
|
-
put :update, id: application.id,
|
42
|
+
put :update, id: application.id, doorkeeper_application: {
|
43
43
|
uid: '1A2B3C4D',
|
44
44
|
secret: '1A2B3C4D' }
|
45
45
|
|
@@ -48,7 +48,7 @@ module Doorkeeper
|
|
48
48
|
|
49
49
|
it 'updates application' do
|
50
50
|
application = FactoryGirl.create(:application)
|
51
|
-
put :update, id: application.id,
|
51
|
+
put :update, id: application.id, doorkeeper_application: {
|
52
52
|
name: 'Example',
|
53
53
|
redirect_uri: 'http://example.com' }
|
54
54
|
expect(application.reload.name).to eq 'Example'
|
@@ -10,66 +10,10 @@ module ControllerActions
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
context 'with valid token', token: :valid do
|
15
|
-
it 'allows into index action' do
|
16
|
-
get :index, access_token: token_string
|
17
|
-
expect(response).to be_success
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'allows into show action' do
|
21
|
-
get :show, id: '3', access_token: token_string
|
22
|
-
expect(response).to be_success
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'with invalid token', token: :invalid do
|
27
|
-
include_context 'invalid token'
|
28
|
-
|
29
|
-
it 'does not allow into index action' do
|
30
|
-
get :index, access_token: token_string
|
31
|
-
expect(response.status).to eq 401
|
32
|
-
expect(response.headers['WWW-Authenticate']).to match(/^Bearer/)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'allows into show action' do
|
36
|
-
get :show, id: '5', access_token: token_string
|
37
|
-
expect(response).to be_success
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
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
|
-
expect(response).to be_success
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'allows into show action' do
|
50
|
-
get :show, id: '4', access_token: token_string
|
51
|
-
expect(response).to be_success
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'with invalid token', token: :invalid do
|
56
|
-
it 'allows into index action' do
|
57
|
-
get :index, access_token: token_string
|
58
|
-
expect(response).to be_success
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'does not allow into show action' do
|
62
|
-
get :show, id: '14', access_token: token_string
|
63
|
-
expect(response.status).to eq 401
|
64
|
-
expect(response.headers['WWW-Authenticate']).to match(/^Bearer/)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe 'Doorkeeper_for helper' do
|
13
|
+
describe 'doorkeeper authorize filter' do
|
70
14
|
context 'accepts token code specified as' do
|
71
15
|
controller do
|
72
|
-
|
16
|
+
before_filter :doorkeeper_authorize!
|
73
17
|
|
74
18
|
def index
|
75
19
|
render text: 'index'
|
@@ -82,39 +26,39 @@ describe 'Doorkeeper_for helper' do
|
|
82
26
|
end
|
83
27
|
|
84
28
|
it 'access_token param' do
|
85
|
-
expect(Doorkeeper::AccessToken).to receive(:
|
29
|
+
expect(Doorkeeper::AccessToken).to receive(:by_token).with(token_string).and_return(token)
|
86
30
|
get :index, access_token: token_string
|
87
31
|
end
|
88
32
|
|
89
33
|
it 'bearer_token param' do
|
90
|
-
expect(Doorkeeper::AccessToken).to receive(:
|
34
|
+
expect(Doorkeeper::AccessToken).to receive(:by_token).with(token_string).and_return(token)
|
91
35
|
get :index, bearer_token: token_string
|
92
36
|
end
|
93
37
|
|
94
38
|
it 'Authorization header' do
|
95
|
-
expect(Doorkeeper::AccessToken).to receive(:
|
39
|
+
expect(Doorkeeper::AccessToken).to receive(:by_token).with(token_string).and_return(token)
|
96
40
|
request.env['HTTP_AUTHORIZATION'] = "Bearer #{token_string}"
|
97
41
|
get :index
|
98
42
|
end
|
99
43
|
|
100
44
|
it 'different kind of Authorization header' do
|
101
|
-
expect(Doorkeeper::AccessToken).not_to receive(:
|
45
|
+
expect(Doorkeeper::AccessToken).not_to receive(:by_token)
|
102
46
|
request.env['HTTP_AUTHORIZATION'] = "MAC #{token_string}"
|
103
47
|
get :index
|
104
48
|
end
|
105
49
|
|
106
50
|
it 'does not change Authorization header value' do
|
107
|
-
expect(Doorkeeper::AccessToken).to receive(:
|
51
|
+
expect(Doorkeeper::AccessToken).to receive(:by_token).exactly(2).times.and_return(token)
|
108
52
|
request.env['HTTP_AUTHORIZATION'] = "Bearer #{token_string}"
|
109
53
|
get :index
|
110
|
-
controller.send(:remove_instance_variable, :@
|
54
|
+
controller.send(:remove_instance_variable, :@_doorkeeper_token)
|
111
55
|
get :index
|
112
56
|
end
|
113
57
|
end
|
114
58
|
|
115
59
|
context 'defined for all actions' do
|
116
60
|
controller do
|
117
|
-
|
61
|
+
before_filter :doorkeeper_authorize!
|
118
62
|
|
119
63
|
include ControllerActions
|
120
64
|
end
|
@@ -146,27 +90,9 @@ describe 'Doorkeeper_for helper' do
|
|
146
90
|
end
|
147
91
|
end
|
148
92
|
|
149
|
-
context 'defined only for index action' do
|
150
|
-
controller do
|
151
|
-
doorkeeper_for :index
|
152
|
-
|
153
|
-
include ControllerActions
|
154
|
-
end
|
155
|
-
include_examples 'specified for particular actions'
|
156
|
-
end
|
157
|
-
|
158
|
-
context 'defined for actions except index' do
|
159
|
-
controller do
|
160
|
-
doorkeeper_for :all, except: :index
|
161
|
-
|
162
|
-
include ControllerActions
|
163
|
-
end
|
164
|
-
include_examples 'specified with except'
|
165
|
-
end
|
166
|
-
|
167
93
|
context 'defined with scopes' do
|
168
94
|
controller do
|
169
|
-
|
95
|
+
before_filter -> { doorkeeper_authorize! :write }
|
170
96
|
|
171
97
|
include ControllerActions
|
172
98
|
end
|
@@ -175,16 +101,16 @@ describe 'Doorkeeper_for helper' do
|
|
175
101
|
|
176
102
|
it 'allows if the token has particular scopes' do
|
177
103
|
token = double(Doorkeeper::AccessToken, accessible?: true, scopes: %w(write public))
|
178
|
-
expect(token).to receive(:acceptable?).with([
|
179
|
-
expect(Doorkeeper::AccessToken).to receive(:
|
104
|
+
expect(token).to receive(:acceptable?).with([:write]).and_return(true)
|
105
|
+
expect(Doorkeeper::AccessToken).to receive(:by_token).with(token_string).and_return(token)
|
180
106
|
get :index, access_token: token_string
|
181
107
|
expect(response).to be_success
|
182
108
|
end
|
183
109
|
|
184
110
|
it 'does not allow if the token does not include given scope' do
|
185
111
|
token = double(Doorkeeper::AccessToken, accessible?: true, scopes: ['public'], revoked?: false, expired?: false)
|
186
|
-
expect(Doorkeeper::AccessToken).to receive(:
|
187
|
-
expect(token).to receive(:acceptable?).with([
|
112
|
+
expect(Doorkeeper::AccessToken).to receive(:by_token).with(token_string).and_return(token)
|
113
|
+
expect(token).to receive(:acceptable?).with([:write]).and_return(false)
|
188
114
|
get :index, access_token: token_string
|
189
115
|
expect(response.status).to eq 403
|
190
116
|
expect(response.header).to_not include('WWW-Authenticate')
|
@@ -193,7 +119,7 @@ describe 'Doorkeeper_for helper' do
|
|
193
119
|
|
194
120
|
context 'when custom unauthorized render options are configured' do
|
195
121
|
controller do
|
196
|
-
|
122
|
+
before_filter :doorkeeper_authorize!
|
197
123
|
|
198
124
|
include ControllerActions
|
199
125
|
end
|
@@ -212,7 +138,6 @@ describe 'Doorkeeper_for helper' do
|
|
212
138
|
expect(parsed_body).not_to be_nil
|
213
139
|
expect(parsed_body['error']).to eq('Unauthorized')
|
214
140
|
end
|
215
|
-
|
216
141
|
end
|
217
142
|
|
218
143
|
context 'with a text custom render', token: :invalid do
|
@@ -230,91 +155,16 @@ describe 'Doorkeeper_for helper' do
|
|
230
155
|
end
|
231
156
|
end
|
232
157
|
|
233
|
-
context '
|
234
|
-
controller
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
true
|
244
|
-
end
|
245
|
-
|
246
|
-
def the_false
|
247
|
-
false
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
context 'with valid token', token: :valid do
|
252
|
-
it 'enables access if passed block evaluates to false' do
|
253
|
-
get :index, access_token: token_string
|
254
|
-
expect(response).to be_success
|
255
|
-
end
|
256
|
-
|
257
|
-
it 'enables access if passed block evaluates to true' do
|
258
|
-
get :show, id: 1, access_token: token_string
|
259
|
-
expect(response).to be_success
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
context 'with invalid token', token: :invalid do
|
264
|
-
it 'enables access if passed block evaluates to false' do
|
265
|
-
get :index, access_token: token_string
|
266
|
-
expect(response).to be_success
|
267
|
-
end
|
268
|
-
|
269
|
-
it 'does not enable access if passed block evaluates to true' do
|
270
|
-
get :show, id: 3, access_token: token_string
|
271
|
-
expect(response.status).to eq 401
|
272
|
-
expect(response.header['WWW-Authenticate']).to match(/^Bearer/)
|
273
|
-
end
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
context 'when defined with conditional unless block' do
|
278
|
-
controller do
|
279
|
-
doorkeeper_for :index, unless: -> { the_false }
|
280
|
-
doorkeeper_for :show, unless: -> { the_true }
|
281
|
-
|
282
|
-
include ControllerActions
|
283
|
-
|
284
|
-
def the_true
|
285
|
-
true
|
286
|
-
end
|
287
|
-
|
288
|
-
private
|
289
|
-
|
290
|
-
def the_false
|
291
|
-
false
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
context 'with valid token', token: :valid do
|
296
|
-
it 'allows access if passed block evaluates to false' do
|
297
|
-
get :index, access_token: token_string
|
298
|
-
expect(response).to be_success
|
299
|
-
end
|
300
|
-
|
301
|
-
it 'allows access if passed block evaluates to true' do
|
302
|
-
get :show, id: 1, access_token: token_string
|
303
|
-
expect(response).to be_success
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
context 'with invalid token', token: :invalid do
|
308
|
-
it 'does not allow access if passed block evaluates to false' do
|
309
|
-
get :index, access_token: token_string
|
310
|
-
expect(response.status).to eq 401
|
311
|
-
expect(response.header['WWW-Authenticate']).to match(/^Bearer/)
|
312
|
-
end
|
313
|
-
|
314
|
-
it 'allows access if passed block evaluates to true' do
|
315
|
-
get :show, id: 3, access_token: token_string
|
316
|
-
expect(response).to be_success
|
317
|
-
end
|
158
|
+
context 'defined for all actions' do
|
159
|
+
controller {}
|
160
|
+
|
161
|
+
it 'it renders a custom JSON response', token: :invalid do
|
162
|
+
expect do
|
163
|
+
controller.class.doorkeeper_for
|
164
|
+
end.to raise_error(
|
165
|
+
Doorkeeper::Errors::DoorkeeperError,
|
166
|
+
/`doorkeeper_for` no longer available/
|
167
|
+
)
|
318
168
|
end
|
319
169
|
end
|
320
170
|
end
|