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.

Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.gitlab-ci.yml +16 -0
  4. data/.travis.yml +2 -0
  5. data/Appraisals +2 -2
  6. data/Gemfile +1 -1
  7. data/NEWS.md +61 -8
  8. data/README.md +92 -9
  9. data/Rakefile +6 -0
  10. data/UPGRADE.md +2 -0
  11. data/app/assets/stylesheets/doorkeeper/admin/application.css +2 -2
  12. data/app/controllers/doorkeeper/application_controller.rb +4 -3
  13. data/app/controllers/doorkeeper/application_metal_controller.rb +4 -0
  14. data/app/controllers/doorkeeper/applications_controller.rb +42 -22
  15. data/app/controllers/doorkeeper/authorizations_controller.rb +55 -12
  16. data/app/controllers/doorkeeper/authorized_applications_controller.rb +19 -2
  17. data/app/controllers/doorkeeper/tokens_controller.rb +2 -6
  18. data/app/helpers/doorkeeper/dashboard_helper.rb +7 -7
  19. data/app/validators/redirect_uri_validator.rb +3 -2
  20. data/app/views/doorkeeper/applications/_delete_form.html.erb +3 -1
  21. data/app/views/doorkeeper/applications/_form.html.erb +25 -24
  22. data/app/views/doorkeeper/applications/edit.html.erb +1 -1
  23. data/app/views/doorkeeper/applications/index.html.erb +17 -7
  24. data/app/views/doorkeeper/applications/new.html.erb +1 -1
  25. data/app/views/doorkeeper/applications/show.html.erb +6 -6
  26. data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
  27. data/app/views/doorkeeper/authorizations/new.html.erb +4 -0
  28. data/app/views/layouts/doorkeeper/admin.html.erb +15 -15
  29. data/config/locales/en.yml +10 -1
  30. data/doorkeeper.gemspec +18 -20
  31. data/gemfiles/rails_5_2.gemfile +1 -1
  32. data/gemfiles/rails_master.gemfile +4 -1
  33. data/lib/doorkeeper/config.rb +75 -39
  34. data/lib/doorkeeper/engine.rb +4 -0
  35. data/lib/doorkeeper/errors.rb +2 -5
  36. data/lib/doorkeeper/grape/helpers.rb +1 -1
  37. data/lib/doorkeeper/helpers/controller.rb +7 -2
  38. data/lib/doorkeeper/models/access_grant_mixin.rb +71 -0
  39. data/lib/doorkeeper/models/access_token_mixin.rb +39 -22
  40. data/lib/doorkeeper/models/concerns/scopes.rb +1 -1
  41. data/lib/doorkeeper/oauth/authorization/code.rb +31 -8
  42. data/lib/doorkeeper/oauth/authorization/context.rb +15 -0
  43. data/lib/doorkeeper/oauth/authorization/token.rb +36 -14
  44. data/lib/doorkeeper/oauth/authorization_code_request.rb +27 -2
  45. data/lib/doorkeeper/oauth/base_request.rb +20 -9
  46. data/lib/doorkeeper/oauth/client/credentials.rb +1 -1
  47. data/lib/doorkeeper/oauth/client.rb +0 -2
  48. data/lib/doorkeeper/oauth/client_credentials/creator.rb +2 -1
  49. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +6 -3
  50. data/lib/doorkeeper/oauth/client_credentials/validation.rb +4 -6
  51. data/lib/doorkeeper/oauth/client_credentials_request.rb +0 -4
  52. data/lib/doorkeeper/oauth/error_response.rb +11 -3
  53. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +0 -8
  54. data/lib/doorkeeper/oauth/password_access_token_request.rb +7 -4
  55. data/lib/doorkeeper/oauth/pre_authorization.rb +41 -11
  56. data/lib/doorkeeper/oauth/refresh_token_request.rb +6 -1
  57. data/lib/doorkeeper/oauth/scopes.rb +1 -1
  58. data/lib/doorkeeper/oauth/token.rb +5 -2
  59. data/lib/doorkeeper/oauth/token_introspection.rb +2 -2
  60. data/lib/doorkeeper/oauth/token_response.rb +4 -2
  61. data/lib/doorkeeper/oauth.rb +13 -0
  62. data/lib/doorkeeper/orm/active_record/application.rb +22 -14
  63. data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +26 -0
  64. data/lib/doorkeeper/orm/active_record.rb +2 -0
  65. data/lib/doorkeeper/rails/helpers.rb +2 -4
  66. data/lib/doorkeeper/rails/routes.rb +14 -6
  67. data/lib/doorkeeper/rake/db.rake +40 -0
  68. data/lib/doorkeeper/rake/setup.rake +6 -0
  69. data/lib/doorkeeper/rake.rb +14 -0
  70. data/lib/doorkeeper/request/authorization_code.rb +0 -2
  71. data/lib/doorkeeper/request/client_credentials.rb +0 -2
  72. data/lib/doorkeeper/request/code.rb +0 -2
  73. data/lib/doorkeeper/request/password.rb +0 -2
  74. data/lib/doorkeeper/request/refresh_token.rb +0 -2
  75. data/lib/doorkeeper/request/token.rb +0 -2
  76. data/lib/doorkeeper/request.rb +28 -35
  77. data/lib/doorkeeper/version.rb +5 -25
  78. data/lib/doorkeeper.rb +19 -17
  79. data/lib/generators/doorkeeper/application_owner_generator.rb +23 -18
  80. data/lib/generators/doorkeeper/confidential_applications_generator.rb +32 -0
  81. data/lib/generators/doorkeeper/install_generator.rb +17 -9
  82. data/lib/generators/doorkeeper/migration_generator.rb +23 -18
  83. data/lib/generators/doorkeeper/pkce_generator.rb +32 -0
  84. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -24
  85. data/lib/generators/doorkeeper/templates/add_confidential_to_applications.rb.erb +13 -0
  86. data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +6 -0
  87. data/lib/generators/doorkeeper/templates/initializer.rb +76 -11
  88. data/lib/generators/doorkeeper/views_generator.rb +3 -1
  89. data/spec/controllers/application_metal_controller_spec.rb +50 -0
  90. data/spec/controllers/applications_controller_spec.rb +126 -13
  91. data/spec/controllers/authorizations_controller_spec.rb +277 -47
  92. data/spec/controllers/protected_resources_controller_spec.rb +16 -16
  93. data/spec/controllers/token_info_controller_spec.rb +4 -12
  94. data/spec/controllers/tokens_controller_spec.rb +13 -15
  95. data/spec/dummy/app/assets/config/manifest.js +2 -0
  96. data/spec/dummy/config/environments/test.rb +4 -5
  97. data/spec/dummy/config/initializers/doorkeeper.rb +10 -5
  98. data/spec/dummy/config/initializers/new_framework_defaults.rb +4 -0
  99. data/spec/dummy/config/routes.rb +3 -42
  100. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +6 -0
  101. data/spec/dummy/db/migrate/{20180210183654_add_confidential_to_application.rb → 20180210183654_add_confidential_to_applications.rb} +1 -1
  102. data/spec/dummy/db/schema.rb +36 -36
  103. data/spec/generators/application_owner_generator_spec.rb +1 -1
  104. data/spec/generators/confidential_applications_generator_spec.rb +45 -0
  105. data/spec/generators/install_generator_spec.rb +1 -1
  106. data/spec/generators/migration_generator_spec.rb +1 -1
  107. data/spec/generators/pkce_generator_spec.rb +43 -0
  108. data/spec/generators/previous_refresh_token_generator_spec.rb +1 -1
  109. data/spec/generators/views_generator_spec.rb +1 -1
  110. data/spec/grape/grape_integration_spec.rb +1 -1
  111. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
  112. data/spec/lib/config_spec.rb +80 -31
  113. data/spec/lib/doorkeeper_spec.rb +1 -126
  114. data/spec/lib/models/expirable_spec.rb +0 -3
  115. data/spec/lib/models/revocable_spec.rb +0 -2
  116. data/spec/lib/models/scopes_spec.rb +0 -4
  117. data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -4
  118. data/spec/lib/oauth/authorization_code_request_spec.rb +9 -2
  119. data/spec/lib/oauth/base_request_spec.rb +40 -2
  120. data/spec/lib/oauth/base_response_spec.rb +1 -1
  121. data/spec/lib/oauth/client/credentials_spec.rb +1 -3
  122. data/spec/lib/oauth/client_credentials/creator_spec.rb +5 -1
  123. data/spec/lib/oauth/client_credentials/issuer_spec.rb +26 -7
  124. data/spec/lib/oauth/client_credentials/validation_spec.rb +2 -3
  125. data/spec/lib/oauth/client_credentials_integration_spec.rb +1 -1
  126. data/spec/lib/oauth/client_credentials_request_spec.rb +3 -5
  127. data/spec/lib/oauth/client_spec.rb +0 -3
  128. data/spec/lib/oauth/code_request_spec.rb +4 -2
  129. data/spec/lib/oauth/error_response_spec.rb +0 -3
  130. data/spec/lib/oauth/error_spec.rb +0 -2
  131. data/spec/lib/oauth/forbidden_token_response_spec.rb +1 -4
  132. data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -3
  133. data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -1
  134. data/spec/lib/oauth/helpers/uri_checker_spec.rb +5 -7
  135. data/spec/lib/oauth/invalid_token_response_spec.rb +1 -4
  136. data/spec/lib/oauth/password_access_token_request_spec.rb +37 -2
  137. data/spec/lib/oauth/pre_authorization_spec.rb +33 -4
  138. data/spec/lib/oauth/refresh_token_request_spec.rb +11 -7
  139. data/spec/lib/oauth/scopes_spec.rb +0 -3
  140. data/spec/lib/oauth/token_request_spec.rb +4 -5
  141. data/spec/lib/oauth/token_response_spec.rb +0 -1
  142. data/spec/lib/oauth/token_spec.rb +37 -14
  143. data/spec/lib/orm/active_record/stale_records_cleaner_spec.rb +79 -0
  144. data/spec/lib/request/strategy_spec.rb +0 -1
  145. data/spec/lib/server_spec.rb +1 -1
  146. data/spec/models/doorkeeper/access_grant_spec.rb +44 -1
  147. data/spec/models/doorkeeper/access_token_spec.rb +66 -22
  148. data/spec/models/doorkeeper/application_spec.rb +14 -47
  149. data/spec/requests/applications/applications_request_spec.rb +134 -1
  150. data/spec/requests/applications/authorized_applications_spec.rb +1 -1
  151. data/spec/requests/endpoints/authorization_spec.rb +1 -1
  152. data/spec/requests/endpoints/token_spec.rb +7 -5
  153. data/spec/requests/flows/authorization_code_errors_spec.rb +1 -1
  154. data/spec/requests/flows/authorization_code_spec.rb +197 -1
  155. data/spec/requests/flows/client_credentials_spec.rb +46 -6
  156. data/spec/requests/flows/implicit_grant_errors_spec.rb +1 -1
  157. data/spec/requests/flows/implicit_grant_spec.rb +38 -11
  158. data/spec/requests/flows/password_spec.rb +56 -2
  159. data/spec/requests/flows/refresh_token_spec.rb +2 -2
  160. data/spec/requests/flows/revoke_token_spec.rb +11 -11
  161. data/spec/requests/flows/skip_authorization_spec.rb +16 -11
  162. data/spec/requests/protected_resources/metal_spec.rb +1 -1
  163. data/spec/requests/protected_resources/private_api_spec.rb +1 -1
  164. data/spec/routing/custom_controller_routes_spec.rb +59 -7
  165. data/spec/routing/default_routes_spec.rb +2 -2
  166. data/spec/routing/scoped_routes_spec.rb +16 -2
  167. data/spec/spec_helper.rb +54 -3
  168. data/spec/spec_helper_integration.rb +2 -74
  169. data/spec/support/dependencies/{factory_girl.rb → factory_bot.rb} +0 -0
  170. data/spec/support/doorkeeper_rspec.rb +19 -0
  171. data/spec/support/helpers/authorization_request_helper.rb +4 -4
  172. data/spec/support/helpers/request_spec_helper.rb +10 -2
  173. data/spec/support/helpers/url_helper.rb +7 -3
  174. data/spec/support/http_method_shim.rb +12 -16
  175. data/spec/validators/redirect_uri_validator_spec.rb +7 -1
  176. data/spec/version/version_spec.rb +3 -3
  177. data/vendor/assets/stylesheets/doorkeeper/bootstrap.min.css +4 -5
  178. metadata +37 -33
  179. data/lib/generators/doorkeeper/add_client_confidentiality_generator.rb +0 -31
  180. data/lib/generators/doorkeeper/templates/add_confidential_to_application_migration.rb.erb +0 -11
  181. data/spec/controllers/application_metal_controller.rb +0 -10
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
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 :normal
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 be_falsey
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 be_truthy
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 'opt_out_native_route_change' do
166
- around(:each) do |example|
167
- Doorkeeper.configure do
168
- orm DOORKEEPER_ORM
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
- Rails.application.reload_routes!
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 be_truthy
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 be_falsey
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 be_falsey
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 be_falsey
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 be_truthy
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 be_truthy
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 be_truthy
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 be_truthy
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 ['authorization_code', 'implicit']
346
+ grant_flows %w[authorization_code implicit]
328
347
  end
