doorkeeper-mongodb 5.2.1 → 5.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -27
  3. data/lib/doorkeeper/orm/concerns/mongoid/ownership.rb +1 -1
  4. data/lib/doorkeeper/orm/concerns/mongoid/resource_ownerable.rb +1 -1
  5. data/lib/doorkeeper/orm/mongoid4.rb +18 -0
  6. data/lib/doorkeeper/orm/mongoid5.rb +18 -0
  7. data/lib/doorkeeper/orm/mongoid6.rb +18 -0
  8. data/lib/doorkeeper/orm/mongoid7.rb +18 -0
  9. data/lib/doorkeeper-mongodb/mixins/mongoid/access_grant_mixin.rb +7 -6
  10. data/lib/doorkeeper-mongodb/mixins/mongoid/access_token_mixin.rb +8 -5
  11. data/lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb +82 -5
  12. data/lib/doorkeeper-mongodb/mixins/mongoid/base_mixin.rb +0 -8
  13. data/lib/doorkeeper-mongodb/mixins/mongoid/json_serializable.rb +17 -0
  14. data/lib/doorkeeper-mongodb/version.rb +1 -1
  15. data/lib/doorkeeper-mongodb.rb +1 -0
  16. data/spec/controllers/application_metal_controller_spec.rb +4 -4
  17. data/spec/controllers/applications_controller_spec.rb +198 -202
  18. data/spec/controllers/authorizations_controller_spec.rb +32 -31
  19. data/spec/controllers/protected_resources_controller_spec.rb +10 -10
  20. data/spec/controllers/token_info_controller_spec.rb +1 -1
  21. data/spec/controllers/tokens_controller_spec.rb +105 -62
  22. data/spec/doorkeeper/redirect_uri_validator_spec.rb +183 -0
  23. data/spec/{lib → doorkeeper}/server_spec.rb +5 -4
  24. data/spec/{lib → doorkeeper}/stale_records_cleaner_spec.rb +8 -7
  25. data/spec/{version → doorkeeper}/version_spec.rb +3 -3
  26. data/spec/dummy/app/assets/config/manifest.js +0 -0
  27. data/spec/dummy/app/controllers/application_controller.rb +0 -0
  28. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +0 -0
  29. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +0 -0
  30. data/spec/dummy/app/controllers/home_controller.rb +0 -0
  31. data/spec/dummy/app/controllers/metal_controller.rb +0 -0
  32. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +0 -0
  33. data/spec/dummy/app/helpers/application_helper.rb +0 -0
  34. data/spec/dummy/app/models/user.rb +0 -1
  35. data/spec/dummy/app/views/home/index.html.erb +0 -0
  36. data/spec/dummy/app/views/layouts/application.html.erb +0 -0
  37. data/spec/dummy/config/application.rb +0 -0
  38. data/spec/dummy/config/boot.rb +0 -0
  39. data/spec/dummy/config/database.yml +0 -0
  40. data/spec/dummy/config/environment.rb +0 -0
  41. data/spec/dummy/config/environments/development.rb +0 -0
  42. data/spec/dummy/config/environments/production.rb +0 -0
  43. data/spec/dummy/config/environments/test.rb +0 -0
  44. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -0
  45. data/spec/dummy/config/initializers/doorkeeper.rb +0 -0
  46. data/spec/dummy/config/initializers/secret_token.rb +0 -0
  47. data/spec/dummy/config/initializers/session_store.rb +0 -0
  48. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -0
  49. data/spec/dummy/config/locales/doorkeeper.en.yml +0 -0
  50. data/spec/dummy/config/mongo.yml +2 -2
  51. data/spec/dummy/config/routes.rb +0 -0
  52. data/spec/dummy/config.ru +0 -0
  53. data/spec/dummy/db/migrate/20111122132257_create_users.rb +0 -0
  54. data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +0 -0
  55. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +0 -0
  56. data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +0 -0
  57. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +0 -0
  58. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +0 -0
  59. data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +0 -0
  60. data/spec/dummy/db/schema.rb +0 -0
  61. data/spec/dummy/public/404.html +0 -0
  62. data/spec/dummy/public/422.html +0 -0
  63. data/spec/dummy/public/500.html +0 -0
  64. data/spec/dummy/public/favicon.ico +0 -0
  65. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/-o/-ofn45zIfO5vx4VD6m6NXesLf6da5usA-Sbw2SVju3o.cache +0 -0
  66. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/0_/0_ouGcG_o_1zmVmBe-tdQYk594LBwVa1bumjrKtdfEw.cache +0 -0
  67. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/2X/2XMMcHbyTSRqh1GkV0xzyIETNtt-zgN6iniziShaKmQ.cache +0 -0
  68. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/4Q/4QQw-pMQ98JIj3xdcFhGBQdysdGPY9rWffRqWMmyjew.cache +0 -0
  69. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/7H/7HjRsym0tTpXFCVhWt6kteMs_-CozKVbr9s5syHm8es.cache +0 -0
  70. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8B/8BxJyv22HPFHu1se_l2J8qW1N9NzZ16UOWOy1YMSgs4.cache +0 -0
  71. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8D/8DJG7JfPvShfLLyeSom6NZ_TcQc6QH27tJ7prEWZPfI.cache +0 -0
  72. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/9x/9xjtGv-yKjj62x9uFwBZg8pTSh9ERPAgANwNo9uwIaA.cache +0 -0
  73. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Bt/BtXO7f0PZ8DNt3TMLYM-zY7LkbWa_KgyB0v1V98M1CQ.cache +0 -0
  74. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/E0/E02f1Q2tutWumMulGCFNfqQNjvEP_hMAK_5E83eWepI.cache +0 -0
  75. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/EZ/EZGpd6pUEJZxO6uT2yIS4Fpn5KX7VDgC9VB3AaemF5Q.cache +0 -0
  76. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/FJ/FJlQpfMtpRbrM5P8A7d2FAelFKwo6GrVs2xks8z5GKU.cache +0 -0
  77. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/L8/L8mOWakJlWKr6MU85rj0V7yGFfNyIR6vE6YXtqArPGw.cache +0 -0
  78. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Lk/LklIq5hrBAPESXVUpFMwQ9L-1qTj90sPVi6U19_Xi-Q.cache +0 -0
  79. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/MB/MBWRxa9S470ee8suxVKp0jYgv6K6FQOqKGV0kPGQNMs.cache +0 -0
  80. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ma/MaK3K1AoZZ4xM5fOOifhROd73hfZJpP4yGbkGdoYtEk.cache +0 -0
  81. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/PA/PAH_jI20wRw12tngeJ-V619c30avNLDu5U9Z-9Pc5SQ.cache +0 -0
  82. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ph/Ph7RtH_NvG2I8XpTa8mA8SBQXZDzBPVIh4CH6g7OXJ0.cache +0 -0
  83. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{eS/eSL1QMz46gKLM0GR6S9fL6uyARPxOImcappZ9_ZtSyg.cache → Pm/PmheG0PGFqDws1qgFOxOyIL-gpMof3Ar9eSRKVLYuik.cache} +0 -0
  84. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Pn/PnXU_mkG2fLZFm9BwiZ03BZdBTjKuInP-cRXjHS7yJo.cache +0 -0
  85. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Qs/QsVgO6vM5Yn9oeYTYlrqtyVnK6sdVDWDa083N7zpfHw.cache +0 -0
  86. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/So/So59ksdx2dw-_A3-zFZ6Palr7fROjm7_0JDZb04temw.cache +0 -0
  87. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Wt/WtXL_iDofLeTH_v0Yf3PM421r9b1V0g-VBvMPeu9KA0.cache +0 -0
  88. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/b6/b6QRH6ZdCc0e6bUWu4qni_kZmptaMgWciO8Jl9q6_p8.cache +0 -0
  89. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/dX/dX6FDdUIy8yBCOoaoXcjf71rX9N_bpiXGJ4Urt32NTk.cache +0 -0
  90. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/jC/jCTZ1jAldKBn4OTANBBmCKzxLrDgok1ur4meoTqlDNg.cache +0 -0
  91. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/qT/qTQIQsmS0Wbbg2JxNn9rxdI5qVOTg5SfyQdaTvr9vLo.cache +0 -0
  92. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/yN/yNOFGOsnHmxXNMkuEAWuL1u3jlmdvrdeoTx6DDJ1in8.cache +0 -0
  93. data/spec/factories.rb +0 -0
  94. data/spec/grape/grape_integration_spec.rb +1 -1
  95. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
  96. data/spec/lib/config_spec.rb +23 -12
  97. data/spec/lib/doorkeeper_spec.rb +4 -4
  98. data/spec/lib/models/expirable_spec.rb +9 -9
  99. data/spec/lib/models/reusable_spec.rb +2 -2
  100. data/spec/lib/models/revocable_spec.rb +4 -7
  101. data/spec/lib/models/scopes_spec.rb +7 -7
  102. data/spec/lib/models/secret_storable_spec.rb +9 -8
  103. data/spec/lib/oauth/authorization/uri_builder_spec.rb +23 -27
  104. data/spec/lib/oauth/authorization_code_request_spec.rb +6 -6
  105. data/spec/lib/oauth/base_request_spec.rb +11 -27
  106. data/spec/lib/oauth/base_response_spec.rb +2 -2
  107. data/spec/lib/oauth/client/credentials_spec.rb +25 -25
  108. data/spec/lib/oauth/client_credentials/creator_spec.rb +89 -91
  109. data/spec/lib/oauth/client_credentials/issuer_spec.rb +84 -86
  110. data/spec/lib/oauth/client_credentials/validation_spec.rb +72 -39
  111. data/spec/lib/oauth/client_credentials_integration_spec.rb +5 -5
  112. data/spec/lib/oauth/client_credentials_request_spec.rb +7 -10
  113. data/spec/lib/oauth/client_spec.rb +8 -8
  114. data/spec/lib/oauth/code_request_spec.rb +5 -5
  115. data/spec/lib/oauth/code_response_spec.rb +4 -4
  116. data/spec/lib/oauth/error_response_spec.rb +6 -5
  117. data/spec/lib/oauth/error_spec.rb +1 -1
  118. data/spec/lib/oauth/forbidden_token_response_spec.rb +2 -2
  119. data/spec/lib/oauth/helpers/scope_checker_spec.rb +37 -37
  120. data/spec/lib/oauth/helpers/unique_token_spec.rb +2 -2
  121. data/spec/lib/oauth/helpers/uri_checker_spec.rb +54 -54
  122. data/spec/lib/oauth/invalid_request_response_spec.rb +6 -6
  123. data/spec/lib/oauth/invalid_token_response_spec.rb +4 -4
  124. data/spec/lib/oauth/password_access_token_request_spec.rb +10 -9
  125. data/spec/lib/oauth/pre_authorization_spec.rb +20 -8
  126. data/spec/lib/oauth/refresh_token_request_spec.rb +10 -10
  127. data/spec/lib/oauth/scopes_spec.rb +14 -14
  128. data/spec/lib/oauth/token_request_spec.rb +9 -9
  129. data/spec/lib/oauth/token_response_spec.rb +5 -5
  130. data/spec/lib/oauth/token_spec.rb +5 -5
  131. data/spec/lib/option_spec.rb +1 -1
  132. data/spec/lib/request/strategy_spec.rb +34 -37
  133. data/spec/lib/secret_storing/base_spec.rb +3 -2
  134. data/spec/lib/secret_storing/bcrypt_spec.rb +2 -1
  135. data/spec/lib/secret_storing/plain_spec.rb +2 -1
  136. data/spec/lib/secret_storing/sha256_hash_spec.rb +2 -1
  137. data/spec/models/doorkeeper/access_grant_spec.rb +7 -9
  138. data/spec/models/doorkeeper/access_token_spec.rb +20 -26
  139. data/spec/models/doorkeeper/application_spec.rb +83 -26
  140. data/spec/requests/applications/applications_request_spec.rb +91 -93
  141. data/spec/requests/applications/authorized_applications_spec.rb +0 -0
  142. data/spec/requests/endpoints/authorization_spec.rb +1 -1
  143. data/spec/requests/endpoints/token_spec.rb +22 -16
  144. data/spec/requests/flows/authorization_code_errors_spec.rb +12 -8
  145. data/spec/requests/flows/authorization_code_spec.rb +108 -79
  146. data/spec/requests/flows/client_credentials_spec.rb +57 -45
  147. data/spec/requests/flows/implicit_grant_errors_spec.rb +0 -0
  148. data/spec/requests/flows/implicit_grant_spec.rb +4 -4
  149. data/spec/requests/flows/password_spec.rb +253 -213
  150. data/spec/requests/flows/refresh_token_spec.rb +53 -39
  151. data/spec/requests/flows/revoke_token_spec.rb +24 -24
  152. data/spec/requests/flows/skip_authorization_spec.rb +1 -1
  153. data/spec/requests/protected_resources/metal_spec.rb +2 -2
  154. data/spec/requests/protected_resources/private_api_spec.rb +0 -0
  155. data/spec/routing/custom_controller_routes_spec.rb +1 -1
  156. data/spec/routing/default_routes_spec.rb +1 -1
  157. data/spec/routing/scoped_routes_spec.rb +1 -1
  158. data/spec/spec_helper.rb +0 -0
  159. data/spec/spec_helper_integration.rb +0 -0
  160. data/spec/support/dependencies/factory_bot.rb +0 -0
  161. data/spec/support/doorkeeper_rspec.rb +0 -0
  162. data/spec/support/helpers/access_token_request_helper.rb +0 -0
  163. data/spec/support/helpers/authorization_request_helper.rb +0 -0
  164. data/spec/support/helpers/config_helper.rb +0 -0
  165. data/spec/support/helpers/model_helper.rb +0 -0
  166. data/spec/support/helpers/request_spec_helper.rb +1 -13
  167. data/spec/support/helpers/url_helper.rb +2 -2
  168. data/spec/support/orm/active_record.rb +0 -0
  169. data/spec/support/orm/mongoid4.rb +1 -1
  170. data/spec/support/orm/mongoid5.rb +1 -1
  171. data/spec/support/orm/mongoid6.rb +1 -1
  172. data/spec/support/orm/mongoid7.rb +1 -1
  173. data/spec/support/shared/controllers_shared_context.rb +5 -38
  174. data/spec/support/shared/hashing_shared_context.rb +4 -0
  175. data/spec/support/shared/models_shared_examples.rb +6 -6
  176. metadata +154 -167
  177. data/spec/dummy/log/test.log +0 -6108
