doorkeeper 4.4.2 → 5.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +2 -0
- data/Appraisals +2 -2
- data/Gemfile +1 -1
- data/NEWS.md +36 -12
- data/README.md +85 -3
- data/Rakefile +6 -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 +15 -1
- data/app/controllers/doorkeeper/tokens_controller.rb +12 -15
- 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 +9 -1
- data/doorkeeper.gemspec +0 -2
- data/gemfiles/rails_5_2.gemfile +1 -1
- data/lib/doorkeeper/config.rb +60 -23
- 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 +56 -0
- data/lib/doorkeeper/models/access_token_mixin.rb +38 -21
- 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 +23 -6
- data/lib/doorkeeper/oauth/authorization_code_request.rb +27 -2
- data/lib/doorkeeper/oauth/base_request.rb +18 -8
- data/lib/doorkeeper/oauth/client/credentials.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +6 -1
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +4 -2
- 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 +13 -16
- 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 +13 -1
- 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.rb +28 -28
- data/lib/doorkeeper/version.rb +5 -25
- data/lib/doorkeeper.rb +4 -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 +60 -9
- 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 +252 -17
- 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 +19 -73
- 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 +6 -0
- 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 +59 -14
- 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 +16 -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 +1 -1
- data/spec/models/doorkeeper/access_token_spec.rb +50 -16
- data/spec/models/doorkeeper/application_spec.rb +1 -47
- data/spec/requests/applications/applications_request_spec.rb +89 -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 +198 -2
- 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/doorkeeper_rspec.rb +19 -0
- data/spec/support/helpers/authorization_request_helper.rb +4 -4
- data/spec/support/helpers/request_spec_helper.rb +2 -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 +33 -31
- 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/support/dependencies/{factory_girl.rb → factory_bot.rb} +0 -0
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 }
|
|
@@ -122,7 +122,7 @@ describe Doorkeeper, 'configuration' do
|
|
|
122
122
|
it 'has all scopes' do
|
|
123
123
|
Doorkeeper.configure do
|
|
124
124
|
orm DOORKEEPER_ORM
|
|
125
|
-
default_scopes
|
|
125
|
+
default_scopes :normal
|
|
126
126
|
optional_scopes :admin
|
|
127
127
|
end
|
|
128
128
|
|
|
@@ -132,7 +132,7 @@ describe Doorkeeper, 'configuration' do
|
|
|
132
132
|
|
|
133
133
|
describe 'use_refresh_token' do
|
|
134
134
|
it 'is false by default' do
|
|
135
|
-
expect(subject.refresh_token_enabled?).to
|
|
135
|
+
expect(subject.refresh_token_enabled?).to eq(false)
|
|
136
136
|
end
|
|
137
137
|
|
|
138
138
|
it 'can change the value' do
|
|
@@ -141,7 +141,7 @@ describe Doorkeeper, 'configuration' do
|
|
|
141
141
|
use_refresh_token
|
|
142
142
|
end
|
|
143
143
|
|
|
144
|
-
expect(subject.refresh_token_enabled?).to
|
|
144
|
+
expect(subject.refresh_token_enabled?).to eq(true)
|
|
145
145
|
end
|
|
146
146
|
|
|
147
147
|
it "does not includes 'refresh_token' in authorization_response_types" do
|
|
@@ -162,6 +162,21 @@ describe Doorkeeper, 'configuration' do
|
|
|
162
162
|
end
|
|
163
163
|
end
|
|
164
164
|
|
|
165
|
+
describe 'enforce_configured_scopes' do
|
|
166
|
+
it 'is false by default' do
|
|
167
|
+
expect(subject.enforce_configured_scopes?).to eq(false)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
it 'can change the value' do
|
|
171
|
+
Doorkeeper.configure do
|
|
172
|
+
orm DOORKEEPER_ORM
|
|
173
|
+
enforce_configured_scopes
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
expect(subject.enforce_configured_scopes?).to eq(true)
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
165
180
|
describe 'client_credentials' do
|
|
166
181
|
it 'has defaults order' do
|
|
167
182
|
expect(subject.client_credentials_methods).to eq([:from_basic, :from_params])
|
|
@@ -179,7 +194,7 @@ describe Doorkeeper, 'configuration' do
|
|
|
179
194
|
|
|
180
195
|
describe 'force_ssl_in_redirect_uri' do
|
|
181
196
|
it 'is true by default in non-development environments' do
|
|
182
|
-
expect(subject.force_ssl_in_redirect_uri).to
|
|
197
|
+
expect(subject.force_ssl_in_redirect_uri).to eq(true)
|
|
183
198
|
end
|
|
184
199
|
|
|
185
200
|
it 'can change the value' do
|
|
@@ -188,7 +203,7 @@ describe Doorkeeper, 'configuration' do
|
|
|
188
203
|
force_ssl_in_redirect_uri(false)
|
|
189
204
|
end
|
|
190
205
|
|
|
191
|
-
expect(subject.force_ssl_in_redirect_uri).to
|
|
206
|
+
expect(subject.force_ssl_in_redirect_uri).to eq(false)
|
|
192
207
|
end
|
|
193
208
|
|
|
194
209
|
it 'can be a callable object' do
|
|
@@ -199,7 +214,7 @@ describe Doorkeeper, 'configuration' do
|
|
|
199
214
|
end
|
|
200
215
|
|
|
201
216
|
expect(subject.force_ssl_in_redirect_uri).to eq(block)
|
|
202
|
-
expect(subject.force_ssl_in_redirect_uri.call).to
|
|
217
|
+
expect(subject.force_ssl_in_redirect_uri.call).to eq(false)
|
|
203
218
|
end
|
|
204
219
|
end
|
|
205
220
|
|
|
@@ -220,7 +235,7 @@ describe Doorkeeper, 'configuration' do
|
|
|
220
235
|
|
|
221
236
|
describe 'forbid_redirect_uri' do
|
|
222
237
|
it 'is false by default' do
|
|
223
|
-
expect(subject.forbid_redirect_uri.call(URI.parse('https://localhost'))).to
|
|
238
|
+
expect(subject.forbid_redirect_uri.call(URI.parse('https://localhost'))).to eq(false)
|
|
224
239
|
end
|
|
225
240
|
|
|
226
241
|
it 'can be a callable object' do
|
|
@@ -231,13 +246,13 @@ describe Doorkeeper, 'configuration' do
|
|
|
231
246
|
end
|
|
232
247
|
|
|
233
248
|
expect(subject.forbid_redirect_uri).to eq(block)
|
|
234
|
-
expect(subject.forbid_redirect_uri.call).to
|
|
249
|
+
expect(subject.forbid_redirect_uri.call).to eq(true)
|
|
235
250
|
end
|
|
236
251
|
end
|
|
237
252
|
|
|
238
253
|
describe 'enable_application_owner' do
|
|
239
254
|
it 'is disabled by default' do
|
|
240
|
-
expect(Doorkeeper.configuration.enable_application_owner?).not_to
|
|
255
|
+
expect(Doorkeeper.configuration.enable_application_owner?).not_to eq(true)
|
|
241
256
|
end
|
|
242
257
|
|
|
243
258
|
context 'when enabled without confirmation' do
|
|
@@ -253,7 +268,7 @@ describe Doorkeeper, 'configuration' do
|
|
|
253
268
|
end
|
|
254
269
|
|
|
255
270
|
it 'Doorkeeper.configuration.confirm_application_owner? returns false' do
|
|
256
|
-
expect(Doorkeeper.configuration.confirm_application_owner?).not_to
|
|
271
|
+
expect(Doorkeeper.configuration.confirm_application_owner?).not_to eq(true)
|
|
257
272
|
end
|
|
258
273
|
end
|
|
259
274
|
|
|
@@ -270,7 +285,7 @@ describe Doorkeeper, 'configuration' do
|
|
|
270
285
|
end
|
|
271
286
|
|
|
272
287
|
it 'Doorkeeper.configuration.confirm_application_owner? returns true' do
|
|
273
|
-
expect(Doorkeeper.configuration.confirm_application_owner?).to
|
|
288
|
+
expect(Doorkeeper.configuration.confirm_application_owner?).to eq(true)
|
|
274
289
|
end
|
|
275
290
|
end
|
|
276
291
|
end
|
|
@@ -299,10 +314,10 @@ describe Doorkeeper, 'configuration' do
|
|
|
299
314
|
it "can change the value" do
|
|
300
315
|
Doorkeeper.configure do
|
|
301
316
|
orm DOORKEEPER_ORM
|
|
302
|
-
grant_flows [
|
|
317
|
+
grant_flows %w[authorization_code implicit]
|
|
303
318
|
end
|
|
304
319
|
|
|
305
|
-
expect(subject.grant_flows).to eq [
|
|
320
|
+
expect(subject.grant_flows).to eq %w[authorization_code implicit]
|
|
306
321
|
end
|
|
307
322
|
|
|
308
323
|
context "when including 'authorization_code'" do
|
|
@@ -434,4 +449,34 @@ describe Doorkeeper, 'configuration' do
|
|
|
434
449
|
end
|
|
435
450
|
end
|
|
436
451
|
end
|
|
452
|
+
|
|
453
|
+
describe "api_only" do
|
|
454
|
+
it "is false by default" do
|
|
455
|
+
expect(subject.api_only).to eq(false)
|
|
456
|
+
end
|
|
457
|
+
|
|
458
|
+
it "can change the value" do
|
|
459
|
+
Doorkeeper.configure do
|
|
460
|
+
orm DOORKEEPER_ORM
|
|
461
|
+
api_only
|
|
462
|
+
end
|
|
463
|
+
|
|
464
|
+
expect(subject.api_only).to eq(true)
|
|
465
|
+
end
|
|
466
|
+
end
|
|
467
|
+
|
|
468
|
+
describe 'strict_content_type' do
|
|
469
|
+
it 'is false by default' do
|
|
470
|
+
expect(subject.enforce_content_type).to eq(false)
|
|
471
|
+
end
|
|
472
|
+
|
|
473
|
+
it "can change the value" do
|
|
474
|
+
Doorkeeper.configure do
|
|
475
|
+
orm DOORKEEPER_ORM
|
|
476
|
+
enforce_content_type
|
|
477
|
+
end
|
|
478
|
+
|
|
479
|
+
expect(subject.enforce_content_type).to eq(true)
|
|
480
|
+
end
|
|
481
|
+
end
|
|
437
482
|
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,20 @@ 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
|
|
108
122
|
end
|
|
109
123
|
|
|
110
124
|
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
|
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
-
require 'active_model'
|
|
3
|
-
require 'doorkeeper'
|
|
4
|
-
require 'doorkeeper/oauth/forbidden_token_response'
|
|
5
2
|
|
|
6
3
|
module Doorkeeper::OAuth
|
|
7
4
|
describe ForbiddenTokenResponse do
|
|
8
5
|
describe '#name' do
|
|
9
|
-
it
|
|
6
|
+
it { expect(subject.name).to eq(:invalid_scope) }
|
|
10
7
|
end
|
|
11
8
|
|
|
12
9
|
describe '#status' do
|
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
-
require 'uri'
|
|
3
|
-
require 'doorkeeper/oauth/helpers/uri_checker'
|
|
4
2
|
|
|
5
3
|
module Doorkeeper::OAuth::Helpers
|
|
6
4
|
describe URIChecker do
|
|
7
5
|
describe '.valid?' do
|
|
8
|
-
it 'is valid for native uris' do
|
|
9
|
-
uri = 'urn:ietf:wg:oauth:2.0:oob'
|
|
10
|
-
expect(URIChecker.valid?(uri)).to be_truthy
|
|
11
|
-
end
|
|
12
|
-
|
|
13
6
|
it 'is valid for valid uris' do
|
|
14
7
|
uri = 'http://app.co'
|
|
15
8
|
expect(URIChecker.valid?(uri)).to be_truthy
|
|
@@ -49,6 +42,11 @@ module Doorkeeper::OAuth::Helpers
|
|
|
49
42
|
uri = ' '
|
|
50
43
|
expect(URIChecker.valid?(uri)).to be_falsey
|
|
51
44
|
end
|
|
45
|
+
|
|
46
|
+
it 'is valid for native uris' do
|
|
47
|
+
uri = 'urn:ietf:wg:oauth:2.0:oob'
|
|
48
|
+
expect(URIChecker.valid?(uri)).to be_truthy
|
|
49
|
+
end
|
|
52
50
|
end
|
|
53
51
|
|
|
54
52
|
describe '.matches?' do
|