329
348
 
330
- expect(subject.grant_flows).to eq ['authorization_code', 'implicit']
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
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
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,6 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'active_support/core_ext/object/blank'
3
- require 'doorkeeper/models/concerns/revocable'
4
2
 
5
3
  describe 'Revocable' do
6
4
  subject do
@@ -1,8 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'active_support/core_ext/module/delegation'
3
- require 'active_support/core_ext/object/blank'
4
- require 'doorkeeper/oauth/scopes'
5
- require 'doorkeeper/models/concerns/scopes'
6
2
 
7
3
  describe 'Doorkeeper::Models::Scopes' do
8
4
  subject do
@@ -1,8 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'active_support/core_ext/string'
3
- require 'uri'
4
- require 'rack/utils'
5
- require 'doorkeeper/oauth/authorization/uri_builder'
6
2
 
7
3
  module Doorkeeper::OAuth::Authorization
8
4
  describe URIBuilder do
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
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: ->(_app) { nil }
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 'spec_helper_integration'
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: ->(_) { nil },
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,4 +1,4 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
 
3
3
  module Doorkeeper::OAuth
4
4
  describe BaseResponse 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) { return 'uid', 'secret' }
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 'spec_helper_integration'
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: ->(_app) { nil }
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(:custom_ttl) { 1233 }
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: ->(_app) { custom_ttl }
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 'creates with correct token parameters' do
83
+ it 'respects grant based rules' do
75
84
  expect(creator).to receive(:call).with(
76
85
  client,
77
86
  scopes,
78
- expires_in: custom_ttl,
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 'email')
46
+ Doorkeeper::OAuth::Scopes.from_string('email')
47
+ )
49
48
  expect(subject).not_to be_valid
50
49
  end
51
50
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
 
3
3
  module Doorkeeper::OAuth
4
4
  describe ClientCredentialsRequest do
@@ -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
- custom_access_token_expires_in: ->(_app) { nil }
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) { double :application, scopes: Scopes.from_string('') }
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,7 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'active_support/core_ext/module/delegation'
3
- require 'active_support/core_ext/string'
4
- require 'doorkeeper/oauth/client'
5
2
 
6
3
  module Doorkeeper::OAuth
7
4
  describe Client do
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
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,7 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'active_model'
3
- require 'doorkeeper/oauth/error'
4
- require 'doorkeeper/oauth/error_response'
5
2
 
6
3
  module Doorkeeper::OAuth
7
4
  describe ErrorResponse do
@@ -1,6 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'active_support/i18n'
3
- require 'doorkeeper/oauth/error'
4
2
 
5
3
  module Doorkeeper::OAuth
6
4
  describe Error do