@@ -3,7 +3,7 @@
3
3
  require "spec_helper"
4
4
  require "bcrypt"
5
5
 
6
- describe Doorkeeper::Application do
6
+ RSpec.describe Doorkeeper::Application do
7
7
  let(:require_owner) { Doorkeeper.config.instance_variable_set("@confirm_application_owner", true) }
8
8
  let(:unset_require_owner) { Doorkeeper.config.instance_variable_set("@confirm_application_owner", false) }
9
9
  let(:new_application) { FactoryBot.build(:application) }
@@ -83,7 +83,7 @@ describe Doorkeeper::Application do
83
83
  expect(new_application).not_to be_valid
84
84
  end
85
85
 
86
- context "application_owner is enabled" do
86
+ context "when application_owner is enabled" do
87
87
  before do
88
88
  Doorkeeper.configure do
89
89
  orm DOORKEEPER_ORM
@@ -91,8 +91,8 @@ describe Doorkeeper::Application do
91
91
  end
92
92
  end
93
93
 
94
- context "application owner is not required" do
95
- before(:each) do
94
+ context "when application owner is not required" do
95
+ before do
96
96
  unset_require_owner
97
97
  end
98
98
 
@@ -101,8 +101,8 @@ describe Doorkeeper::Application do
101
101
  end
