doorkeeper-mongodb 5.2.3 → 5.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/Rakefile +18 -4
  4. data/lib/doorkeeper/orm/mongoid8/access_grant.rb +26 -0
  5. data/lib/doorkeeper/orm/mongoid8/access_token.rb +38 -0
  6. data/lib/doorkeeper/orm/mongoid8/application.rb +43 -0
  7. data/lib/doorkeeper/orm/mongoid8/stale_records_cleaner.rb +11 -0
  8. data/lib/doorkeeper/orm/mongoid8.rb +50 -0
  9. data/lib/doorkeeper-mongodb/mixins/mongoid/access_token_mixin.rb +45 -5
  10. data/lib/doorkeeper-mongodb/version.rb +2 -2
  11. data/lib/doorkeeper-mongodb.rb +1 -0
  12. data/spec/dummy/app/assets/config/manifest.js +0 -0
  13. data/spec/dummy/app/controllers/application_controller.rb +0 -0
  14. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +0 -0
  15. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +0 -0
  16. data/spec/dummy/app/controllers/home_controller.rb +0 -0
  17. data/spec/dummy/app/controllers/metal_controller.rb +0 -0
  18. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +0 -0
  19. data/spec/dummy/app/helpers/application_helper.rb +0 -0
  20. data/spec/dummy/app/views/home/index.html.erb +0 -0
  21. data/spec/dummy/app/views/layouts/application.html.erb +0 -0
  22. data/spec/dummy/config/application.rb +0 -0
  23. data/spec/dummy/config/boot.rb +0 -0
  24. data/spec/dummy/config/database.yml +0 -0
  25. data/spec/dummy/config/environment.rb +0 -0
  26. data/spec/dummy/config/environments/development.rb +0 -0
  27. data/spec/dummy/config/environments/production.rb +0 -0
  28. data/spec/dummy/config/environments/test.rb +0 -0
  29. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -0
  30. data/spec/dummy/config/initializers/doorkeeper.rb +7 -2
  31. data/spec/dummy/config/initializers/secret_token.rb +0 -0
  32. data/spec/dummy/config/initializers/session_store.rb +0 -0
  33. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -0
  34. data/spec/dummy/config/locales/doorkeeper.en.yml +0 -0
  35. data/spec/dummy/config/mongoid8.yml +19 -0
  36. data/spec/dummy/config/routes.rb +0 -0
  37. data/spec/dummy/config.ru +1 -1
  38. data/spec/dummy/db/migrate/20111122132257_create_users.rb +0 -0
  39. data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +0 -0
  40. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +0 -0
  41. data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +0 -0
  42. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +0 -0
  43. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +0 -0
  44. data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +0 -0
  45. data/spec/dummy/db/migrate/20230205064514_add_custom_attributes.rb +8 -0
  46. data/spec/dummy/db/schema.rb +3 -1
  47. data/spec/dummy/log/test.log +39440 -0
  48. data/spec/dummy/public/404.html +0 -0
  49. data/spec/dummy/public/422.html +0 -0
  50. data/spec/dummy/public/500.html +0 -0
  51. data/spec/dummy/public/favicon.ico +0 -0
  52. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/2L/2LdlR-88TqZc8vSU7Z58xiNpCGRZj0CIlOxSN4Vx2i4.cache +1 -0
  53. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{Pn/PnXU_mkG2fLZFm9BwiZ03BZdBTjKuInP-cRXjHS7yJo.cache → 2r/2r0L9eNOmETsg4Tm1IgBdw3J4ahcko41NpILRXu19_A.cache} +0 -0
  54. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/5y/5ywocFQgpSY36nyF_xDKPExhDRo-eqeiqfDvQee1K9k.cache +2 -0
  55. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{Qs/QsVgO6vM5Yn9oeYTYlrqtyVnK6sdVDWDa083N7zpfHw.cache → 8r/8rW0CpDDUJZ7xvg86t6jZ6WmyvaVZ0uTPEPRjghFIKo.cache} +0 -0
  56. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{PA/PAH_jI20wRw12tngeJ-V619c30avNLDu5U9Z-9Pc5SQ.cache → Cs/CsfBL8Dls9-jhjFsNYt4DZxu5LWChDMB-xXKjsEFSsU.cache} +0 -0
  57. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{8D/8DJG7JfPvShfLLyeSom6NZ_TcQc6QH27tJ7prEWZPfI.cache → Cv/Cv9WXE_0OqtPUZBXfTWaE8uKx9oFIzqO18ZkwVaBLSg.cache} +0 -0
  58. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Mf/MfB2-0nbsmC548XBSLftafi6BZ9nAquBA-6eu7mAmdE.cache +2 -0
  59. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/N2/N2cUP-Um_nQ5ZTCQr_H0bKIjOSIyV7Ry5sT6-DB9e4A.cache +1 -0
  60. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{FJ/FJlQpfMtpRbrM5P8A7d2FAelFKwo6GrVs2xks8z5GKU.cache → Ot/OtNAnT3d-csAKBtJ8UBLOSwUDyfmOdCWpS08RaSCGsQ.cache} +0 -0
  61. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/P3/P33RwiTMGEu2wZySBEUmf5U7hnfBhdL49wzdUWXYNRs.cache +1 -0
  62. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/RZ/RZAL9gIt4aD731Ikf7UZZNPSZXzhPqtDskLB7nQcWH4.cache +1 -0
  63. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/SQ/SQVJeYO2bM0qgQiOaeVBjYo3SWQZmvixa3tXUjsmuUs.cache +0 -0
  64. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{Ma/MaK3K1AoZZ4xM5fOOifhROd73hfZJpP4yGbkGdoYtEk.cache → V2/V2JApVhUSYhvWnNVIbpe58U4xheVkpi0gCStqjDN6-A.cache} +0 -0
  65. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{Lk/LklIq5hrBAPESXVUpFMwQ9L-1qTj90sPVi6U19_Xi-Q.cache → VA/VADOUaZFukufOb44ts4KoyQZumPcVJET0bi9RvC7c-o.cache} +1 -1
  66. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Vz/VzdPLfWn16XbpHNJdkDMamAf3QutM29cvvPkDNyy5nE.cache +1 -0
  67. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/W9/W9QfraySVwoRt-SgGOIS0e-iP8R1qP_URwXZw1l6M5E.cache +0 -0
  68. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Wy/Wyiw07ngOzgV6RPis_Lo2hhSRkwo2YSqKTEDAF0crhA.cache +0 -0
  69. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Z6/Z6rAtdVt3OXS26vLVCtdO3vmMlttI3ajdpbC2FHk7iQ.cache +0 -0
  70. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/b6/b6QRH6ZdCc0e6bUWu4qni_kZmptaMgWciO8Jl9q6_p8.cache +0 -0
  71. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{Pm/PmheG0PGFqDws1qgFOxOyIL-gpMof3Ar9eSRKVLYuik.cache → fP/fPihom3hnc1rQQxpviTvZPRJB_IghWYWP3dDcsGrcLk.cache} +0 -0
  72. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/gD/gDU38plXvosMgFK47_PBI9xGVsmsE2tShWEZzxiek3k.cache +1 -0
  73. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/gR/gRqL5_jaFW7eA3d2frJmOzw_vFLuvfhwMhotAlsO8J4.cache +2 -0
  74. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/jC/jCTZ1jAldKBn4OTANBBmCKzxLrDgok1ur4meoTqlDNg.cache +0 -0
  75. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{yN/yNOFGOsnHmxXNMkuEAWuL1u3jlmdvrdeoTx6DDJ1in8.cache → jc/jcB8w1gBT7JP10DW4OOvvYpW1ZFeMyedngmMy3QbRLQ.cache} +0 -0
  76. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/jg/jgxXkkkXf1NPOPrpNdEJzhDt-2xHGzd_-mLkIHWrOr4.cache +2 -0
  77. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/nx/nxzZnvk5YyBhTUloQSZZ5zRuaqlsLiHy_AbOzQ3d788.cache +0 -0
  78. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/wr/wrlf8nUW2yftpcIA97qImyECR8f8o3OiOdHLdfkmw8c.cache +1 -0
  79. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{qT/qTQIQsmS0Wbbg2JxNn9rxdI5qVOTg5SfyQdaTvr9vLo.cache → xd/xdD4KJ55W3jy5PIrwT0UnDp1toKpUfgrjJBgB4WaPIc.cache} +0 -0
  80. data/spec/support/doorkeeper_rspec.rb +0 -0
  81. data/spec/support/orm/mongoid.rb +18 -2
  82. data/spec/support/orm/mongoid8.rb +6 -0
  83. data/spec/support/render_with_matcher.rb +26 -0
  84. metadata +123 -242
  85. data/spec/controllers/application_metal_controller_spec.rb +0 -64
  86. data/spec/controllers/applications_controller_spec.rb +0 -270
  87. data/spec/controllers/authorizations_controller_spec.rb +0 -744
  88. data/spec/controllers/protected_resources_controller_spec.rb +0 -361
  89. data/spec/controllers/token_info_controller_spec.rb +0 -50
  90. data/spec/controllers/tokens_controller_spec.rb +0 -542
  91. data/spec/doorkeeper/redirect_uri_validator_spec.rb +0 -183
  92. data/spec/doorkeeper/server_spec.rb +0 -50
  93. data/spec/doorkeeper/stale_records_cleaner_spec.rb +0 -103
  94. data/spec/doorkeeper/version_spec.rb +0 -17
  95. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/-o/-ofn45zIfO5vx4VD6m6NXesLf6da5usA-Sbw2SVju3o.cache +0 -2
  96. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/0_/0_ouGcG_o_1zmVmBe-tdQYk594LBwVa1bumjrKtdfEw.cache +0 -0
  97. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/2X/2XMMcHbyTSRqh1GkV0xzyIETNtt-zgN6iniziShaKmQ.cache +0 -2
  98. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/4Q/4QQw-pMQ98JIj3xdcFhGBQdysdGPY9rWffRqWMmyjew.cache +0 -1
  99. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/7H/7HjRsym0tTpXFCVhWt6kteMs_-CozKVbr9s5syHm8es.cache +0 -1
  100. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8B/8BxJyv22HPFHu1se_l2J8qW1N9NzZ16UOWOy1YMSgs4.cache +0 -1
  101. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/9x/9xjtGv-yKjj62x9uFwBZg8pTSh9ERPAgANwNo9uwIaA.cache +0 -1
  102. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Bt/BtXO7f0PZ8DNt3TMLYM-zY7LkbWa_KgyB0v1V98M1CQ.cache +0 -1
  103. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/E0/E02f1Q2tutWumMulGCFNfqQNjvEP_hMAK_5E83eWepI.cache +0 -0
  104. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/EZ/EZGpd6pUEJZxO6uT2yIS4Fpn5KX7VDgC9VB3AaemF5Q.cache +0 -2
  105. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/L8/L8mOWakJlWKr6MU85rj0V7yGFfNyIR6vE6YXtqArPGw.cache +0 -1
  106. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/MB/MBWRxa9S470ee8suxVKp0jYgv6K6FQOqKGV0kPGQNMs.cache +0 -1
  107. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ph/Ph7RtH_NvG2I8XpTa8mA8SBQXZDzBPVIh4CH6g7OXJ0.cache +0 -2
  108. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/So/So59ksdx2dw-_A3-zFZ6Palr7fROjm7_0JDZb04temw.cache +0 -0
  109. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Wt/WtXL_iDofLeTH_v0Yf3PM421r9b1V0g-VBvMPeu9KA0.cache +0 -0
  110. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/dX/dX6FDdUIy8yBCOoaoXcjf71rX9N_bpiXGJ4Urt32NTk.cache +0 -0
  111. data/spec/factories.rb +0 -30
  112. data/spec/grape/grape_integration_spec.rb +0 -137
  113. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +0 -26
  114. data/spec/lib/config_spec.rb +0 -824
  115. data/spec/lib/doorkeeper_spec.rb +0 -27
  116. data/spec/lib/models/expirable_spec.rb +0 -61
  117. data/spec/lib/models/reusable_spec.rb +0 -40
  118. data/spec/lib/models/revocable_spec.rb +0 -55
  119. data/spec/lib/models/scopes_spec.rb +0 -61
  120. data/spec/lib/models/secret_storable_spec.rb +0 -136
  121. data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -35
  122. data/spec/lib/oauth/authorization_code_request_spec.rb +0 -180
  123. data/spec/lib/oauth/base_request_spec.rb +0 -210
  124. data/spec/lib/oauth/base_response_spec.rb +0 -45
  125. data/spec/lib/oauth/client/credentials_spec.rb +0 -90
  126. data/spec/lib/oauth/client_credentials/creator_spec.rb +0 -135
  127. data/spec/lib/oauth/client_credentials/issuer_spec.rb +0 -110
  128. data/spec/lib/oauth/client_credentials/validation_spec.rb +0 -92
  129. data/spec/lib/oauth/client_credentials_integration_spec.rb +0 -27
  130. data/spec/lib/oauth/client_credentials_request_spec.rb +0 -105
  131. data/spec/lib/oauth/client_spec.rb +0 -38
  132. data/spec/lib/oauth/code_request_spec.rb +0 -46
  133. data/spec/lib/oauth/code_response_spec.rb +0 -36
  134. data/spec/lib/oauth/error_response_spec.rb +0 -65
  135. data/spec/lib/oauth/error_spec.rb +0 -21
  136. data/spec/lib/oauth/forbidden_token_response_spec.rb +0 -20
  137. data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -110
  138. data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -21
  139. data/spec/lib/oauth/helpers/uri_checker_spec.rb +0 -262
  140. data/spec/lib/oauth/invalid_request_response_spec.rb +0 -73
  141. data/spec/lib/oauth/invalid_token_response_spec.rb +0 -53
  142. data/spec/lib/oauth/password_access_token_request_spec.rb +0 -202
  143. data/spec/lib/oauth/pre_authorization_spec.rb +0 -230
  144. data/spec/lib/oauth/refresh_token_request_spec.rb +0 -166
  145. data/spec/lib/oauth/scopes_spec.rb +0 -146
  146. data/spec/lib/oauth/token_request_spec.rb +0 -164
  147. data/spec/lib/oauth/token_response_spec.rb +0 -84
  148. data/spec/lib/oauth/token_spec.rb +0 -156
  149. data/spec/lib/option_spec.rb +0 -51
  150. data/spec/lib/request/strategy_spec.rb +0 -51
  151. data/spec/lib/secret_storing/base_spec.rb +0 -61
  152. data/spec/lib/secret_storing/bcrypt_spec.rb +0 -50
  153. data/spec/lib/secret_storing/plain_spec.rb +0 -45
  154. data/spec/lib/secret_storing/sha256_hash_spec.rb +0 -49
  155. data/spec/models/doorkeeper/access_grant_spec.rb +0 -173
  156. data/spec/models/doorkeeper/access_token_spec.rb +0 -644
  157. data/spec/models/doorkeeper/application_spec.rb +0 -499
  158. data/spec/requests/applications/applications_request_spec.rb +0 -257
  159. data/spec/requests/applications/authorized_applications_spec.rb +0 -32
  160. data/spec/requests/endpoints/authorization_spec.rb +0 -91
  161. data/spec/requests/endpoints/token_spec.rb +0 -85
  162. data/spec/requests/flows/authorization_code_errors_spec.rb +0 -86
  163. data/spec/requests/flows/authorization_code_spec.rb +0 -559
  164. data/spec/requests/flows/client_credentials_spec.rb +0 -219
  165. data/spec/requests/flows/implicit_grant_errors_spec.rb +0 -46
  166. data/spec/requests/flows/implicit_grant_spec.rb +0 -91
  167. data/spec/requests/flows/password_spec.rb +0 -356
  168. data/spec/requests/flows/refresh_token_spec.rb +0 -255
  169. data/spec/requests/flows/revoke_token_spec.rb +0 -196
  170. data/spec/requests/flows/skip_authorization_spec.rb +0 -66
  171. data/spec/requests/protected_resources/metal_spec.rb +0 -16
  172. data/spec/requests/protected_resources/private_api_spec.rb +0 -83
  173. data/spec/routing/custom_controller_routes_spec.rb +0 -133
  174. data/spec/routing/default_routes_spec.rb +0 -41
  175. data/spec/routing/scoped_routes_spec.rb +0 -47
  176. data/spec/spec_helper.rb +0 -54
  177. data/spec/spec_helper_integration.rb +0 -4
  178. data/spec/support/dependencies/factory_bot.rb +0 -4
  179. data/spec/support/helpers/access_token_request_helper.rb +0 -14
  180. data/spec/support/helpers/authorization_request_helper.rb +0 -43
  181. data/spec/support/helpers/config_helper.rb +0 -11
  182. data/spec/support/helpers/model_helper.rb +0 -78
  183. data/spec/support/helpers/request_spec_helper.rb +0 -98
  184. data/spec/support/helpers/url_helper.rb +0 -62
  185. data/spec/support/orm/active_record.rb +0 -5
  186. data/spec/support/shared/controllers_shared_context.rb +0 -100
  187. data/spec/support/shared/hashing_shared_context.rb +0 -40
  188. data/spec/support/shared/models_shared_examples.rb +0 -56
