doorkeeper-mongodb 5.3.0 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/Rakefile +18 -4
  4. data/lib/doorkeeper/orm/mongoid9/access_grant.rb +26 -0
  5. data/lib/doorkeeper/orm/mongoid9/access_token.rb +38 -0
  6. data/lib/doorkeeper/orm/mongoid9/application.rb +43 -0
  7. data/lib/doorkeeper/orm/mongoid9/stale_records_cleaner.rb +11 -0
  8. data/lib/doorkeeper/orm/mongoid9.rb +50 -0
  9. data/lib/doorkeeper-mongodb/mixins/mongoid/access_grant_mixin.rb +6 -2
  10. data/lib/doorkeeper-mongodb/mixins/mongoid/access_token_mixin.rb +46 -6
  11. data/lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb +2 -2
  12. data/lib/doorkeeper-mongodb/version.rb +1 -1
  13. data/lib/doorkeeper-mongodb.rb +1 -0
  14. data/spec/dummy/app/assets/config/manifest.js +0 -0
  15. data/spec/dummy/app/controllers/application_controller.rb +0 -0
  16. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +0 -0
  17. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +0 -0
  18. data/spec/dummy/app/controllers/home_controller.rb +0 -0
  19. data/spec/dummy/app/controllers/metal_controller.rb +0 -0
  20. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +0 -0
  21. data/spec/dummy/app/helpers/application_helper.rb +0 -0
  22. data/spec/dummy/app/views/home/index.html.erb +0 -0
  23. data/spec/dummy/app/views/layouts/application.html.erb +0 -0
  24. data/spec/dummy/config/application.rb +0 -0
  25. data/spec/dummy/config/boot.rb +0 -0
  26. data/spec/dummy/config/database.yml +0 -0
  27. data/spec/dummy/config/environment.rb +0 -0
  28. data/spec/dummy/config/environments/development.rb +0 -0
  29. data/spec/dummy/config/environments/production.rb +0 -0
  30. data/spec/dummy/config/environments/test.rb +0 -0
  31. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -0
  32. data/spec/dummy/config/initializers/doorkeeper.rb +7 -2
  33. data/spec/dummy/config/initializers/secret_token.rb +0 -0
  34. data/spec/dummy/config/initializers/session_store.rb +0 -0
  35. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -0
  36. data/spec/dummy/config/locales/doorkeeper.en.yml +0 -0
  37. data/spec/dummy/config/mongoid8.yml +19 -0
  38. data/spec/dummy/config/mongoid9.yml +19 -0
  39. data/spec/dummy/config/routes.rb +0 -0
  40. data/spec/dummy/config.ru +1 -1
  41. data/spec/dummy/db/migrate/20111122132257_create_users.rb +0 -0
  42. data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +0 -0
  43. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +0 -0
  44. data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +0 -0
  45. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +0 -0
  46. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +0 -0
  47. data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +0 -0
  48. data/spec/dummy/db/migrate/20230205064514_add_custom_attributes.rb +8 -0
  49. data/spec/dummy/db/schema.rb +3 -1
  50. data/spec/dummy/log/test.log +39440 -0
  51. data/spec/dummy/public/404.html +0 -0
  52. data/spec/dummy/public/422.html +0 -0
  53. data/spec/dummy/public/500.html +0 -0
  54. data/spec/dummy/public/favicon.ico +0 -0
  55. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/2L/2LdlR-88TqZc8vSU7Z58xiNpCGRZj0CIlOxSN4Vx2i4.cache +1 -0
  56. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{Pn/PnXU_mkG2fLZFm9BwiZ03BZdBTjKuInP-cRXjHS7yJo.cache → 2r/2r0L9eNOmETsg4Tm1IgBdw3J4ahcko41NpILRXu19_A.cache} +0 -0
  57. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/5y/5ywocFQgpSY36nyF_xDKPExhDRo-eqeiqfDvQee1K9k.cache +2 -0
  58. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{Qs/QsVgO6vM5Yn9oeYTYlrqtyVnK6sdVDWDa083N7zpfHw.cache → 8r/8rW0CpDDUJZ7xvg86t6jZ6WmyvaVZ0uTPEPRjghFIKo.cache} +0 -0
  59. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{PA/PAH_jI20wRw12tngeJ-V619c30avNLDu5U9Z-9Pc5SQ.cache → Cs/CsfBL8Dls9-jhjFsNYt4DZxu5LWChDMB-xXKjsEFSsU.cache} +0 -0
  60. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{8D/8DJG7JfPvShfLLyeSom6NZ_TcQc6QH27tJ7prEWZPfI.cache → Cv/Cv9WXE_0OqtPUZBXfTWaE8uKx9oFIzqO18ZkwVaBLSg.cache} +0 -0
  61. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Mf/MfB2-0nbsmC548XBSLftafi6BZ9nAquBA-6eu7mAmdE.cache +2 -0
  62. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/N2/N2cUP-Um_nQ5ZTCQr_H0bKIjOSIyV7Ry5sT6-DB9e4A.cache +1 -0
  63. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{FJ/FJlQpfMtpRbrM5P8A7d2FAelFKwo6GrVs2xks8z5GKU.cache → Ot/OtNAnT3d-csAKBtJ8UBLOSwUDyfmOdCWpS08RaSCGsQ.cache} +0 -0
  64. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/P3/P33RwiTMGEu2wZySBEUmf5U7hnfBhdL49wzdUWXYNRs.cache +1 -0
  65. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/RZ/RZAL9gIt4aD731Ikf7UZZNPSZXzhPqtDskLB7nQcWH4.cache +1 -0
  66. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/SQ/SQVJeYO2bM0qgQiOaeVBjYo3SWQZmvixa3tXUjsmuUs.cache +0 -0
  67. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{Ma/MaK3K1AoZZ4xM5fOOifhROd73hfZJpP4yGbkGdoYtEk.cache → V2/V2JApVhUSYhvWnNVIbpe58U4xheVkpi0gCStqjDN6-A.cache} +0 -0
  68. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{Lk/LklIq5hrBAPESXVUpFMwQ9L-1qTj90sPVi6U19_Xi-Q.cache → VA/VADOUaZFukufOb44ts4KoyQZumPcVJET0bi9RvC7c-o.cache} +1 -1
  69. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Vz/VzdPLfWn16XbpHNJdkDMamAf3QutM29cvvPkDNyy5nE.cache +1 -0
  70. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/W9/W9QfraySVwoRt-SgGOIS0e-iP8R1qP_URwXZw1l6M5E.cache +0 -0
  71. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Wy/Wyiw07ngOzgV6RPis_Lo2hhSRkwo2YSqKTEDAF0crhA.cache +0 -0
  72. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Z6/Z6rAtdVt3OXS26vLVCtdO3vmMlttI3ajdpbC2FHk7iQ.cache +0 -0
  73. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/b6/b6QRH6ZdCc0e6bUWu4qni_kZmptaMgWciO8Jl9q6_p8.cache +0 -0
  74. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{Pm/PmheG0PGFqDws1qgFOxOyIL-gpMof3Ar9eSRKVLYuik.cache → fP/fPihom3hnc1rQQxpviTvZPRJB_IghWYWP3dDcsGrcLk.cache} +0 -0
  75. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/gD/gDU38plXvosMgFK47_PBI9xGVsmsE2tShWEZzxiek3k.cache +1 -0
  76. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/gR/gRqL5_jaFW7eA3d2frJmOzw_vFLuvfhwMhotAlsO8J4.cache +2 -0
  77. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/jC/jCTZ1jAldKBn4OTANBBmCKzxLrDgok1ur4meoTqlDNg.cache +0 -0
  78. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{yN/yNOFGOsnHmxXNMkuEAWuL1u3jlmdvrdeoTx6DDJ1in8.cache → jc/jcB8w1gBT7JP10DW4OOvvYpW1ZFeMyedngmMy3QbRLQ.cache} +0 -0
  79. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/jg/jgxXkkkXf1NPOPrpNdEJzhDt-2xHGzd_-mLkIHWrOr4.cache +2 -0
  80. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/nx/nxzZnvk5YyBhTUloQSZZ5zRuaqlsLiHy_AbOzQ3d788.cache +0 -0
  81. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/wr/wrlf8nUW2yftpcIA97qImyECR8f8o3OiOdHLdfkmw8c.cache +1 -0
  82. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{qT/qTQIQsmS0Wbbg2JxNn9rxdI5qVOTg5SfyQdaTvr9vLo.cache → xd/xdD4KJ55W3jy5PIrwT0UnDp1toKpUfgrjJBgB4WaPIc.cache} +0 -0
  83. data/spec/support/doorkeeper_rspec.rb +0 -0
  84. data/spec/support/orm/mongoid.rb +18 -2
  85. data/spec/support/orm/mongoid8.rb +6 -0
  86. data/spec/support/orm/mongoid9.rb +6 -0
  87. data/spec/support/render_with_matcher.rb +26 -0
  88. metadata +126 -241
  89. data/spec/controllers/application_metal_controller_spec.rb +0 -64
  90. data/spec/controllers/applications_controller_spec.rb +0 -270
  91. data/spec/controllers/authorizations_controller_spec.rb +0 -744
  92. data/spec/controllers/protected_resources_controller_spec.rb +0 -361
  93. data/spec/controllers/token_info_controller_spec.rb +0 -50
  94. data/spec/controllers/tokens_controller_spec.rb +0 -542
  95. data/spec/doorkeeper/redirect_uri_validator_spec.rb +0 -183
  96. data/spec/doorkeeper/server_spec.rb +0 -50
  97. data/spec/doorkeeper/stale_records_cleaner_spec.rb +0 -103
  98. data/spec/doorkeeper/version_spec.rb +0 -17
  99. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/-o/-ofn45zIfO5vx4VD6m6NXesLf6da5usA-Sbw2SVju3o.cache +0 -2
  100. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/0_/0_ouGcG_o_1zmVmBe-tdQYk594LBwVa1bumjrKtdfEw.cache +0 -0
  101. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/2X/2XMMcHbyTSRqh1GkV0xzyIETNtt-zgN6iniziShaKmQ.cache +0 -2
  102. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/4Q/4QQw-pMQ98JIj3xdcFhGBQdysdGPY9rWffRqWMmyjew.cache +0 -1
  103. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/7H/7HjRsym0tTpXFCVhWt6kteMs_-CozKVbr9s5syHm8es.cache +0 -1
  104. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8B/8BxJyv22HPFHu1se_l2J8qW1N9NzZ16UOWOy1YMSgs4.cache +0 -1
  105. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/9x/9xjtGv-yKjj62x9uFwBZg8pTSh9ERPAgANwNo9uwIaA.cache +0 -1
  106. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Bt/BtXO7f0PZ8DNt3TMLYM-zY7LkbWa_KgyB0v1V98M1CQ.cache +0 -1
  107. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/E0/E02f1Q2tutWumMulGCFNfqQNjvEP_hMAK_5E83eWepI.cache +0 -0
  108. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/EZ/EZGpd6pUEJZxO6uT2yIS4Fpn5KX7VDgC9VB3AaemF5Q.cache +0 -2
  109. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/L8/L8mOWakJlWKr6MU85rj0V7yGFfNyIR6vE6YXtqArPGw.cache +0 -1
  110. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/MB/MBWRxa9S470ee8suxVKp0jYgv6K6FQOqKGV0kPGQNMs.cache +0 -1
  111. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ph/Ph7RtH_NvG2I8XpTa8mA8SBQXZDzBPVIh4CH6g7OXJ0.cache +0 -2
  112. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/So/So59ksdx2dw-_A3-zFZ6Palr7fROjm7_0JDZb04temw.cache +0 -0
  113. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Wt/WtXL_iDofLeTH_v0Yf3PM421r9b1V0g-VBvMPeu9KA0.cache +0 -0
  114. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/dX/dX6FDdUIy8yBCOoaoXcjf71rX9N_bpiXGJ4Urt32NTk.cache +0 -0
  115. data/spec/factories.rb +0 -30
  116. data/spec/grape/grape_integration_spec.rb +0 -137
  117. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +0 -26
  118. data/spec/lib/config_spec.rb +0 -824
  119. data/spec/lib/doorkeeper_spec.rb +0 -27
  120. data/spec/lib/models/expirable_spec.rb +0 -61
  121. data/spec/lib/models/reusable_spec.rb +0 -40
  122. data/spec/lib/models/revocable_spec.rb +0 -55
  123. data/spec/lib/models/scopes_spec.rb +0 -61
  124. data/spec/lib/models/secret_storable_spec.rb +0 -136
  125. data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -35
  126. data/spec/lib/oauth/authorization_code_request_spec.rb +0 -180
  127. data/spec/lib/oauth/base_request_spec.rb +0 -210
  128. data/spec/lib/oauth/base_response_spec.rb +0 -45
  129. data/spec/lib/oauth/client/credentials_spec.rb +0 -90
  130. data/spec/lib/oauth/client_credentials/creator_spec.rb +0 -135
  131. data/spec/lib/oauth/client_credentials/issuer_spec.rb +0 -110
  132. data/spec/lib/oauth/client_credentials/validation_spec.rb +0 -92
  133. data/spec/lib/oauth/client_credentials_integration_spec.rb +0 -27
  134. data/spec/lib/oauth/client_credentials_request_spec.rb +0 -105
  135. data/spec/lib/oauth/client_spec.rb +0 -38
  136. data/spec/lib/oauth/code_request_spec.rb +0 -46
  137. data/spec/lib/oauth/code_response_spec.rb +0 -36
  138. data/spec/lib/oauth/error_response_spec.rb +0 -65
  139. data/spec/lib/oauth/error_spec.rb +0 -21
  140. data/spec/lib/oauth/forbidden_token_response_spec.rb +0 -20
  141. data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -110
  142. data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -21
  143. data/spec/lib/oauth/helpers/uri_checker_spec.rb +0 -262
  144. data/spec/lib/oauth/invalid_request_response_spec.rb +0 -73
  145. data/spec/lib/oauth/invalid_token_response_spec.rb +0 -53
  146. data/spec/lib/oauth/password_access_token_request_spec.rb +0 -202
  147. data/spec/lib/oauth/pre_authorization_spec.rb +0 -230
  148. data/spec/lib/oauth/refresh_token_request_spec.rb +0 -166
  149. data/spec/lib/oauth/scopes_spec.rb +0 -146
  150. data/spec/lib/oauth/token_request_spec.rb +0 -164
  151. data/spec/lib/oauth/token_response_spec.rb +0 -84
  152. data/spec/lib/oauth/token_spec.rb +0 -156
  153. data/spec/lib/option_spec.rb +0 -51
  154. data/spec/lib/request/strategy_spec.rb +0 -51
  155. data/spec/lib/secret_storing/base_spec.rb +0 -61
  156. data/spec/lib/secret_storing/bcrypt_spec.rb +0 -50
  157. data/spec/lib/secret_storing/plain_spec.rb +0 -45
  158. data/spec/lib/secret_storing/sha256_hash_spec.rb +0 -49
  159. data/spec/models/doorkeeper/access_grant_spec.rb +0 -173
  160. data/spec/models/doorkeeper/access_token_spec.rb +0 -644
  161. data/spec/models/doorkeeper/application_spec.rb +0 -499
  162. data/spec/requests/applications/applications_request_spec.rb +0 -257
  163. data/spec/requests/applications/authorized_applications_spec.rb +0 -32
  164. data/spec/requests/endpoints/authorization_spec.rb +0 -91
  165. data/spec/requests/endpoints/token_spec.rb +0 -85
  166. data/spec/requests/flows/authorization_code_errors_spec.rb +0 -86
  167. data/spec/requests/flows/authorization_code_spec.rb +0 -559
  168. data/spec/requests/flows/client_credentials_spec.rb +0 -219
  169. data/spec/requests/flows/implicit_grant_errors_spec.rb +0 -46
  170. data/spec/requests/flows/implicit_grant_spec.rb +0 -91
  171. data/spec/requests/flows/password_spec.rb +0 -356
  172. data/spec/requests/flows/refresh_token_spec.rb +0 -255
  173. data/spec/requests/flows/revoke_token_spec.rb +0 -196
  174. data/spec/requests/flows/skip_authorization_spec.rb +0 -66
  175. data/spec/requests/protected_resources/metal_spec.rb +0 -16
  176. data/spec/requests/protected_resources/private_api_spec.rb +0 -83
  177. data/spec/routing/custom_controller_routes_spec.rb +0 -133
  178. data/spec/routing/default_routes_spec.rb +0 -41
  179. data/spec/routing/scoped_routes_spec.rb +0 -47
  180. data/spec/spec_helper.rb +0 -54
  181. data/spec/spec_helper_integration.rb +0 -4
  182. data/spec/support/dependencies/factory_bot.rb +0 -4
  183. data/spec/support/helpers/access_token_request_helper.rb +0 -14
  184. data/spec/support/helpers/authorization_request_helper.rb +0 -43
  185. data/spec/support/helpers/config_helper.rb +0 -11
  186. data/spec/support/helpers/model_helper.rb +0 -78
  187. data/spec/support/helpers/request_spec_helper.rb +0 -98
  188. data/spec/support/helpers/url_helper.rb +0 -62
  189. data/spec/support/orm/active_record.rb +0 -5
  190. data/spec/support/shared/controllers_shared_context.rb +0 -100
  191. data/spec/support/shared/hashing_shared_context.rb +0 -40
  192. data/spec/support/shared/models_shared_examples.rb +0 -56