102
102
  end
103
103
 
104
- context "application owner is required" do
105
- before(:each) do
104
+ context "when application owner is required" do
105
+ before do
106
106
  require_owner
107
107
  @owner = FactoryBot.build_stubbed(:doorkeeper_testing_user)
108
108
  end
@@ -118,10 +118,11 @@ describe Doorkeeper::Application do
118
118
  end
119
119
  end
120
120
 
121
- context "redirect URI" do
121
+ describe "redirect URI" do
122
122
  context "when grant flows allow blank redirect URI" do
123
123
  before do
124
124
  Doorkeeper.configure do
125
+ orm DOORKEEPER_ORM
125
126
  grant_flows %w[password client_credentials]
126
127
  end
127
128
  end
@@ -136,6 +137,7 @@ describe Doorkeeper::Application do
136
137
  context "when grant flows require redirect URI" do
137
138
  before do
138
139
  Doorkeeper.configure do
140
+ orm DOORKEEPER_ORM
139
141
  grant_flows %w[password client_credentials authorization_code]
140
142
  end
141
143
  end
@@ -150,6 +152,7 @@ describe Doorkeeper::Application do
150
152
  context "when blank URI option disabled" do
151
153
  before do
152
154
  Doorkeeper.configure do
155
+ orm DOORKEEPER_ORM
153
156
  grant_flows %w[password client_credentials]
