doorkeeper 4.4.3 → 5.0.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/.gitignore +1 -0
- data/.gitlab-ci.yml +16 -0
- data/.travis.yml +2 -0
- data/Appraisals +2 -2
- data/Gemfile +1 -1
- data/NEWS.md +61 -8
- data/README.md +92 -9
- data/Rakefile +6 -0
- data/UPGRADE.md +2 -0
- data/app/assets/stylesheets/doorkeeper/admin/application.css +2 -2
- data/app/controllers/doorkeeper/application_controller.rb +4 -3
- data/app/controllers/doorkeeper/application_metal_controller.rb +4 -0
- data/app/controllers/doorkeeper/applications_controller.rb +42 -22
- data/app/controllers/doorkeeper/authorizations_controller.rb +55 -12
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +19 -2
- data/app/controllers/doorkeeper/tokens_controller.rb +2 -6
- data/app/helpers/doorkeeper/dashboard_helper.rb +7 -7
- data/app/validators/redirect_uri_validator.rb +3 -2
- data/app/views/doorkeeper/applications/_delete_form.html.erb +3 -1
- data/app/views/doorkeeper/applications/_form.html.erb +25 -24
- data/app/views/doorkeeper/applications/edit.html.erb +1 -1
- data/app/views/doorkeeper/applications/index.html.erb +17 -7
- data/app/views/doorkeeper/applications/new.html.erb +1 -1
- data/app/views/doorkeeper/applications/show.html.erb +6 -6
- data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
- data/app/views/doorkeeper/authorizations/new.html.erb +4 -0
- data/app/views/layouts/doorkeeper/admin.html.erb +15 -15
- data/config/locales/en.yml +10 -1
- data/doorkeeper.gemspec +18 -20
- data/gemfiles/rails_5_2.gemfile +1 -1
- data/gemfiles/rails_master.gemfile +4 -1
- data/lib/doorkeeper/config.rb +75 -39
- data/lib/doorkeeper/engine.rb +4 -0
- data/lib/doorkeeper/errors.rb +2 -5
- data/lib/doorkeeper/grape/helpers.rb +1 -1
- data/lib/doorkeeper/helpers/controller.rb +7 -2
- data/lib/doorkeeper/models/access_grant_mixin.rb +71 -0
- data/lib/doorkeeper/models/access_token_mixin.rb +39 -22
- data/lib/doorkeeper/models/concerns/scopes.rb +1 -1
- data/lib/doorkeeper/oauth/authorization/code.rb +31 -8
- data/lib/doorkeeper/oauth/authorization/context.rb +15 -0
- data/lib/doorkeeper/oauth/authorization/token.rb +36 -14
- data/lib/doorkeeper/oauth/authorization_code_request.rb +27 -2
- data/lib/doorkeeper/oauth/base_request.rb +20 -9
- data/lib/doorkeeper/oauth/client/credentials.rb +1 -1
- data/lib/doorkeeper/oauth/client.rb +0 -2
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +2 -1
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +6 -3
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +4 -6
- data/lib/doorkeeper/oauth/client_credentials_request.rb +0 -4
- data/lib/doorkeeper/oauth/error_response.rb +11 -3
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +0 -8
- data/lib/doorkeeper/oauth/password_access_token_request.rb +7 -4
- data/lib/doorkeeper/oauth/pre_authorization.rb +41 -11
- data/lib/doorkeeper/oauth/refresh_token_request.rb +6 -1
- data/lib/doorkeeper/oauth/scopes.rb +1 -1
- data/lib/doorkeeper/oauth/token.rb +5 -2
- data/lib/doorkeeper/oauth/token_introspection.rb +2 -2
- data/lib/doorkeeper/oauth/token_response.rb +4 -2
- data/lib/doorkeeper/oauth.rb +13 -0
- data/lib/doorkeeper/orm/active_record/application.rb +22 -14
- data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +26 -0
- data/lib/doorkeeper/orm/active_record.rb +2 -0
- data/lib/doorkeeper/rails/helpers.rb +2 -4
- data/lib/doorkeeper/rails/routes.rb +14 -6
- data/lib/doorkeeper/rake/db.rake +40 -0
- data/lib/doorkeeper/rake/setup.rake +6 -0
- data/lib/doorkeeper/rake.rb +14 -0
- data/lib/doorkeeper/request/authorization_code.rb +0 -2
- data/lib/doorkeeper/request/client_credentials.rb +0 -2
- data/lib/doorkeeper/request/code.rb +0 -2
- data/lib/doorkeeper/request/password.rb +0 -2
- data/lib/doorkeeper/request/refresh_token.rb +0 -2
- data/lib/doorkeeper/request/token.rb +0 -2
- data/lib/doorkeeper/request.rb +28 -35
- data/lib/doorkeeper/version.rb +5 -25
- data/lib/doorkeeper.rb +19 -17
- data/lib/generators/doorkeeper/application_owner_generator.rb +23 -18
- data/lib/generators/doorkeeper/confidential_applications_generator.rb +32 -0
- data/lib/generators/doorkeeper/install_generator.rb +17 -9
- data/lib/generators/doorkeeper/migration_generator.rb +23 -18
- data/lib/generators/doorkeeper/pkce_generator.rb +32 -0
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -24
- data/lib/generators/doorkeeper/templates/add_confidential_to_applications.rb.erb +13 -0
- data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +6 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +76 -11
- data/lib/generators/doorkeeper/views_generator.rb +3 -1
- data/spec/controllers/application_metal_controller_spec.rb +50 -0
- data/spec/controllers/applications_controller_spec.rb +126 -13
- data/spec/controllers/authorizations_controller_spec.rb +277 -47
- data/spec/controllers/protected_resources_controller_spec.rb +16 -16
- data/spec/controllers/token_info_controller_spec.rb +4 -12
- data/spec/controllers/tokens_controller_spec.rb +13 -15
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/dummy/config/environments/test.rb +4 -5
- data/spec/dummy/config/initializers/doorkeeper.rb +10 -5
- data/spec/dummy/config/initializers/new_framework_defaults.rb +4 -0
- data/spec/dummy/config/routes.rb +3 -42
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +6 -0
- data/spec/dummy/db/migrate/{20180210183654_add_confidential_to_application.rb → 20180210183654_add_confidential_to_applications.rb} +1 -1
- data/spec/dummy/db/schema.rb +36 -36
- data/spec/generators/application_owner_generator_spec.rb +1 -1
- data/spec/generators/confidential_applications_generator_spec.rb +45 -0
- data/spec/generators/install_generator_spec.rb +1 -1
- data/spec/generators/migration_generator_spec.rb +1 -1
- data/spec/generators/pkce_generator_spec.rb +43 -0
- data/spec/generators/previous_refresh_token_generator_spec.rb +1 -1
- data/spec/generators/views_generator_spec.rb +1 -1
- data/spec/grape/grape_integration_spec.rb +1 -1
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
- data/spec/lib/config_spec.rb +80 -31
- data/spec/lib/doorkeeper_spec.rb +1 -126
- data/spec/lib/models/expirable_spec.rb +0 -3
- data/spec/lib/models/revocable_spec.rb +0 -2
- data/spec/lib/models/scopes_spec.rb +0 -4
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -4
- data/spec/lib/oauth/authorization_code_request_spec.rb +9 -2
- data/spec/lib/oauth/base_request_spec.rb +40 -2
- data/spec/lib/oauth/base_response_spec.rb +1 -1
- data/spec/lib/oauth/client/credentials_spec.rb +1 -3
- data/spec/lib/oauth/client_credentials/creator_spec.rb +5 -1
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +26 -7
- data/spec/lib/oauth/client_credentials/validation_spec.rb +2 -3
- data/spec/lib/oauth/client_credentials_integration_spec.rb +1 -1
- data/spec/lib/oauth/client_credentials_request_spec.rb +3 -5
- data/spec/lib/oauth/client_spec.rb +0 -3
- data/spec/lib/oauth/code_request_spec.rb +4 -2
- data/spec/lib/oauth/error_response_spec.rb +0 -3
- data/spec/lib/oauth/error_spec.rb +0 -2
- data/spec/lib/oauth/forbidden_token_response_spec.rb +1 -4
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -3
- data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -1
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +5 -7
- data/spec/lib/oauth/invalid_token_response_spec.rb +1 -4
- data/spec/lib/oauth/password_access_token_request_spec.rb +37 -2
- data/spec/lib/oauth/pre_authorization_spec.rb +33 -4
- data/spec/lib/oauth/refresh_token_request_spec.rb +11 -7
- data/spec/lib/oauth/scopes_spec.rb +0 -3
- data/spec/lib/oauth/token_request_spec.rb +4 -5
- data/spec/lib/oauth/token_response_spec.rb +0 -1
- data/spec/lib/oauth/token_spec.rb +37 -14
- data/spec/lib/orm/active_record/stale_records_cleaner_spec.rb +79 -0
- data/spec/lib/request/strategy_spec.rb +0 -1
- data/spec/lib/server_spec.rb +1 -1
- data/spec/models/doorkeeper/access_grant_spec.rb +44 -1
- data/spec/models/doorkeeper/access_token_spec.rb +66 -22
- data/spec/models/doorkeeper/application_spec.rb +14 -47
- data/spec/requests/applications/applications_request_spec.rb +134 -1
- data/spec/requests/applications/authorized_applications_spec.rb +1 -1
- data/spec/requests/endpoints/authorization_spec.rb +1 -1
- data/spec/requests/endpoints/token_spec.rb +7 -5
- data/spec/requests/flows/authorization_code_errors_spec.rb +1 -1
- data/spec/requests/flows/authorization_code_spec.rb +197 -1
- data/spec/requests/flows/client_credentials_spec.rb +46 -6
- data/spec/requests/flows/implicit_grant_errors_spec.rb +1 -1
- data/spec/requests/flows/implicit_grant_spec.rb +38 -11
- data/spec/requests/flows/password_spec.rb +56 -2
- data/spec/requests/flows/refresh_token_spec.rb +2 -2
- data/spec/requests/flows/revoke_token_spec.rb +11 -11
- data/spec/requests/flows/skip_authorization_spec.rb +16 -11
- data/spec/requests/protected_resources/metal_spec.rb +1 -1
- data/spec/requests/protected_resources/private_api_spec.rb +1 -1
- data/spec/routing/custom_controller_routes_spec.rb +59 -7
- data/spec/routing/default_routes_spec.rb +2 -2
- data/spec/routing/scoped_routes_spec.rb +16 -2
- data/spec/spec_helper.rb +54 -3
- data/spec/spec_helper_integration.rb +2 -74
- data/spec/support/dependencies/{factory_girl.rb → factory_bot.rb} +0 -0
- data/spec/support/doorkeeper_rspec.rb +19 -0
- data/spec/support/helpers/authorization_request_helper.rb +4 -4
- data/spec/support/helpers/request_spec_helper.rb +10 -2
- data/spec/support/helpers/url_helper.rb +7 -3
- data/spec/support/http_method_shim.rb +12 -16
- data/spec/validators/redirect_uri_validator_spec.rb +7 -1
- data/spec/version/version_spec.rb +3 -3
- data/vendor/assets/stylesheets/doorkeeper/bootstrap.min.css +4 -5
- metadata +37 -33
- data/lib/generators/doorkeeper/add_client_confidentiality_generator.rb +0 -31
- data/lib/generators/doorkeeper/templates/add_confidential_to_application_migration.rb.erb +0 -11
- data/spec/controllers/application_metal_controller.rb +0 -10
data/spec/lib/config_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Doorkeeper, 'configuration' do
|
4
4
|
subject { Doorkeeper.configuration }
|
@@ -66,6 +66,17 @@ describe Doorkeeper, 'configuration' do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
describe 'admin_authenticator' do
|
69
|
+
it 'sets the block that is accessible via authenticate_admin' do
|
70
|
+
default_behaviour = 'default behaviour'
|
71
|
+
allow(Doorkeeper::Config).to receive(:head).and_return(default_behaviour)
|
72
|
+
|
73
|
+
Doorkeeper.configure do
|
74
|
+
orm DOORKEEPER_ORM
|
75
|
+
end
|
76
|
+
|
77
|
+
expect(subject.authenticate_admin.call({})).to eq(default_behaviour)
|
78
|
+
end
|
79
|
+
|
69
80
|
it 'sets the block that is accessible via authenticate_admin' do
|
70
81
|
block = proc {}
|
71
82
|
Doorkeeper.configure do
|
@@ -122,7 +133,7 @@ describe Doorkeeper, 'configuration' do
|
|
122
133
|
it 'has all scopes' do
|
123
134
|
Doorkeeper.configure do
|
124
135
|
orm DOORKEEPER_ORM
|
125
|
-
default_scopes
|
136
|
+
default_scopes :normal
|
126
137
|
optional_scopes :admin
|
127
138
|
end
|
128
139
|
|
@@ -132,7 +143,7 @@ describe Doorkeeper, 'configuration' do
|
|
132
143
|
|
133
144
|
describe 'use_refresh_token' do
|
134
145
|
it 'is false by default' do
|
135
|
-
expect(subject.refresh_token_enabled?).to
|
146
|
+
expect(subject.refresh_token_enabled?).to eq(false)
|
136
147
|
end
|
137
148
|
|
138
149
|
it 'can change the value' do
|
@@ -141,7 +152,25 @@ describe Doorkeeper, 'configuration' do
|
|
141
152
|
use_refresh_token
|
142
153
|
end
|
143
154
|
|
144
|
-
expect(subject.refresh_token_enabled?).to
|
155
|
+
expect(subject.refresh_token_enabled?).to eq(true)
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'can accept a boolean parameter' do
|
159
|
+
Doorkeeper.configure do
|
160
|
+
orm DOORKEEPER_ORM
|
161
|
+
use_refresh_token false
|
162
|
+
end
|
163
|
+
|
164
|
+
expect(subject.refresh_token_enabled?).to eq(false)
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'can accept a block parameter' do
|
168
|
+
Doorkeeper.configure do
|
169
|
+
orm DOORKEEPER_ORM
|
170
|
+
use_refresh_token { |_context| nil }
|
171
|
+
end
|
172
|
+
|
173
|
+
expect(subject.refresh_token_enabled?).to be_a(Proc)
|
145
174
|
end
|
146
175
|
|
147
176
|
it "does not includes 'refresh_token' in authorization_response_types" do
|
@@ -162,28 +191,18 @@ describe Doorkeeper, 'configuration' do
|
|
162
191
|
end
|
163
192
|
end
|
164
193
|
|
165
|
-
describe '
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
opt_out_native_route_change
|
170
|
-
end
|
171
|
-
|
172
|
-
Rails.application.reload_routes!
|
173
|
-
|
174
|
-
subject { Doorkeeper.configuration }
|
175
|
-
|
176
|
-
example.run
|
194
|
+
describe 'enforce_configured_scopes' do
|
195
|
+
it 'is false by default' do
|
196
|
+
expect(subject.enforce_configured_scopes?).to eq(false)
|
197
|
+
end
|
177
198
|
|
199
|
+
it 'can change the value' do
|
178
200
|
Doorkeeper.configure do
|
179
201
|
orm DOORKEEPER_ORM
|
202
|
+
enforce_configured_scopes
|
180
203
|
end
|
181
204
|
|
182
|
-
|
183
|
-
end
|
184
|
-
|
185
|
-
it 'sets the native authorization code route /:code' do
|
186
|
-
expect(subject.native_authorization_code_route).to eq('/:code')
|
205
|
+
expect(subject.enforce_configured_scopes?).to eq(true)
|
187
206
|
end
|
188
207
|
end
|
189
208
|
|
@@ -204,7 +223,7 @@ describe Doorkeeper, 'configuration' do
|
|
204
223
|
|
205
224
|
describe 'force_ssl_in_redirect_uri' do
|
206
225
|
it 'is true by default in non-development environments' do
|
207
|
-
expect(subject.force_ssl_in_redirect_uri).to
|
226
|
+
expect(subject.force_ssl_in_redirect_uri).to eq(true)
|
208
227
|
end
|
209
228
|
|
210
229
|
it 'can change the value' do
|
@@ -213,7 +232,7 @@ describe Doorkeeper, 'configuration' do
|
|
213
232
|
force_ssl_in_redirect_uri(false)
|
214
233
|
end
|
215
234
|
|
216
|
-
expect(subject.force_ssl_in_redirect_uri).to
|
235
|
+
expect(subject.force_ssl_in_redirect_uri).to eq(false)
|
217
236
|
end
|
218
237
|
|
219
238
|
it 'can be a callable object' do
|
@@ -224,7 +243,7 @@ describe Doorkeeper, 'configuration' do
|
|
224
243
|
end
|
225
244
|
|
226
245
|
expect(subject.force_ssl_in_redirect_uri).to eq(block)
|
227
|
-
expect(subject.force_ssl_in_redirect_uri.call).to
|
246
|
+
expect(subject.force_ssl_in_redirect_uri.call).to eq(false)
|
228
247
|
end
|
229
248
|
end
|
230
249
|
|
@@ -245,7 +264,7 @@ describe Doorkeeper, 'configuration' do
|
|
245
264
|
|
246
265
|
describe 'forbid_redirect_uri' do
|
247
266
|
it 'is false by default' do
|
248
|
-
expect(subject.forbid_redirect_uri.call(URI.parse('https://localhost'))).to
|
267
|
+
expect(subject.forbid_redirect_uri.call(URI.parse('https://localhost'))).to eq(false)
|
249
268
|
end
|
250
269
|
|
251
270
|
it 'can be a callable object' do
|
@@ -256,13 +275,13 @@ describe Doorkeeper, 'configuration' do
|
|
256
275
|
end
|
257
276
|
|
258
277
|
expect(subject.forbid_redirect_uri).to eq(block)
|
259
|
-
expect(subject.forbid_redirect_uri.call).to
|
278
|
+
expect(subject.forbid_redirect_uri.call).to eq(true)
|
260
279
|
end
|
261
280
|
end
|
262
281
|
|
263
282
|
describe 'enable_application_owner' do
|
264
283
|
it 'is disabled by default' do
|
265
|
-
expect(Doorkeeper.configuration.enable_application_owner?).not_to
|
284
|
+
expect(Doorkeeper.configuration.enable_application_owner?).not_to eq(true)
|
266
285
|
end
|
267
286
|
|
268
287
|
context 'when enabled without confirmation' do
|
@@ -278,7 +297,7 @@ describe Doorkeeper, 'configuration' do
|
|
278
297
|
end
|
279
298
|
|
280
299
|
it 'Doorkeeper.configuration.confirm_application_owner? returns false' do
|
281
|
-
expect(Doorkeeper.configuration.confirm_application_owner?).not_to
|
300
|
+
expect(Doorkeeper.configuration.confirm_application_owner?).not_to eq(true)
|
282
301
|
end
|
283
302
|
end
|
284
303
|
|
@@ -295,7 +314,7 @@ describe Doorkeeper, 'configuration' do
|
|
295
314
|
end
|
296
315
|
|
297
316
|
it 'Doorkeeper.configuration.confirm_application_owner? returns true' do
|
298
|
-
expect(Doorkeeper.configuration.confirm_application_owner?).to
|
317
|
+
expect(Doorkeeper.configuration.confirm_application_owner?).to eq(true)
|
299
318
|
end
|
300
319
|
end
|
301
320
|
end
|
@@ -324,10 +343,10 @@ describe Doorkeeper, 'configuration' do
|
|
324
343
|
it "can change the value" do
|
325
344
|
Doorkeeper.configure do
|
326
345
|
orm DOORKEEPER_ORM
|
327
|
-
grant_flows [
|
346
|
+
grant_flows %w[authorization_code implicit]
|
328
347
|
end
|
329
348
|
|
330
|
-
expect(subject.grant_flows).to eq [
|
349
|
+
expect(subject.grant_flows).to eq %w[authorization_code implicit]
|
331
350
|
end
|
332
351
|
|
333
352
|
context "when including 'authorization_code'" do
|
@@ -459,4 +478,34 @@ describe Doorkeeper, 'configuration' do
|
|
459
478
|
end
|
460
479
|
end
|
461
480
|
end
|
481
|
+
|
482
|
+
describe "api_only" do
|
483
|
+
it "is false by default" do
|
484
|
+
expect(subject.api_only).to eq(false)
|
485
|
+
end
|
486
|
+
|
487
|
+
it "can change the value" do
|
488
|
+
Doorkeeper.configure do
|
489
|
+
orm DOORKEEPER_ORM
|
490
|
+
api_only
|
491
|
+
end
|
492
|
+
|
493
|
+
expect(subject.api_only).to eq(true)
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
describe 'strict_content_type' do
|
498
|
+
it 'is false by default' do
|
499
|
+
expect(subject.enforce_content_type).to eq(false)
|
500
|
+
end
|
501
|
+
|
502
|
+
it "can change the value" do
|
503
|
+
Doorkeeper.configure do
|
504
|
+
orm DOORKEEPER_ORM
|
505
|
+
enforce_content_type
|
506
|
+
end
|
507
|
+
|
508
|
+
expect(subject.enforce_content_type).to eq(true)
|
509
|
+
end
|
510
|
+
end
|
462
511
|
end
|
data/spec/lib/doorkeeper_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Doorkeeper do
|
4
4
|
describe "#authenticate" do
|
@@ -22,129 +22,4 @@ describe Doorkeeper do
|
|
22
22
|
Doorkeeper.authenticate(request, token_strategies)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
26
|
-
describe "#configured?" do
|
27
|
-
after do
|
28
|
-
Doorkeeper.remove_instance_variable(:@config)
|
29
|
-
end
|
30
|
-
|
31
|
-
context "@config is set" do
|
32
|
-
it "returns true" do
|
33
|
-
Doorkeeper.instance_variable_set(:@config, "hi")
|
34
|
-
|
35
|
-
expect(Doorkeeper.configured?).to eq(true)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context "@config is not set" do
|
40
|
-
it "returns false" do
|
41
|
-
Doorkeeper.instance_variable_set(:@config, nil)
|
42
|
-
|
43
|
-
expect(Doorkeeper.configured?).to eq(false)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
it "is deprecated" do
|
48
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).
|
49
|
-
with("Method `Doorkeeper#configured?` has been deprecated without replacement.")
|
50
|
-
|
51
|
-
Doorkeeper.configured?
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "#database_installed?" do
|
56
|
-
before do
|
57
|
-
["AccessToken", "AccessGrant", "Application"].each do |klass|
|
58
|
-
@original_classes ||= {}
|
59
|
-
@original_classes[klass] = Doorkeeper.const_get(klass)
|
60
|
-
Doorkeeper.send(:remove_const, klass)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
after do
|
65
|
-
["AccessToken", "AccessGrant", "Application"].each do |klass|
|
66
|
-
Doorkeeper.send(:remove_const, klass)
|
67
|
-
Doorkeeper.const_set(klass, @original_classes[klass])
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "all tables exist" do
|
72
|
-
before do
|
73
|
-
klass = double table_exists?: true
|
74
|
-
|
75
|
-
Doorkeeper.const_set(:AccessToken, klass)
|
76
|
-
Doorkeeper.const_set(:AccessGrant, klass)
|
77
|
-
Doorkeeper.const_set(:Application, klass)
|
78
|
-
end
|
79
|
-
|
80
|
-
it "returns true" do
|
81
|
-
expect(Doorkeeper.database_installed?).to eq(true)
|
82
|
-
end
|
83
|
-
|
84
|
-
it "is deprecated" do
|
85
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).
|
86
|
-
with("Method `Doorkeeper#database_installed?` has been deprecated without replacement.")
|
87
|
-
|
88
|
-
Doorkeeper.database_installed?
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
context "all tables do not exist" do
|
93
|
-
before do
|
94
|
-
klass = double table_exists?: false
|
95
|
-
|
96
|
-
Doorkeeper.const_set(:AccessToken, klass)
|
97
|
-
Doorkeeper.const_set(:AccessGrant, klass)
|
98
|
-
Doorkeeper.const_set(:Application, klass)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "returns false" do
|
102
|
-
expect(Doorkeeper.database_installed?).to eq(false)
|
103
|
-
end
|
104
|
-
|
105
|
-
it "is deprecated" do
|
106
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).
|
107
|
-
with("Method `Doorkeeper#database_installed?` has been deprecated without replacement.")
|
108
|
-
|
109
|
-
Doorkeeper.database_installed?
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe "#installed?" do
|
115
|
-
context "methods return true" do
|
116
|
-
before do
|
117
|
-
allow(Doorkeeper).to receive(:configured?).and_return(true).once
|
118
|
-
allow(Doorkeeper).to receive(:database_installed?).and_return(true).once
|
119
|
-
end
|
120
|
-
|
121
|
-
it "returns true" do
|
122
|
-
expect(Doorkeeper.installed?).to eq(true)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
context "methods return false" do
|
127
|
-
before do
|
128
|
-
allow(Doorkeeper).to receive(:configured?).and_return(false).once
|
129
|
-
allow(Doorkeeper).to receive(:database_installed?).and_return(false).once
|
130
|
-
end
|
131
|
-
|
132
|
-
it "returns false" do
|
133
|
-
expect(Doorkeeper.installed?).to eq(false)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
it "is deprecated" do
|
138
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).
|
139
|
-
with("Method `Doorkeeper#configured?` has been deprecated without replacement.")
|
140
|
-
|
141
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).
|
142
|
-
with("Method `Doorkeeper#database_installed?` has been deprecated without replacement.")
|
143
|
-
|
144
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).
|
145
|
-
with("Method `Doorkeeper#installed?` has been deprecated without replacement.")
|
146
|
-
|
147
|
-
Doorkeeper.installed?
|
148
|
-
end
|
149
|
-
end
|
150
25
|
end
|
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'active_support/time'
|
3
|
-
require 'doorkeeper/models/concerns/expirable'
|
4
2
|
|
5
3
|
describe 'Expirable' do
|
6
4
|
subject do
|
@@ -45,6 +43,5 @@ describe 'Expirable' do
|
|
45
43
|
allow(subject).to receive(:expires_in).and_return(nil)
|
46
44
|
expect(subject.expires_in_seconds).to be_nil
|
47
45
|
end
|
48
|
-
|
49
46
|
end
|
50
47
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module Doorkeeper::OAuth
|
4
4
|
describe AuthorizationCodeRequest do
|
@@ -6,7 +6,9 @@ module Doorkeeper::OAuth
|
|
6
6
|
double :server,
|
7
7
|
access_token_expires_in: 2.days,
|
8
8
|
refresh_token_enabled?: false,
|
9
|
-
custom_access_token_expires_in:
|
9
|
+
custom_access_token_expires_in: lambda { |context|
|
10
|
+
context.grant_type == Doorkeeper::OAuth::AUTHORIZATION_CODE ? 1234 : nil
|
11
|
+
}
|
10
12
|
end
|
11
13
|
|
12
14
|
let(:grant) { FactoryBot.create :access_grant }
|
@@ -22,6 +24,8 @@ module Doorkeeper::OAuth
|
|
22
24
|
expect do
|
23
25
|
subject.authorize
|
24
26
|
end.to change { client.reload.access_tokens.count }.by(1)
|
27
|
+
|
28
|
+
expect(client.reload.access_tokens.sort_by(&:created_at).last.expires_in).to eq(1234)
|
25
29
|
end
|
26
30
|
|
27
31
|
it "issues the token with same grant's scopes" do
|
@@ -70,9 +74,12 @@ module Doorkeeper::OAuth
|
|
70
74
|
end
|
71
75
|
|
72
76
|
it 'skips token creation if there is a matching one' do
|
77
|
+
scopes = grant.scopes
|
78
|
+
|
73
79
|
Doorkeeper.configure do
|
74
80
|
orm DOORKEEPER_ORM
|
75
81
|
reuse_access_token
|
82
|
+
default_scopes(*scopes)
|
76
83
|
end
|
77
84
|
|
78
85
|
FactoryBot.create(:access_token, application_id: client.id,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module Doorkeeper::OAuth
|
4
4
|
describe BaseRequest do
|
@@ -20,7 +20,7 @@ module Doorkeeper::OAuth
|
|
20
20
|
let(:server) do
|
21
21
|
double :server,
|
22
22
|
access_token_expires_in: 100,
|
23
|
-
custom_access_token_expires_in: ->(
|
23
|
+
custom_access_token_expires_in: ->(_context) { nil },
|
24
24
|
refresh_token_enabled?: false
|
25
25
|
end
|
26
26
|
|
@@ -105,6 +105,44 @@ module Doorkeeper::OAuth
|
|
105
105
|
|
106
106
|
expect(result).to be_an_instance_of(Doorkeeper::AccessToken)
|
107
107
|
end
|
108
|
+
|
109
|
+
it "respects custom_access_token_expires_in" do
|
110
|
+
server = double(:server,
|
111
|
+
access_token_expires_in: 100,
|
112
|
+
custom_access_token_expires_in: ->(context) { context.scopes == "public" ? 500 : nil },
|
113
|
+
refresh_token_enabled?: false)
|
114
|
+
result = subject.find_or_create_access_token(
|
115
|
+
client,
|
116
|
+
"1",
|
117
|
+
"public",
|
118
|
+
server
|
119
|
+
)
|
120
|
+
expect(result.expires_in).to eql(500)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "respects use_refresh_token with a block" do
|
124
|
+
server = double(:server,
|
125
|
+
access_token_expires_in: 100,
|
126
|
+
custom_access_token_expires_in: ->(_context) { nil },
|
127
|
+
refresh_token_enabled?: lambda { |context|
|
128
|
+
context.scopes == "public"
|
129
|
+
})
|
130
|
+
result = subject.find_or_create_access_token(
|
131
|
+
client,
|
132
|
+
"1",
|
133
|
+
"public",
|
134
|
+
server
|
135
|
+
)
|
136
|
+
expect(result.refresh_token).to_not be_nil
|
137
|
+
|
138
|
+
result = subject.find_or_create_access_token(
|
139
|
+
client,
|
140
|
+
"1",
|
141
|
+
"private",
|
142
|
+
server
|
143
|
+
)
|
144
|
+
expect(result.refresh_token).to be_nil
|
145
|
+
end
|
108
146
|
end
|
109
147
|
|
110
148
|
describe "#scopes" do
|
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'active_support/core_ext/string'
|
3
|
-
require 'doorkeeper/oauth/client'
|
4
2
|
|
5
3
|
class Doorkeeper::OAuth::Client
|
6
4
|
describe Credentials do
|
@@ -18,7 +16,7 @@ class Doorkeeper::OAuth::Client
|
|
18
16
|
let(:request) { double.as_null_object }
|
19
17
|
|
20
18
|
let(:method) do
|
21
|
-
->(_request) {
|
19
|
+
->(_request) { ['uid', 'secret'] }
|
22
20
|
end
|
23
21
|
|
24
22
|
it 'accepts anything that responds to #call' do
|
@@ -1,10 +1,14 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
class Doorkeeper::OAuth::ClientCredentialsRequest
|
4
4
|
describe Creator do
|
5
5
|
let(:client) { FactoryBot.create :application }
|
6
6
|
let(:scopes) { Doorkeeper::OAuth::Scopes.from_string('public') }
|
7
7
|
|
8
|
+
before do
|
9
|
+
default_scopes_exist :public
|
10
|
+
end
|
11
|
+
|
8
12
|
it 'creates a new token' do
|
9
13
|
expect do
|
10
14
|
subject.call(client, scopes)
|
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'active_support/all'
|
3
|
-
require 'doorkeeper/oauth/client_credentials/issuer'
|
4
2
|
|
5
3
|
class Doorkeeper::OAuth::ClientCredentialsRequest
|
6
4
|
describe Issuer do
|
@@ -9,7 +7,7 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
|
|
9
7
|
double(
|
10
8
|
:server,
|
11
9
|
access_token_expires_in: 100,
|
12
|
-
custom_access_token_expires_in: ->(
|
10
|
+
custom_access_token_expires_in: ->(_context) { nil }
|
13
11
|
)
|
14
12
|
end
|
15
13
|
let(:validation) { double :validation, valid?: true }
|
@@ -63,23 +61,44 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
|
|
63
61
|
end
|
64
62
|
|
65
63
|
context 'with custom expirations' do
|
66
|
-
let(:
|
64
|
+
let(:custom_ttl_grant) { 1234 }
|
65
|
+
let(:custom_ttl_scope) { 1235 }
|
66
|
+
let(:custom_scope) { 'special' }
|
67
67
|
let(:server) do
|
68
68
|
double(
|
69
69
|
:server,
|
70
|
-
custom_access_token_expires_in:
|
70
|
+
custom_access_token_expires_in: lambda { |context|
|
71
|
+
# scopes is normally an object but is a string in this test
|
72
|
+
if context.scopes == custom_scope
|
73
|
+
custom_ttl_scope
|
74
|
+
elsif context.grant_type == Doorkeeper::OAuth::CLIENT_CREDENTIALS
|
75
|
+
custom_ttl_grant
|
76
|
+
else
|
77
|
+
nil
|
78
|
+
end
|
79
|
+
}
|
71
80
|
)
|
72
81
|
end
|
73
82
|
|
74
|
-
it '
|
83
|
+
it 'respects grant based rules' do
|
75
84
|
expect(creator).to receive(:call).with(
|
76
85
|
client,
|
77
86
|
scopes,
|
78
|
-
expires_in:
|
87
|
+
expires_in: custom_ttl_grant,
|
79
88
|
use_refresh_token: false
|
80
89
|
)
|
81
90
|
subject.create client, scopes, creator
|
82
91
|
end
|
92
|
+
|
93
|
+
it 'respects scope based rules' do
|
94
|
+
expect(creator).to receive(:call).with(
|
95
|
+
client,
|
96
|
+
custom_scope,
|
97
|
+
expires_in: custom_ttl_scope,
|
98
|
+
use_refresh_token: false
|
99
|
+
)
|
100
|
+
subject.create client, custom_scope, creator
|
101
|
+
end
|
83
102
|
end
|
84
103
|
end
|
85
104
|
end
|
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'active_support/all'
|
3
|
-
require 'doorkeeper/oauth/client_credentials/validation'
|
4
2
|
|
5
3
|
class Doorkeeper::OAuth::ClientCredentialsRequest
|
6
4
|
describe Validation do
|
@@ -45,7 +43,8 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
|
|
45
43
|
allow(application).to receive(:scopes).and_return(application_scopes)
|
46
44
|
allow(server).to receive(:scopes).and_return(server_scopes)
|
47
45
|
allow(request).to receive(:scopes).and_return(
|
48
|
-
Doorkeeper::OAuth::Scopes.from_string
|
46
|
+
Doorkeeper::OAuth::Scopes.from_string('email')
|
47
|
+
)
|
49
48
|
expect(subject).not_to be_valid
|
50
49
|
end
|
51
50
|
end
|
@@ -1,18 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'active_support/all'
|
3
|
-
require 'active_model'
|
4
|
-
require 'doorkeeper/oauth/client_credentials_request'
|
5
2
|
|
6
3
|
module Doorkeeper::OAuth
|
7
4
|
describe ClientCredentialsRequest do
|
8
5
|
let(:server) do
|
9
6
|
double(
|
10
7
|
default_scopes: nil,
|
11
|
-
|
8
|
+
access_token_expires_in: 2.hours,
|
9
|
+
custom_access_token_expires_in: ->(_context) { nil }
|
12
10
|
)
|
13
11
|
end
|
14
12
|
|
15
|
-
let(:application) {
|
13
|
+
let(:application) { FactoryBot.create(:application, scopes: '') }
|
16
14
|
let(:client) { double :client, application: application }
|
17
15
|
let(:token_creator) { double :issuer, create: true, token: double }
|
18
16
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module Doorkeeper::OAuth
|
4
4
|
describe CodeRequest do
|
@@ -10,7 +10,9 @@ module Doorkeeper::OAuth
|
|
10
10
|
scopes: nil,
|
11
11
|
state: nil,
|
12
12
|
error: nil,
|
13
|
-
authorizable?: true
|
13
|
+
authorizable?: true,
|
14
|
+
code_challenge: nil,
|
15
|
+
code_challenge_method: nil,
|
14
16
|
)
|
15
17
|
end
|
16
18
|
|