@@ -1,262 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- module Doorkeeper::OAuth::Helpers
6
- describe URIChecker do
7
- describe ".valid?" do
8
- it "is valid for valid uris" do
9
- uri = "http://app.co"
10
- expect(described_class).to be_valid(uri)
11
- end
12
-
13
- it "is valid if include path param" do
14
- uri = "http://app.co/path"
15
- expect(described_class).to be_valid(uri)
16
- end
17
-
18
- it "is valid if include query param" do
19
- uri = "http://app.co/?query=1"
20
- expect(described_class).to be_valid(uri)
21
- end
22
-
23
- it "is invalid if uri includes fragment" do
24
- uri = "http://app.co/test#fragment"
25
- expect(described_class).not_to be_valid(uri)
26
- end
27
-
28
- it "is invalid if scheme is missing" do
29
- uri = "app.co"
30
- expect(described_class).not_to be_valid(uri)
31
- end
32
-
33
- it "is invalid if is a relative uri" do
34
- uri = "/abc/123"
35
- expect(described_class).not_to be_valid(uri)
36
- end
37
-
38
- it "is invalid if is not a url" do
39
- uri = "http://"
40
- expect(described_class).not_to be_valid(uri)
41
- end
42
-
43
- it "is invalid if localhost is resolved as as scheme (no scheme specified)" do
44
- uri = "localhost:8080"
45
- expect(described_class).not_to be_valid(uri)
46
- end
47
-
48
- it "is invalid if scheme is missing #2" do
49
- uri = "app.co:80"
50
- expect(described_class).not_to be_valid(uri)
51
- end
52
-
53
- it "is invalid if is not an uri" do
54
- uri = " "
55
- expect(described_class).not_to be_valid(uri)
56
- end
57
-
58
- it "is valid for custom schemes" do
59
- uri = "com.example.app:/test"
60
- expect(described_class).to be_valid(uri)
61
- end
62
-
63
- it "is valid for custom schemes with authority marker (common misconfiguration)" do
64
- uri = "com.example.app://test"
65
- expect(described_class).to be_valid(uri)
66
- end
67
- end
68
-
69
- describe ".matches?" do
70
- it "is true if both url matches" do
71
- uri = client_uri = "http://app.co/aaa"
72
- expect(described_class).to be_matches(uri, client_uri)
73
- end
74
-
75
- it "ignores query parameter on comparison" do
76
- uri = "http://app.co/?query=hello"
77
- client_uri = "http://app.co"
78
- expect(described_class).to be_matches(uri, client_uri)
79
- end
80
-
81
- it "doesn't allow non-matching domains through" do
82
- uri = "http://app.abc/?query=hello"
83
- client_uri = "http://app.co"
84
- expect(described_class).not_to be_matches(uri, client_uri)
85
- end
86
-
87
- it "doesn't allow non-matching domains that don't start at the beginning" do
88
- uri = "http://app.co/?query=hello"
89
- client_uri = "http://example.com?app.co=test"
90
- expect(described_class).not_to be_matches(uri, client_uri)
91
- end
92
-
93
- context "when loopback IP redirect URIs" do
94
- it "ignores port for same URIs" do
95
- uri = "http://127.0.0.1:5555/auth/callback"
96
- client_uri = "http://127.0.0.1:48599/auth/callback"
97
- expect(described_class).to be_matches(uri, client_uri)
98
-
99
- uri = "http://[::1]:5555/auth/callback"
100
- client_uri = "http://[::1]:5555/auth/callback"
101
- expect(described_class).to be_matches(uri, client_uri)
102
- end
103
-
104
- it "doesn't ignore port for URIs with different queries" do
105
- uri = "http://127.0.0.1:5555/auth/callback"
106
- client_uri = "http://127.0.0.1:48599/auth/callback2"
107
- expect(described_class).not_to be_matches(uri, client_uri)
108
- end
109
- end
110
-
111
- context "when client registered query params" do
112
- it "doesn't allow query being absent" do
113
- uri = "http://app.co"
114
- client_uri = "http://app.co/?vendorId=AJ4L7XXW9"
115
- expect(described_class).not_to be_matches(uri, client_uri)
116
- end
117
-
118
- it "is false if query values differ but key same" do
119
- uri = "http://app.co/?vendorId=pancakes"
120
- client_uri = "http://app.co/?vendorId=waffles"
121
- expect(described_class).not_to be_matches(uri, client_uri)
122
- end
123
-
124
- it "is false if query values same but key differs" do
125
- uri = "http://app.co/?foo=pancakes"
126
- client_uri = "http://app.co/?bar=pancakes"
127
- expect(described_class).not_to be_matches(uri, client_uri)
128
- end
129
-
130
- it "is false if query present and match, but unknown queries present" do
131
- uri = "http://app.co/?vendorId=pancakes&unknown=query"
132
- client_uri = "http://app.co/?vendorId=waffles"
133
- expect(described_class).not_to be_matches(uri, client_uri)
134
- end
135
-
136
- it "is true if queries are present and matche" do
137
- uri = "http://app.co/?vendorId=AJ4L7XXW9&foo=bar"
138
- client_uri = "http://app.co/?vendorId=AJ4L7XXW9&foo=bar"
139
- expect(described_class).to be_matches(uri, client_uri)
140
- end
141
-
142
- it "is true if queries are present, match and in different order" do
143
- uri = "http://app.co/?bing=bang&foo=bar"
144
- client_uri = "http://app.co/?foo=bar&bing=bang"
145
- expect(described_class).to be_matches(uri, client_uri)
146
- end
147
- end
148
- end
149
-
150
- describe ".valid_for_authorization?" do
151
- it "is true if valid and matches" do
152
- uri = client_uri = "http://app.co/aaa"
153
- expect(described_class).to be_valid_for_authorization(uri, client_uri)
154
-
155
- uri = client_uri = "http://app.co/aaa?b=c"
156
- expect(described_class).to be_valid_for_authorization(uri, client_uri)
157
- end
158
-
159
- it "is true if uri includes blank query" do
160
- uri = client_uri = "http://app.co/aaa?"
161
- expect(described_class).to be_valid_for_authorization(uri, client_uri)
162
-
163
- uri = "http://app.co/aaa?"
164
- client_uri = "http://app.co/aaa"
165
- expect(described_class).to be_valid_for_authorization(uri, client_uri)
166
-
167
- uri = "http://app.co/aaa"
168
- client_uri = "http://app.co/aaa?"
169
- expect(described_class).to be_valid_for_authorization(uri, client_uri)
170
- end
171
-
172
- it "is false if valid and mismatches" do
173
- uri = "http://app.co/aaa"
174
- client_uri = "http://app.co/bbb"
175
- expect(described_class).not_to be_valid_for_authorization(uri, client_uri)
176
- end
177
-
178
- it "is true if valid and included in array" do
179
- uri = "http://app.co/aaa"
180
- client_uri = "http://example.com/bbb\nhttp://app.co/aaa"
181
- expect(described_class).to be_valid_for_authorization(uri, client_uri)
182
- end
183
-
184
- it "is false if valid and not included in array" do
185
- uri = "http://app.co/aaa"
186
- client_uri = "http://example.com/bbb\nhttp://app.co/cc"
187
- expect(described_class).not_to be_valid_for_authorization(uri, client_uri)
188
- end
189
-
190
- it "is false if queries does not match" do
191
- uri = "http://app.co/aaa?pankcakes=abc"
192
- client_uri = "http://app.co/aaa?waffles=abc"
193
- expect(described_class.valid_for_authorization?(uri, client_uri)).to be false
194
- end
195
-
196
- it "calls .matches?" do
197
- uri = "http://app.co/aaa?pankcakes=abc"
198
- client_uri = "http://app.co/aaa?waffles=abc"
199
- expect(described_class).to receive(:matches?).with(uri, client_uri).once
200
- described_class.valid_for_authorization?(uri, client_uri)
201
- end
202
-
203
- it "calls .valid?" do
204
- uri = "http://app.co/aaa?pankcakes=abc"
205
- client_uri = "http://app.co/aaa?waffles=abc"
206
- expect(described_class).to receive(:valid?).with(uri).once
207
- described_class.valid_for_authorization?(uri, client_uri)
208
- end
209
- end
210
-
211
- describe ".query_matches?" do
212
- it "is true if no queries" do
213
- expect(described_class).to be_query_matches("", "")
214
- expect(described_class).to be_query_matches(nil, nil)
215
- end
216
-
217
- it "is true if same query" do
218
- expect(described_class).to be_query_matches("foo", "foo")
219
- end
220
-
221
- it "is false if different query" do
222
- expect(described_class).not_to be_query_matches("foo", "bar")
223
- end
224
-
225
- it "is true if same queries" do
226
- expect(described_class).to be_query_matches("foo&bar", "foo&bar")
227
- end
228
-
229
- it "is true if same queries, different order" do
230
- expect(described_class).to be_query_matches("foo&bar", "bar&foo")
231
- end
232
-
233
- it "is false if one different query" do
234
- expect(described_class).not_to be_query_matches("foo&bang", "foo&bing")
235
- end
236
-
237
- it "is true if same query with same value" do
238
- expect(described_class).to be_query_matches("foo=bar", "foo=bar")
239
- end
240
-
241
- it "is true if same queries with same values" do
242
- expect(described_class).to be_query_matches("foo=bar&bing=bang", "foo=bar&bing=bang")
243
- end
244
-
245
- it "is true if same queries with same values, different order" do
246
- expect(described_class).to be_query_matches("foo=bar&bing=bang", "bing=bang&foo=bar")
247
- end
248
-
249
- it "is false if same query with different value" do
250
- expect(described_class).not_to be_query_matches("foo=bar", "foo=bang")
251
- end
252
-
253
- it "is false if some queries missing" do
254
- expect(described_class).not_to be_query_matches("foo=bar", "foo=bar&bing=bang")
255
- end
256
-
257
- it "is false if some queries different value" do
258
- expect(described_class).not_to be_query_matches("foo=bar&bing=bang", "foo=bar&bing=banana")
259
- end
260
- end
261
- end
262
- end
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.describe Doorkeeper::OAuth::InvalidRequestResponse do
6
- describe "#name" do
7
- it { expect(subject.name).to eq(:invalid_request) }
8
- end
9
-
10
- describe "#status" do
11
- it { expect(subject.status).to eq(:bad_request) }
12
- end
13
-
14
- describe ".from_request" do
15
- let(:response) { described_class.from_request(request) }
16
-
17
- context "when param missed" do
18
- let(:request) { double(missing_param: "some_param") }
19
-
20
- it "sets a description" do
21
- expect(response.description).to eq(
22
- I18n.t(:missing_param, scope: %i[doorkeeper errors messages invalid_request], value: "some_param"),
23
- )
24
- end
25
-
26
- it "sets the reason" do
27
- expect(response.reason).to eq(:missing_param)
28
- end
29
- end
30
-
31
- context "when server doesn't support PKCE" do
32
- let(:request) { double(invalid_request_reason: :not_support_pkce) }
33
-
34
- it "sets a description" do
35
- expect(response.description).to eq(
36
- I18n.t(:not_support_pkce, scope: %i[doorkeeper errors messages invalid_request]),
37
- )
38
- end
39
-
40
- it "sets the reason" do
41
- expect(response.reason).to eq(:not_support_pkce)
42
- end
43
- end
44
-
45
- context "when request is not authorized" do
46
- let(:request) { double(invalid_request_reason: :request_not_authorized) }
47
-
48
- it "sets a description" do
49
- expect(response.description).to eq(
50
- I18n.t(:request_not_authorized, scope: %i[doorkeeper errors messages invalid_request]),
51
- )
52
- end
53
-
54
- it "sets the reason" do
55
- expect(response.reason).to eq(:request_not_authorized)
56
- end
57
- end
58
-
59
- context "when unknown reason" do
60
- let(:request) { double(invalid_request_reason: :unknown_reason) }
61
-
62
- it "sets a description" do
63
- expect(response.description).to eq(
64
- I18n.t(:unknown, scope: %i[doorkeeper errors messages invalid_request]),
65
- )
66
- end
67
-
68
- it "sets the reason to unknown" do
69
- expect(response.reason).to eq(:unknown_reason)
70
- end
71
- end
72
- end
73
- end
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.describe Doorkeeper::OAuth::InvalidTokenResponse do
6
- describe "#name" do
7
- it { expect(subject.name).to eq(:invalid_token) }
8
- end
9
-
10
- describe "#status" do
11
- it { expect(subject.status).to eq(:unauthorized) }
12
- end
13
-
14
- describe ".from_access_token" do
15
- let(:response) { described_class.from_access_token(access_token) }
16
-
17
- context "when token revoked" do
18
- let(:access_token) { double(revoked?: true, expired?: true) }
19
-
20
- it "sets a description" do
21
- expect(response.description).to include("revoked")
22
- end
23
-
24
- it "sets the reason" do
25
- expect(response.reason).to eq(:revoked)
26
- end
27
- end
28
-
29
- context "when token expired" do
30
- let(:access_token) { double(revoked?: false, expired?: true) }
31
-
32
- it "sets a description" do
33
- expect(response.description).to include("expired")
34
- end
35
-
36
- it "sets the reason" do
37
- expect(response.reason).to eq(:expired)
38
- end
39
- end
40
-
41
- context "when unknown" do
42
- let(:access_token) { double(revoked?: false, expired?: false) }
43
-
44
- it "sets a description" do
45
- expect(response.description).to include("invalid")
46
- end
47
-
48
- it "sets the reason" do
49
- expect(response.reason).to eq(:unknown)
50
- end
51
- end
52
- end
53
- end
@@ -1,202 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.describe Doorkeeper::OAuth::PasswordAccessTokenRequest do
6
- subject do
7
- described_class.new(server, client, owner)
8
- end
9
-
10
- let(:server) do
11
- double(
12
- :server,
13
- default_scopes: Doorkeeper::OAuth::Scopes.new,
14
- access_token_expires_in: 2.hours,
15
- refresh_token_enabled?: false,
16
- custom_access_token_expires_in: lambda { |context|
17
- context.grant_type == Doorkeeper::OAuth::PASSWORD ? 1234 : nil
18
- },
19
- )
20
- end
21
- let(:client) { Doorkeeper::OAuth::Client.new(FactoryBot.create(:application)) }
22
- let(:application) { client.application }
23
- let(:owner) { FactoryBot.build_stubbed(:resource_owner) }
24
-
25
- before do
26
- allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
27
- end
28
-
29
- it "issues a new token for the client" do
30
- expect do
31
- subject.authorize
32
- end.to change { application.reload.access_tokens.count }.by(1)
33
-
34
- expect(application.reload.access_tokens.max_by(&:created_at).expires_in).to eq(1234)
35
- end
36
-
37
- it "issues a new token without a client" do
38
- subject = described_class.new(server, nil, owner)
39
- expect(subject).to be_valid
40
-
41
- expect do
42
- subject.authorize
43
- end.to change { Doorkeeper::AccessToken.count }.by(1)
44
- end
45
-
46
- it "does not issue a new token with an invalid client" do
47
- subject = described_class.new(server, nil, owner, { client_id: "bad_id" })
48
- expect do
49
- subject.authorize
50
- end.not_to(change { Doorkeeper::AccessToken.count })
51
-
52
- expect(subject.error).to eq(:invalid_client)
53
- end
54
-
55
- it "requires the owner" do
56
- subject = described_class.new(server, client, nil)
57
- subject.validate
58
- expect(subject.error).to eq(:invalid_grant)
59
- end
60
-
61
- it "creates token even when there is already one (default)" do
62
- FactoryBot.create(
63
- :access_token,
64
- application_id: client.id,
65
- resource_owner_id: owner.id,
66
- resource_owner_type: owner.class.name,
67
- )
68
-
69
- expect do
70
- subject.authorize
71
- end.to change { Doorkeeper::AccessToken.count }.by(1)
72
- end
73
-
74
- it "skips token creation if there is already one reusable" do
75
- allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
76
- FactoryBot.create(
77
- :access_token,
78
- application_id: client.id,
79
- resource_owner_id: owner.id,
80
- resource_owner_type: owner.class.name,
81
- )
82
-
83
- expect do
84
- subject.authorize
85
- end.not_to(change { Doorkeeper::AccessToken.count })
86
- end
87
-
88
- it "creates token when there is already one but non reusable" do
89
- allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
90
- FactoryBot.create(
91
- :access_token,
92
- application_id: client.id,
93
- resource_owner_id: owner.id,
94
- resource_owner_type: owner.class.name,
95
- )
96
- allow_any_instance_of(Doorkeeper::AccessToken).to receive(:reusable?).and_return(false)
97
-
98
- expect do
99
- subject.authorize
100
- end.to change { Doorkeeper::AccessToken.count }.by(1)
101
- end
102
-
103
- it "calls configured request callback methods" do
104
- expect(Doorkeeper.configuration.before_successful_strategy_response)
105
- .to receive(:call).with(subject).once
106
-
107
- expect(Doorkeeper.configuration.after_successful_strategy_response)
108
- .to receive(:call).with(subject, instance_of(Doorkeeper::OAuth::TokenResponse)).once
109
-
110
- subject.authorize
111
- end
112
-
113
- describe "with scopes" do
114
- subject do
115
- described_class.new(server, client, owner, scope: "public")
116
- end
117
-
118
- context "when scopes_by_grant_type is not configured for grant_type" do
119
- it "returns error when scopes are invalid" do
120
- allow(server).to receive(:scopes).and_return(Doorkeeper::OAuth::Scopes.from_string("another"))
121
- subject.validate
122
- expect(subject.error).to eq(:invalid_scope)
123
- end
124
-
125
- it "creates the token with scopes if scopes are valid" do
126
- allow(server).to receive(:scopes).and_return(Doorkeeper::OAuth::Scopes.from_string("public"))
127
- expect do
128
- subject.authorize
129
- end.to change { Doorkeeper::AccessToken.count }.by(1)
130
-
131
- expect(Doorkeeper::AccessToken.last.scopes).to include("public")
132
- end
133
- end
134
-
135
- context "when scopes_by_grant_type is configured for grant_type" do
136
- it "returns error when scopes are valid but not permitted for grant_type" do
137
- allow(server)
138
- .to receive(:scopes).and_return(Doorkeeper::OAuth::Scopes.from_string("public"))
139
- allow(Doorkeeper.configuration)
140
- .to receive(:scopes_by_grant_type).and_return(password: "another")
141
- subject.validate
142
- expect(subject.error).to eq(:invalid_scope)
143
- end
144
-
145
- it "creates the token with scopes if scopes are valid and permitted for grant_type" do
146
- allow(server).to receive(:scopes).and_return(Doorkeeper::OAuth::Scopes.from_string("public"))
147
- allow(Doorkeeper.configuration)
148
- .to receive(:scopes_by_grant_type).and_return(password: [:public])
149
-
150
- expect do
151
- subject.authorize
152
- end.to change { Doorkeeper::AccessToken.count }.by(1)
153
-
154
- expect(Doorkeeper::AccessToken.last.scopes).to include("public")
155
- end
156
- end
157
- end
158
-
159
- describe "with custom expiry" do
160
- let(:server) do
161
- double(
162
- :server,
163
- default_scopes: Doorkeeper::OAuth::Scopes.new,
164
- access_token_expires_in: 2.hours,
165
- refresh_token_enabled?: false,
166
- custom_access_token_expires_in: lambda { |context|
167
- if context.scopes.exists?("public")
168
- 222
169
- elsif context.scopes.exists?("magic")
170
- Float::INFINITY
171
- end
172
- },
173
- )
174
- end
175
-
176
- before do
177
- allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
178
- end
179
-
180
- it "checks scopes" do
181
- subject = described_class.new(server, client, owner, scope: "public")
182
- allow(server).to receive(:scopes).and_return(Doorkeeper::OAuth::Scopes.from_string("public"))
183
-
184
- expect do
185
- subject.authorize
186
- end.to change { Doorkeeper::AccessToken.count }.by(1)
187
-
188
- expect(Doorkeeper::AccessToken.last.expires_in).to eq(222)
189
- end
190
-
191
- it "falls back to the default otherwise" do
192
- subject = described_class.new(server, client, owner, scope: "private")
193
- allow(server).to receive(:scopes).and_return(Doorkeeper::OAuth::Scopes.from_string("private"))
194
-
195
- expect do
196
- subject.authorize
197
- end.to change { Doorkeeper::AccessToken.count }.by(1)
198
-
199
- expect(Doorkeeper::AccessToken.last.expires_in).to eq(2.hours)
200
- end
201
- end
202
- end