154
157
  allow_blank_redirect_uri false
155
158
  end
@@ -179,6 +182,7 @@ describe Doorkeeper::Application do
179
182
  # will always be true
180
183
  before do
181
184
  Doorkeeper.configure do
185
+ orm DOORKEEPER_ORM
182
186
  hash_application_secrets using: "Doorkeeper::SecretStoring::BCrypt"
183
187
  end
184
188
  end
@@ -218,13 +222,13 @@ describe Doorkeeper::Application do
218
222
  end
219
223
 
220
224
  describe "destroy related models on cascade" do
221
- before(:each) do
225
+ before do
222
226
  new_application.save
223
227
  end
224
228
 
225
229
  let(:resource_owner) { FactoryBot.create(:resource_owner) }
226
230
 
227
- it "should destroy its access grants" do
231
+ it "destroys its access grants" do
228
232
  FactoryBot.create(
229
233
  :access_grant,
230
234
  application: new_application,
@@ -235,7 +239,7 @@ describe Doorkeeper::Application do
235
239
  expect { new_application.destroy }.to change { Doorkeeper::AccessGrant.count }.by(-1)
236
240
  end
237
241
 
238
- it "should destroy its access tokens" do
242
+ it "destroys its access tokens" do
239
243
  FactoryBot.create(:access_token, application: new_application)
240
244
  FactoryBot.create(:access_token, application: new_application, revoked_at: Time.now.utc)
241
245
  expect do
@@ -264,13 +268,14 @@ describe Doorkeeper::Application do
264
268
 
265
269
  describe "#redirect_uri=" do
266
270
  context "when array of valid redirect_uris" do
267
- it "should join by newline" do
271
+ it "joins by newline" do
268
272
  new_application.redirect_uri = ["http://localhost/callback1", "http://localhost/callback2"]
269
273
  expect(new_application.redirect_uri).to eq("http://localhost/callback1\nhttp://localhost/callback2")
270
274
  end
271
275
  end
276
+
272
277
  context "when string of valid redirect_uris" do
273
- it "should store as-is" do
278
+ it "stores as-is" do
274
279
  new_application.redirect_uri = "http://localhost/callback1\nhttp://localhost/callback2"
275
280
  expect(new_application.redirect_uri).to eq("http://localhost/callback1\nhttp://localhost/callback2")
276
281
  end
@@ -280,7 +285,7 @@ describe Doorkeeper::Application do
280
285
  describe "#renew_secret" do
281
286
  let(:app) { FactoryBot.create :application }
282
287
 
283
- it "should generate a new secret" do
288
+ it "generates a new secret" do
284
289
  old_secret = app.secret
285
290
  app.renew_secret
286
291
  expect(old_secret).not_to eq(app.secret)
@@ -372,8 +377,9 @@ describe Doorkeeper::Application do
372
377
  authenticated = described_class.by_uid_and_secret(app.uid, app.secret)
373
378
  expect(authenticated).to eq(app)
374
379
  end
380
+
375
381
  context "when secret is wrong" do
376
- it "should not find the application" do
382
+ it "does not find the application" do
377
383
  app = FactoryBot.create :application
378
384
  authenticated = described_class.by_uid_and_secret(app.uid, "bad")
379
385
  expect(authenticated).to eq(nil)
@@ -383,14 +389,15 @@ describe Doorkeeper::Application do
383
389
 
384
390
  context "when application is public/non-confidential" do
385
391
  context "when secret is blank" do
386
- it "should find the application" do
392
+ it "finds the application" do
387
393
  app = FactoryBot.create :application, confidential: false
388
394
  authenticated = described_class.by_uid_and_secret(app.uid, nil)
389
395
  expect(authenticated).to eq(app)
390
396
  end
391
397
  end
398
+
392
399
  context "when secret is wrong" do
393
- it "should not find the application" do
400
+ it "does not find the application" do
394
401
  app = FactoryBot.create :application, confidential: false
395
402
  authenticated = described_class.by_uid_and_secret(app.uid, "bad")
396
403
  expect(authenticated).to eq(nil)
@@ -404,11 +411,13 @@ describe Doorkeeper::Application do
404
411
 
405
412
  context "when application is private/confidential" do
406
413
  let(:confidential) { true }
414
+
407
415
  it { expect(subject).to eq(true) }
408
416
  end
409
417
 
410
418
  context "when application is public/non-confidential" do
411
419
  let(:confidential) { false }
420
+
412
421
  it { expect(subject).to eq(false) }
413
422
  end
414
423
  end
@@ -421,16 +430,7 @@ describe Doorkeeper::Application do
421
430
  .to receive(:application_secret_strategy).and_return(Doorkeeper::SecretStoring::Plain)
422
431
  end
423
432
 
424
- it "includes plaintext secret" do
425
- expect(app.as_json).to include("secret" => "123123123")
426
- end
427
-
428
- it "respects custom options" do
429
- expect(app.as_json(except: :secret)).not_to include("secret")
430
- expect(app.as_json(only: :id)).to match("id" => app.id)
431
- end
432
-
433
- # AR specific
433
+ # AR specific feature
434
434
  if DOORKEEPER_ORM == :active_record
435
435
  it "correctly works with #to_json" do
436
436
  ActiveRecord::Base.include_root_in_json = true
@@ -438,5 +438,62 @@ describe Doorkeeper::Application do
438
438
  ActiveRecord::Base.include_root_in_json = false
439
439
  end
440
440
  end
441
+
442
+ context "when called without authorized resource owner" do
443
+ it "includes minimal set of attributes" do
444
+ expect(app.as_json).to match(
445
+ "id" => app.id,
446
+ "name" => app.name,
447
+ "created_at" => anything,
448
+ )
449
+ end
450
+
451
+ it "includes application UID if it's public" do
452
+ app = FactoryBot.create :application, secret: "123123123", confidential: false
453
+
454
+ expect(app.as_json).to match(
455
+ "id" => app.id,
456
+ "name" => app.name,
457
+ "created_at" => anything,
458
+ "uid" => app.uid,
459
+ )
460
+ end
461
+
462
+ it "respects custom options" do
463
+ expect(app.as_json(except: :id)).not_to include("id")
464
+ expect(app.as_json(only: %i[name created_at secret]))
465
+ .to match(
466
+ "name" => app.name,
467
+ "created_at" => anything,
468
+ )
469
+ end
470
+ end
471
+
472
+ context "when called with authorized resource owner" do
473
+ let(:owner) { FactoryBot.create(:doorkeeper_testing_user) }
474
+ let(:other_owner) { FactoryBot.create(:doorkeeper_testing_user) }
475
+ let(:app) { FactoryBot.create(:application, secret: "123123123", owner: owner) }
476
+
477
+ before do
478
+ Doorkeeper.configure do
479
+ orm DOORKEEPER_ORM
480
+ enable_application_owner confirmation: false
481
+ end
482
+ end
483
+
484
+ it "includes all the attributes" do
485
+ expect(app.as_json(current_resource_owner: owner))
486
+ .to include(
487
+ "secret" => "123123123",
488
+ "redirect_uri" => app.redirect_uri,
489
+ "uid" => app.uid,
490
+ )
491
+ end
492
+
493
+ it "doesn't include unsafe attributes if current owner isn't the same as owner" do
494
+ expect(app.as_json(current_resource_owner: other_owner))
495
+ .not_to include("redirect_uri")
496
+ end
497
+ end
441
498
  end
442
499
  end
@@ -2,127 +2,125 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- feature "Adding applications" do
6
- context "in application form" do
7
- background do
8
- i_am_logged_in
9
- visit "/oauth/applications/new"
10
- end
5
+ feature "Adding applications in application form" do
6
+ background do
7
+ i_am_logged_in
8
+ visit "/oauth/applications/new"
9
+ end
11
10
 
12
- scenario "adding a valid app" do
13
- fill_in "doorkeeper_application[name]", with: "My Application"
14
- fill_in "doorkeeper_application[redirect_uri]",
15
- with: "https://example.com"
11
+ scenario "adding a valid app" do
12
+ fill_in "doorkeeper_application[name]", with: "My Application"
13
+ fill_in "doorkeeper_application[redirect_uri]",
14
+ with: "https://example.com"
16
15
 
17
- click_button "Submit"
18
- i_should_see "Application created"
19
- i_should_see "My Application"
20
- end
16
+ click_button "Submit"
17
+ i_should_see "Application created"
18
+ i_should_see "My Application"
19
+ end
21
20
 
22
- scenario "adding invalid app" do
23
- click_button "Submit"
24
- i_should_see "Whoops! Check your form for possible errors"
25
- end
21
+ scenario "adding invalid app" do
22
+ click_button "Submit"
23
+ i_should_see "Whoops! Check your form for possible errors"
24
+ end
26
25
 
27
- scenario "adding app ignoring bad scope" do
28
- config_is_set("enforce_configured_scopes", false)
26
+ scenario "adding app ignoring bad scope" do
27
+ config_is_set("enforce_configured_scopes", false)
29
28
 
30
- fill_in "doorkeeper_application[name]", with: "My Application"
31
- fill_in "doorkeeper_application[redirect_uri]",
32
- with: "https://example.com"
33
- fill_in "doorkeeper_application[scopes]", with: "blahblah"
29
+ fill_in "doorkeeper_application[name]", with: "My Application"
30
+ fill_in "doorkeeper_application[redirect_uri]",
31
+ with: "https://example.com"
32
+ fill_in "doorkeeper_application[scopes]", with: "blahblah"
34
33
 
35
- click_button "Submit"
36
- i_should_see "Application created"
37
- i_should_see "My Application"
38
- end
34
+ click_button "Submit"
35
+ i_should_see "Application created"
36
+ i_should_see "My Application"
37
+ end
39
38
 
40
- scenario "adding app validating bad scope" do
41
- config_is_set("enforce_configured_scopes", true)
39
+ scenario "adding app validating bad scope" do
40
+ config_is_set("enforce_configured_scopes", true)
42
41
 
43
- fill_in "doorkeeper_application[name]", with: "My Application"
44
- fill_in "doorkeeper_application[redirect_uri]",
45
- with: "https://example.com"
46
- fill_in "doorkeeper_application[scopes]", with: "blahblah"
42
+ fill_in "doorkeeper_application[name]", with: "My Application"
43
+ fill_in "doorkeeper_application[redirect_uri]",
44
+ with: "https://example.com"
45
+ fill_in "doorkeeper_application[scopes]", with: "blahblah"
47
46
 
48
- click_button "Submit"
49
- i_should_see "Whoops! Check your form for possible errors"
50
- end
47
+ click_button "Submit"
48
+ i_should_see "Whoops! Check your form for possible errors"
49
+ end
51
50
 
52
- scenario "adding app validating scope, blank scope is accepted" do
53
- config_is_set("enforce_configured_scopes", true)
51
+ scenario "adding app validating scope, blank scope is accepted" do
52
+ config_is_set("enforce_configured_scopes", true)
54
53
 
55
- fill_in "doorkeeper_application[name]", with: "My Application"
56
- fill_in "doorkeeper_application[redirect_uri]",
57
- with: "https://example.com"
58
- fill_in "doorkeeper_application[scopes]", with: ""
54
+ fill_in "doorkeeper_application[name]", with: "My Application"
55
+ fill_in "doorkeeper_application[redirect_uri]",
56
+ with: "https://example.com"
57
+ fill_in "doorkeeper_application[scopes]", with: ""
59
58
 
60
- click_button "Submit"
61
- i_should_see "Application created"
62
- i_should_see "My Application"
63
- end
59
+ click_button "Submit"
60
+ i_should_see "Application created"
61
+ i_should_see "My Application"
62
+ end
64
63
 
65
- scenario "adding app validating scope, multiple scopes configured" do
66
- config_is_set("enforce_configured_scopes", true)
67
- scopes = Doorkeeper::OAuth::Scopes.from_array(%w[read write admin])
68
- config_is_set("optional_scopes", scopes)
64
+ scenario "adding app validating scope, multiple scopes configured" do
65
+ config_is_set("enforce_configured_scopes", true)
66
+ scopes = Doorkeeper::OAuth::Scopes.from_array(%w[read write admin])
67
+ config_is_set("optional_scopes", scopes)
69
68
 
70
- fill_in "doorkeeper_application[name]", with: "My Application"
71
- fill_in "doorkeeper_application[redirect_uri]",
72
- with: "https://example.com"
73
- fill_in "doorkeeper_application[scopes]", with: "read write"
69
+ fill_in "doorkeeper_application[name]", with: "My Application"
70
+ fill_in "doorkeeper_application[redirect_uri]",
71
+ with: "https://example.com"
72
+ fill_in "doorkeeper_application[scopes]", with: "read write"
74
73
 
75
- click_button "Submit"
76
- i_should_see "Application created"
77
- i_should_see "My Application"
78
- end
74
+ click_button "Submit"
75
+ i_should_see "Application created"
76
+ i_should_see "My Application"
77
+ end
78
+
79
+ scenario "adding app validating scope, bad scope with multiple scopes configured" do
80
+ config_is_set("enforce_configured_scopes", true)
81
+ scopes = Doorkeeper::OAuth::Scopes.from_array(%w[read write admin])
82
+ config_is_set("optional_scopes", scopes)
83
+
84
+ fill_in "doorkeeper_application[name]", with: "My Application"
85
+ fill_in "doorkeeper_application[redirect_uri]",
86
+ with: "https://example.com"
87
+ fill_in "doorkeeper_application[scopes]", with: "read blah"
88
+
89
+ click_button "Submit"
90
+ i_should_see "Whoops! Check your form for possible errors"
91
+ i_should_see Regexp.new(
92
+ I18n.t("activerecord.errors.models.doorkeeper/application.attributes.scopes.not_match_configured"),
93
+ true,
94
+ )
95
+ end
79
96
 
80
- scenario "adding app validating scope, bad scope with multiple scopes configured" do
81
- config_is_set("enforce_configured_scopes", true)
82
- scopes = Doorkeeper::OAuth::Scopes.from_array(%w[read write admin])
83
- config_is_set("optional_scopes", scopes)
97
+ context "with blank redirect URI" do
98
+ scenario "adding app with blank redirect URI when configured flows requires redirect uri" do
99
+ config_is_set("grant_flows", %w[authorization_code implicit client_credentials])
84
100
 
85
101
  fill_in "doorkeeper_application[name]", with: "My Application"
86
102
  fill_in "doorkeeper_application[redirect_uri]",
87
- with: "https://example.com"
88
- fill_in "doorkeeper_application[scopes]", with: "read blah"
103
+ with: ""
89
104
 
90
105
  click_button "Submit"
91
106
  i_should_see "Whoops! Check your form for possible errors"
92
- i_should_see Regexp.new(
93
- I18n.t("activerecord.errors.models.doorkeeper/application.attributes.scopes.not_match_configured"),
94
- true,
95
- )
96
107
  end
97
108
 
98
- context "redirect URI" do
99
- scenario "adding app with blank redirect URI when configured flows requires redirect uri" do
100
- config_is_set("grant_flows", %w[authorization_code implicit client_credentials])
101
-
102
- fill_in "doorkeeper_application[name]", with: "My Application"
103
- fill_in "doorkeeper_application[redirect_uri]",
104
- with: ""
109
+ scenario "adding app with blank redirect URI when configured flows without redirect uri" do
110
+ config_is_set("grant_flows", %w[client_credentials password])
105
111
 
106
- click_button "Submit"
107
- i_should_see "Whoops! Check your form for possible errors"
108
- end
109
-
110
- scenario "adding app with blank redirect URI when configured flows without redirect uri" do
111
- config_is_set("grant_flows", %w[client_credentials password])
112
-
113
- # Visit it once again to consider grant flows
114
- visit "/oauth/applications/new"
112
+ # Visit it once again to consider grant flows
113
+ visit "/oauth/applications/new"
115
114
 
116
- i_should_see I18n.t("doorkeeper.applications.help.blank_redirect_uri")
115
+ i_should_see I18n.t("doorkeeper.applications.help.blank_redirect_uri")
117
116
 
118
- fill_in "doorkeeper_application[name]", with: "My Application"
119
- fill_in "doorkeeper_application[redirect_uri]",
120
- with: ""
117
+ fill_in "doorkeeper_application[name]", with: "My Application"
118
+ fill_in "doorkeeper_application[redirect_uri]",
119
+ with: ""
121
120
 
122
- click_button "Submit"
123
- i_should_see "Application created"
124
- i_should_see "My Application"
125
- end
121
+ click_button "Submit"
122
+ i_should_see "Application created"
123
+ i_should_see "My Application"
126
124
  end
127
125
  end
128
126
  end
@@ -70,7 +70,7 @@ feature "Authorization endpoint" do
70
70
  end
71
71
  end
72
72
 
73
- context "forgery protection enabled" do
73
+ context "when forgery protection enabled" do
74
74
  background do
75
75
  create_resource_owner
76
76
  sign_in
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe "Token endpoint" do
5
+ RSpec.describe "Token endpoint" do
6
6
  before do
7
7
  client_exists
8
8
  create_resource_owner
@@ -34,46 +34,52 @@ describe "Token endpoint" do
34
34
  },