@@ -1,230 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.describe Doorkeeper::OAuth::PreAuthorization do
6
- subject do
7
- described_class.new(server, attributes)
8
- end
9
-
10
- let(:server) do
11
- server = Doorkeeper.configuration
12
- allow(server).to receive(:default_scopes).and_return(Doorkeeper::OAuth::Scopes.from_string("default"))
13
- allow(server).to receive(:optional_scopes).and_return(Doorkeeper::OAuth::Scopes.from_string("public profile"))
14
- server
15
- end
16
-
17
- let(:application) { FactoryBot.create(:application, redirect_uri: "https://app.com/callback") }
18
- let(:client) { Doorkeeper::OAuth::Client.find(application.uid) }
19
-
20
- let :attributes do
21
- {
22
- client_id: client.uid,
23
- response_type: "code",
24
- redirect_uri: "https://app.com/callback",
25
- state: "save-this",
26
- current_resource_owner: Object.new,
27
- }
28
- end
29
-
30
- it "is authorizable when request is valid" do
31
- expect(subject).to be_authorizable
32
- end
33
-
34
- it "accepts code as response type" do
35
- attributes[:response_type] = "code"
36
- expect(subject).to be_authorizable
37
- end
38
-
39
- it "accepts token as response type" do
40
- allow(server).to receive(:grant_flows).and_return(["implicit"])
41
- attributes[:response_type] = "token"
42
- expect(subject).to be_authorizable
43
- end
44
-
45
- context "when using default grant flows" do
46
- it 'accepts "code" as response type' do
47
- attributes[:response_type] = "code"
48
- expect(subject).to be_authorizable
49
- end
50
-
51
- it 'accepts "token" as response type' do
52
- allow(server).to receive(:grant_flows).and_return(["implicit"])
53
- attributes[:response_type] = "token"
54
- expect(subject).to be_authorizable
55
- end
56
- end
57
-
58
- context "when authorization code grant flow is disabled" do
59
- before do
60
- allow(server).to receive(:grant_flows).and_return(["implicit"])
61
- end
62
-
63
- it 'does not accept "code" as response type' do
64
- attributes[:response_type] = "code"
65
- expect(subject).not_to be_authorizable
66
- end
67
- end
68
-
69
- context "when implicit grant flow is disabled" do
70
- before do
71
- allow(server).to receive(:grant_flows).and_return(["authorization_code"])
72
- end
73
-
74
- it 'does not accept "token" as response type' do
75
- attributes[:response_type] = "token"
76
- expect(subject).not_to be_authorizable
77
- end
78
- end
79
-
80
- context "when grant flow is client credentials & redirect_uri is nil" do
81
- before do
82
- allow(server).to receive(:grant_flows).and_return(["client_credentials"])
83
- allow(Doorkeeper.configuration).to receive(:allow_grant_flow_for_client?).and_return(false)
84
- application.update_column :redirect_uri, nil
85
- end
86
-
87
- it "is not authorizable" do
88
- expect(subject).not_to be_authorizable
89
- end
90
- end
91
-
92
- context "when client application does not restrict valid scopes" do
93
- it "accepts valid scopes" do
94
- attributes[:scope] = "public"
95
- expect(subject).to be_authorizable
96
- end
97
-
98
- it "rejects (globally) non-valid scopes" do
99
- attributes[:scope] = "invalid"
100
- expect(subject).not_to be_authorizable
101
- end
102
-
103
- it "accepts scopes which are permitted for grant_type" do
104
- allow(server).to receive(:scopes_by_grant_type).and_return(authorization_code: [:public])
105
- attributes[:scope] = "public"
106
- expect(subject).to be_authorizable
107
- end
108
-
109
- it "rejects scopes which are not permitted for grant_type" do
110
- allow(server).to receive(:scopes_by_grant_type).and_return(authorization_code: [:profile])
111
- attributes[:scope] = "public"
112
- expect(subject).not_to be_authorizable
113
- end
114
- end
115
-
116
- context "when client application restricts valid scopes" do
117
- let(:application) do
118
- FactoryBot.create(:application, scopes: Doorkeeper::OAuth::Scopes.from_string("public nonsense"))
119
- end
120
-
121
- it "accepts valid scopes" do
122
- attributes[:scope] = "public"
123
- expect(subject).to be_authorizable
124
- end
125
-
126
- it "rejects (globally) non-valid scopes" do
127
- attributes[:scope] = "invalid"
128
- expect(subject).not_to be_authorizable
129
- end
130
-
131
- it "rejects (application level) non-valid scopes" do
132
- attributes[:scope] = "profile"
133
- expect(subject).not_to be_authorizable
134
- end
135
-
136
- it "accepts scopes which are permitted for grant_type" do
137
- allow(server).to receive(:scopes_by_grant_type).and_return(authorization_code: [:public])
138
- attributes[:scope] = "public"
139
- expect(subject).to be_authorizable
140
- end
141
-
142
- it "rejects scopes which are not permitted for grant_type" do
143
- allow(server).to receive(:scopes_by_grant_type).and_return(authorization_code: [:profile])
144
- attributes[:scope] = "public"
145
- expect(subject).not_to be_authorizable
146
- end
147
- end
148
-
149
- context "when scope is not provided to pre_authorization" do
150
- before { attributes[:scope] = nil }
151
-
152
- context "when default scopes is provided" do
153
- it "uses default scopes" do
154
- allow(server).to receive(:default_scopes).and_return(Doorkeeper::OAuth::Scopes.from_string("default_scope"))
155
- expect(subject).to be_authorizable
156
- expect(subject.scope).to eq("default_scope")
157
- expect(subject.scopes).to eq(Doorkeeper::OAuth::Scopes.from_string("default_scope"))
158
- end
159
- end
160
-
161
- context "when default scopes is none" do
162
- it "not be authorizable when none default scope" do
163
- allow(server).to receive(:default_scopes).and_return(Doorkeeper::OAuth::Scopes.new)
164
- expect(subject).not_to be_authorizable
165
- end
166
- end
167
- end
168
-
169
- it "matches the redirect uri against client's one" do
170
- attributes[:redirect_uri] = "http://nothesame.com"
171
- expect(subject).not_to be_authorizable
172
- end
173
-
174
- it "stores the state" do
175
- expect(subject.state).to eq("save-this")
176
- end
177
-
178
- it "rejects if response type is not allowed" do
179
- attributes[:response_type] = "whops"
180
- expect(subject).not_to be_authorizable
181
- end
182
-
183
- it "requires an existing client" do
184
- attributes[:client_id] = nil
185
- expect(subject).not_to be_authorizable
186
- end
187
-
188
- it "requires a redirect uri" do
189
- attributes[:redirect_uri] = nil
190
- expect(subject).not_to be_authorizable
191
- end
192
-
193
- context "when resource_owner cannot access client application" do
194
- before { allow(Doorkeeper.configuration).to receive(:authorize_resource_owner_for_client).and_return(->(*_) { false }) }
195
-
196
- it "is not authorizable" do
197
- expect(subject).not_to be_authorizable
198
- end
199
- end
200
-
201
- describe "as_json" do
202
- before { subject.authorizable? }
203
-
204
- it { is_expected.to respond_to :as_json }
205
-
206
- shared_examples "returns the pre authorization" do
207
- it "returns the pre authorization" do
208
- expect(json[:client_id]).to eq client.uid
209
- expect(json[:redirect_uri]).to eq subject.redirect_uri
210
- expect(json[:state]).to eq subject.state
211
- expect(json[:response_type]).to eq subject.response_type
212
- expect(json[:scope]).to eq subject.scope
213
- expect(json[:client_name]).to eq client.name
214
- expect(json[:status]).to eq I18n.t("doorkeeper.pre_authorization.status")
215
- end
216
- end
217
-
218
- context "when called without params" do
219
- let(:json) { subject.as_json }
220
-
221
- include_examples "returns the pre authorization"
222
- end
223
-
224
- context "when called with params" do
225
- let(:json) { subject.as_json(foo: "bar") }
226
-
227
- include_examples "returns the pre authorization"
228
- end
229
- end
230
- end
@@ -1,166 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.describe Doorkeeper::OAuth::RefreshTokenRequest do
6
- subject { described_class.new(server, refresh_token, credentials) }
7
-
8
- let(:server) do
9
- double :server, access_token_expires_in: 2.minutes
10
- end
11
-
12
- let(:refresh_token) do
13
- FactoryBot.create(:access_token, use_refresh_token: true)
14
- end
15
-
16
- let(:client) { refresh_token.application }
17
- let(:credentials) { Doorkeeper::OAuth::Client::Credentials.new(client.uid, client.secret) }
18
-
19
- before do
20
- allow(Doorkeeper::AccessToken).to receive(:refresh_token_revoked_on_use?).and_return(false)
21
- allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(false)
22
- end
23
-
24
- it "issues a new token for the client" do
25
- expect { subject.authorize }.to change { client.reload.access_tokens.count }.by(1)
26
- # #sort_by used for MongoDB ORM extensions for valid ordering
27
- expect(client.reload.access_tokens.max_by(&:created_at).expires_in).to eq(refresh_token.expires_in)
28
- end
29
-
30
- it "issues a new token for the client with the same expiry as of original token" do
31
- allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
32
- allow(Doorkeeper::AccessToken).to receive(:refresh_token_revoked_on_use?).and_return(false)
33
-
34
- described_class.new(server, refresh_token, credentials).authorize
35
-
36
- # #sort_by used for MongoDB ORM extensions for valid ordering
37
- expect(client.reload.access_tokens.max_by(&:created_at).expires_in).to eq(refresh_token.expires_in)
38
- end
39
-
40
- it "revokes the previous token" do
41
- expect { subject.authorize }.to change(refresh_token, :revoked?).from(false).to(true)
42
- end
43
-
44
- it "calls configured request callback methods" do
45
- expect(Doorkeeper.configuration.before_successful_strategy_response)
46
- .to receive(:call).with(subject).once
47
-
48
- expect(Doorkeeper.configuration.after_successful_strategy_response)
49
- .to receive(:call).with(subject, instance_of(Doorkeeper::OAuth::TokenResponse)).once
50
-
51
- subject.authorize
52
- end
53
-
54
- it "requires the refresh token" do
55
- request = described_class.new(server, nil, credentials)
56
- request.validate
57
- expect(request.error).to eq(:invalid_request)
58
- expect(request.missing_param).to eq(:refresh_token)
59
- end
60
-
61
- it "requires credentials to be valid if provided" do
62
- credentials = Doorkeeper::OAuth::Client::Credentials.new("invalid", "invalid")
63
- request = described_class.new(server, refresh_token, credentials)
64
- request.validate
65
- expect(request.error).to eq(:invalid_client)
66
- end
67
-
68
- it "requires the token's client and current client to match" do
69
- other_app = FactoryBot.create(:application)
70
- credentials = Doorkeeper::OAuth::Client::Credentials.new(other_app.uid, other_app.secret)
71
-
72
- request = described_class.new(server, refresh_token, credentials)
73
- request.validate
74
- expect(request.error).to eq(:invalid_grant)
75
- end
76
-
77
- it "rejects revoked tokens" do
78
- refresh_token.revoke
79
- subject.validate
80
- expect(subject.error).to eq(:invalid_grant)
81
- end
82
-
83
- it "accepts expired tokens" do
84
- refresh_token.expires_in = -1
85
- refresh_token.save
86
- subject.validate
87
- expect(subject).to be_valid
88
- end
89
-
90
- context "when refresh tokens expire on access token use" do
91
- before do
92
- allow(Doorkeeper::AccessToken).to receive(:refresh_token_revoked_on_use?).and_return(true)
93
- end
94
-
95
- it "issues a new token for the client" do
96
- expect { subject.authorize }.to change { client.reload.access_tokens.count }.by(1)
97
- end
98
-
99
- it "does not revoke the previous token" do
100
- subject.authorize
101
- expect(refresh_token).not_to be_revoked
102
- end
103
-
104
- it "sets the previous refresh token in the new access token" do
105
- subject.authorize
106
- expect(
107
- # #sort_by used for MongoDB ORM extensions for valid ordering
108
- client.access_tokens.max_by(&:created_at).previous_refresh_token,
109
- ).to eq(refresh_token.refresh_token)
110
- end
111
- end
112
-
113
- context "with clientless access tokens" do
114
- subject { described_class.new server, refresh_token, nil }
115
-
116
- let!(:refresh_token) { FactoryBot.create(:clientless_access_token, use_refresh_token: true) }
117
-
118
- it "issues a new token without a client" do
119
- expect { subject.authorize }.to change { Doorkeeper::AccessToken.count }.by(1)
120
- end
121
- end
122
-
123
- context "with scopes" do
124
- subject { described_class.new server, refresh_token, credentials, parameters }
125
-
126
- let(:refresh_token) do
127
- FactoryBot.create :access_token,
128
- use_refresh_token: true,
129
- scopes: "public write"
130
- end
131
- let(:parameters) { {} }
132
-
133
- it "transfers scopes from the old token to the new token" do
134
- subject.authorize
135
- expect(Doorkeeper::AccessToken.last.scopes).to eq(%i[public write])
136
- end
137
-
138
- it "reduces scopes to the provided scopes" do
139
- parameters[:scopes] = "public"
140
- subject.authorize
141
- expect(Doorkeeper::AccessToken.last.scopes).to eq(%i[public])
142
- end
143
-
144
- it "validates that scopes are included in the original access token" do
145
- parameters[:scopes] = "public update"
146
-
147
- subject.validate
148
- expect(subject.error).to eq(:invalid_scope)
149
- end
150
-
151
- it "uses params[:scope] in favor of scopes if present (valid)" do
152
- parameters[:scopes] = "public update"
153
- parameters[:scope] = "public"
154
- subject.authorize
155
- expect(Doorkeeper::AccessToken.last.scopes).to eq(%i[public])
156
- end
157
-
158
- it "uses params[:scope] in favor of scopes if present (invalid)" do
159
- parameters[:scopes] = "public"
160
- parameters[:scope] = "public update"
161
-
162
- subject.validate
163
- expect(subject.error).to eq(:invalid_scope)
164
- end
165
- end
166
- end
@@ -1,146 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.describe Doorkeeper::OAuth::Scopes do
6
- describe "#add" do
7
- it "allows you to add scopes with symbols" do
8
- subject.add :public
9
- expect(subject.all).to eq(["public"])
10
- end
11
-
12
- it "allows you to add scopes with strings" do
13
- subject.add "public"
14
- expect(subject.all).to eq(["public"])
15
- end
16
-
17
- it "do not add already included scopes" do
18
- subject.add :public
19
- subject.add :public
20
- expect(subject.all).to eq(["public"])
21
- end
22
- end
23
-
24
- describe "#exists" do
25
- before do
26
- subject.add :public
27
- end
28
-
29
- it "returns true if scope with given name is present" do
30
- expect(subject).to exist("public")
31
- end
32
-
33
- it "returns false if scope with given name does not exist" do
34
- expect(subject).not_to exist("other")
35
- end
36
-
37
- it "handles symbols" do
38
- expect(subject).to exist(:public)
39
- expect(subject).not_to exist(:other)
40
- end
41
- end
42
-
43
- describe ".from_string" do
44
- subject { described_class.from_string(string) }
45
-
46
- let(:string) { "public write" }
47
-
48
- it { expect(subject).to be_a(described_class) }
49
-
50
- describe "#all" do
51
- it "is an array of the expected scopes" do
52
- scopes_array = subject.all
53
- expect(scopes_array.size).to eq(2)
54
- expect(scopes_array).to include("public")
55
- expect(scopes_array).to include("write")
56
- end
57
- end
58
- end
59
-
60
- describe "#+" do
61
- it "can add to another scope object" do
62
- scopes = described_class.from_string("public") + described_class.from_string("admin")
63
- expect(scopes.all).to eq(%w[public admin])
64
- end
65
-
66
- it "does not change the existing object" do
67
- origin = described_class.from_string("public")
68
- expect(origin.to_s).to eq("public")
69
- end
70
-
71
- it "can add an array to a scope object" do
72
- scopes = described_class.from_string("public") + ["admin"]
73
- expect(scopes.all).to eq(%w[public admin])
74
- end
75
-
76
- it "raises an error if cannot handle addition" do
77
- expect do
78
- described_class.from_string("public") + "admin"
79
- end.to raise_error(NoMethodError)
80
- end
81
- end
82
-
83
- describe "#&" do
84
- it "can get intersection with another scope object" do
85
- scopes = described_class.from_string("public admin") & described_class.from_string("write admin")
86
- expect(scopes.all).to eq(%w[admin])
87
- end
88
-
89
- it "does not change the existing object" do
90
- origin = described_class.from_string("public admin")
91
- origin & described_class.from_string("write admin")
92
- expect(origin.to_s).to eq("public admin")
93
- end
94
-
95
- it "can get intersection with an array" do
96
- scopes = described_class.from_string("public admin") & %w[write admin]
97
- expect(scopes.all).to eq(%w[admin])
98
- end
99
- end
100
-
101
- describe "#==" do
102
- it "is equal to another set of scopes" do
103
- expect(described_class.from_string("public")).to eq(described_class.from_string("public"))
104
- end
105
-
106
- it "is equal to another set of scopes with no particular order" do
107
- expect(described_class.from_string("public write")).to eq(described_class.from_string("write public"))
108
- end
109
-
110
- it "differs from another set of scopes when scopes are not the same" do
111
- expect(described_class.from_string("public write")).not_to eq(described_class.from_string("write"))
112
- end
113
-
114
- it "does not raise an error when compared to a non-enumerable object" do
115
- expect { described_class.from_string("public") == false }.not_to raise_error
116
- end
117
- end
118
-
119
- describe "#has_scopes?" do
120
- subject { described_class.from_string("public admin") }
121
-
122
- it "returns true when at least one scope is included" do
123
- expect(subject).to have_scopes(described_class.from_string("public"))
124
- end
125
-
126
- it "returns true when all scopes are included" do
127
- expect(subject).to have_scopes(described_class.from_string("public admin"))
128
- end
129
-
130
- it "is true if all scopes are included in any order" do
131
- expect(subject).to have_scopes(described_class.from_string("admin public"))
132
- end
133
-
134
- it "is false if no scopes are included" do
135
- expect(subject).not_to have_scopes(described_class.from_string("notexistent"))
136
- end
137
-
138
- it "returns false when any scope is not included" do
139
- expect(subject).not_to have_scopes(described_class.from_string("public nope"))
140
- end
141
-
142
- it "is false if no scopes are included even for existing ones" do
143
- expect(subject).not_to have_scopes(described_class.from_string("public admin notexistent"))
144
- end
145
- end
146
- end
@@ -1,164 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.describe Doorkeeper::OAuth::TokenRequest do
6
- subject do
7
- described_class.new(pre_auth, owner)
8
- end
9
-
10
- let :application do
11
- FactoryBot.create(:application, scopes: "public")
12
- end
13
-
14
- let :pre_auth do
15
- server = Doorkeeper.config
16
- allow(server).to receive(:default_scopes).and_return(Doorkeeper::OAuth::Scopes.from_string("public"))
17
- allow(server).to receive(:grant_flows).and_return(Doorkeeper::OAuth::Scopes.from_string("implicit"))
18
-
19
- client = Doorkeeper::OAuth::Client.new(application)
20
-
21
- attributes = {
22
- client_id: client.uid,
23
- response_type: "token",
24
- redirect_uri: "https://app.com/callback",
25
- }
26
-
27
- pre_auth = Doorkeeper::OAuth::PreAuthorization.new(server, attributes)
28
- pre_auth.authorizable?
29
- pre_auth
30
- end
31
-
32
- let :owner do
33
- FactoryBot.create(:doorkeeper_testing_user)
34
- end
35
-
36
- it "creates an access token" do
37
- expect do
38
- subject.authorize
39
- end.to change { Doorkeeper::AccessToken.count }.by(1)
40
- end
41
-
42
- it "returns a code response" do
43
- expect(subject.authorize).to be_a(Doorkeeper::OAuth::CodeResponse)
44
- end
45
-
46
- context "when pre_auth is denied" do
47
- it "does not create token and returns a error response" do
48
- expect { subject.deny }.not_to(change { Doorkeeper::AccessToken.count })
49
- expect(subject.deny).to be_a(Doorkeeper::OAuth::ErrorResponse)
50
- end
51
- end
52
-
53
- describe "with custom expiration" do
54
- context "when proper TTL returned" do
55
- before do
56
- Doorkeeper.configure do
57
- orm DOORKEEPER_ORM
58
- custom_access_token_expires_in do |context|
59
- context.grant_type == Doorkeeper::OAuth::IMPLICIT ? 1234 : nil
60
- end
61
- end
62
- end
63
-
64
- it "uses the custom ttl" do
65
- subject.authorize
66
- token = Doorkeeper::AccessToken.first
67
- expect(token.expires_in).to eq(1234)
68
- end
69
- end
70
-
71
- context "when nil TTL returned" do
72
- before do
73
- Doorkeeper.configure do
74
- orm DOORKEEPER_ORM
75
- access_token_expires_in 654
76
- custom_access_token_expires_in do |_context|
77
- nil
78
- end
79
- end
80
- end
81
-
82
- it "fallbacks to access_token_expires_in" do
83
- subject.authorize
84
- token = Doorkeeper::AccessToken.first
85
- expect(token.expires_in).to eq(654)
86
- end
87
- end
88
-
89
- context "when infinite TTL returned" do
90
- before do
91
- Doorkeeper.configure do
92
- orm DOORKEEPER_ORM
93
- access_token_expires_in 654
94
- custom_access_token_expires_in do |_context|
95
- Float::INFINITY
96
- end
97
- end
98
- end
99
-
100
- it "fallbacks to access_token_expires_in" do
101
- subject.authorize
102
- token = Doorkeeper::AccessToken.first
103
- expect(token.expires_in).to be_nil
104
- end
105
- end
106
- end
107
-
108
- context "when reuse_access_token enabled" do
109
- it "creates a new token if there are no matching tokens" do
110
- allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
111
- expect do
112
- subject.authorize
113
- end.to change { Doorkeeper::AccessToken.count }.by(1)
114
- end
115
-
116
- it "creates a new token if scopes do not match" do
117
- allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
118
- FactoryBot.create(
119
- :access_token,
120
- application_id: pre_auth.client.id,
121
- resource_owner_id: owner.id,
122
- resource_owner_type: owner.class.name,
123
- scopes: "",
124
- )
125
-
126
- expect do
127
- subject.authorize
128
- end.to change { Doorkeeper::AccessToken.count }.by(1)
129
- end
130
-
131
- it "skips token creation if there is a matching one reusable" do
132
- allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
133
- allow(application.scopes).to receive(:has_scopes?).and_return(true)
134
- allow(application.scopes).to receive(:all?).and_return(true)
135
-
136
- FactoryBot.create(
137
- :access_token, application_id: pre_auth.client.id,
138
- resource_owner_id: owner.id, resource_owner_type: owner.class.name, scopes: "public",
139
- )
140
-
141
- expect { subject.authorize }.not_to(change { Doorkeeper::AccessToken.count })
142
- end
143
-
144
- it "creates new token if there is a matching one but non reusable" do
145
- allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
146
- allow(application.scopes).to receive(:has_scopes?).and_return(true)
147
- allow(application.scopes).to receive(:all?).and_return(true)
148
-
149
- FactoryBot.create(
150
- :access_token,
151
- application_id: pre_auth.client.id,
152
- resource_owner_id: owner.id,
153
- resource_owner_type: owner.class.name,
154
- scopes: "public",
155
- )
156
-
157
- allow_any_instance_of(Doorkeeper::AccessToken).to receive(:reusable?).and_return(false)
158
-
159
- expect do
160
- subject.authorize
161
- end.to change { Doorkeeper::AccessToken.count }.by(1)
162
- end
163
- end
164
- end