35
35
  headers: { "HTTP_AUTHORIZATION" => basic_auth_header_for_client(@client) }
36
36
 
37
- should_have_json "access_token", Doorkeeper::AccessToken.first.token
37
+ expect(json_response).to include("access_token" => Doorkeeper::AccessToken.first.token)
38
38
  end
39
39
 
40
40
  it "returns null for expires_in when a permanent token is set" do
41
41
  config_is_set(:access_token_expires_in, nil)
42
+
42
43
  post token_endpoint_url(code: @authorization.token, client: @client)
43
- should_have_json "access_token", Doorkeeper::AccessToken.first.token
44
- should_not_have_json "expires_in"
44
+
45
+ expect(json_response).to include("access_token" => Doorkeeper::AccessToken.first.token)
46
+ expect(json_response).not_to include("expires_in")
45
47
  end
46
48
 
47
49
  it "returns unsupported_grant_type for invalid grant_type param" do
48
50
  post token_endpoint_url(code: @authorization.token, client: @client, grant_type: "nothing")
49
51
 
50
- should_not_have_json "access_token"
51
- should_have_json "error", "unsupported_grant_type"
52
- should_have_json "error_description", translated_error_message("unsupported_grant_type")
52
+ expect(json_response).to match(
53
+ "error" => "unsupported_grant_type",
54
+ "error_description" => translated_error_message("unsupported_grant_type"),
55
+ )
53
56
  end
54
57
 
55
58
  it "returns unsupported_grant_type for disabled grant flows" do
56
59
  config_is_set(:grant_flows, ["implicit"])
57
60
  post token_endpoint_url(code: @authorization.token, client: @client, grant_type: "authorization_code")
58
61
 
59
- should_not_have_json "access_token"
60
- should_have_json "error", "unsupported_grant_type"
61
- should_have_json "error_description", translated_error_message("unsupported_grant_type")
62
+ expect(json_response).to match(
63
+ "error" => "unsupported_grant_type",
64
+ "error_description" => translated_error_message("unsupported_grant_type"),
65
+ )
62
66
  end
63
67
 
64
68
  it "returns unsupported_grant_type when refresh_token is not in use" do
65
69
  post token_endpoint_url(code: @authorization.token, client: @client, grant_type: "refresh_token")
66
70
 
67
- should_not_have_json "access_token"
68
- should_have_json "error", "unsupported_grant_type"
69
- should_have_json "error_description", translated_error_message("unsupported_grant_type")
71
+ expect(json_response).to match(
72
+ "error" => "unsupported_grant_type",
73
+ "error_description" => translated_error_message("unsupported_grant_type"),
74
+ )
70
75
  end
71
76
 
72
77
  it "returns invalid_request if grant_type is missing" do
73
78
  post token_endpoint_url(code: @authorization.token, client: @client, grant_type: "")
74
79
 
75
- should_not_have_json "access_token"
76
- should_have_json "error", "invalid_request"
77
- should_have_json "error_description", translated_invalid_request_error_message(:missing_param, :grant_type)
80
+ expect(json_response).to match(
81
+ "error" => "invalid_request",
82
+ "error_description" => translated_invalid_request_error_message(:missing_param, :grant_type),
83
+ )
78
84
  end
79
85
  end
@@ -4,6 +4,7 @@ require "spec_helper"
4
4
 
5
5
  feature "Authorization Code Flow Errors" do
6
6
  let(:client_params) { {} }
7
+
7
8
  background do
8
9
  default_scopes_exist :default
9
10
  config_is_set(:authenticate_resource_owner) { User.first || redirect_to("/sign_in") }
@@ -19,6 +20,7 @@ feature "Authorization Code Flow Errors" do
19
20
  context "with a client trying to xss resource owner" do
20
21
  let(:client_name) { "<div id='xss'>XSS</div>" }
21
22
  let(:client_params) { { name: client_name } }
23
+
22
24
  scenario "resource owner visit authorization endpoint" do
23
25
  visit authorization_endpoint_url(client: @client)
24
26
  expect(page).not_to have_css("#xss")
@@ -47,7 +49,7 @@ feature "Authorization Code Flow Errors" do
47
49
  end
48
50
  end
49
51
 
50
- describe "Authorization Code Flow Errors", "after authorization" do
52
+ RSpec.describe "Authorization Code Flow Errors after authorization" do
51
53
  before do
52
54
  client_exists
53
55
  create_resource_owner
@@ -63,11 +65,12 @@ describe "Authorization Code Flow Errors", "after authorization" do
63
65
  # Second attempt with same token
64
66
  expect do
65
67
  post token_endpoint_url(code: @authorization.token, client: @client)
66
- end.to_not(change { Doorkeeper::AccessToken.count })
68
+ end.not_to(change { Doorkeeper::AccessToken.count })
67
69
 
68
- should_not_have_json "access_token"
69
- should_have_json "error", "invalid_grant"
70
- should_have_json "error_description", translated_error_message("invalid_grant")
70
+ expect(json_response).to match(
71
+ "error" => "invalid_grant",
72
+ "error_description" => translated_error_message("invalid_grant"),
73
+ )
71
74
  end
72
75
 
73
76
  it "returns :invalid_grant error for invalid grant code" do
@@ -75,8 +78,9 @@ describe "Authorization Code Flow Errors", "after authorization" do
75
78
 
76
79
  access_token_should_not_exist
77
80
 
78
- should_not_have_json "access_token"
79
- should_have_json "error", "invalid_grant"
80
- should_have_json "error_description", translated_error_message("invalid_grant")
81
+ expect(json_response).to match(
82
+ "error" => "invalid_grant",
83
+ "error_description" => translated_error_message("invalid_grant"),
84
+ )
81
85
  end
82
86
  end