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,744 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.describe Doorkeeper::AuthorizationsController do
6
- include AuthorizationRequestHelper
7
-
8
- class ActionDispatch::TestResponse
9
- def query_params
10
- @query_params ||= begin
11
- fragment = URI.parse(location).fragment
12
- Rack::Utils.parse_query(fragment)
13
- end
14
- end
15
- end
16
-
17
- let(:client) { FactoryBot.create :application }
18
- let(:user) { User.create!(name: "Joe", password: "sekret") }
19
-
20
- let(:access_token) do
21
- FactoryBot.build :access_token,
22
- resource_owner_id: user.id,
23
- resource_owner_type: user.class.name,
24
- application_id: client.id,
25
- scopes: "default"
26
- end
27
-
28
- before do
29
- Doorkeeper.configure do
30
- orm DOORKEEPER_ORM
31
- default_scopes :default
32
-
33
- custom_access_token_expires_in(lambda do |context|
34
- context.grant_type == Doorkeeper::OAuth::IMPLICIT ? 1234 : nil
35
- end)
36
- end
37
-
38
- allow(Doorkeeper.config).to receive(:grant_flows).and_return(["implicit"])
39
- allow(Doorkeeper.config).to receive(:authenticate_resource_owner).and_return(->(_) { authenticator_method })
40
- allow(controller).to receive(:authenticator_method).and_return(user)
41
- end
42
-
43
- describe "POST #create" do
44
- before do
45
- post :create, params: { client_id: client.uid, response_type: "token", redirect_uri: client.redirect_uri }
46
- end
47
-
48
- it "redirects after authorization" do
49
- expect(response).to be_redirect
50
- expect(controller).to receive(:authenticator_method).at_most(:once)
51
- end
52
-
53
- it "redirects to client redirect uri" do
54
- expect(response.location).to match(/^#{client.redirect_uri}/)
55
- end
56
-
57
- it "includes access token in fragment" do
58
- expect(response.query_params["access_token"]).to eq(Doorkeeper::AccessToken.first.token)
59
- end
60
-
61
- it "includes token type in fragment" do
62
- expect(response.query_params["token_type"]).to eq("Bearer")
63
- end
64
-
65
- it "includes token expiration in fragment" do
66
- expect(response.query_params["expires_in"].to_i).to eq(1234)
67
- end
68
-
69
- it "issues the token for the current client" do
70
- expect(Doorkeeper::AccessToken.first.application_id).to eq(client.id)
71
- end
72
-
73
- it "issues the token for the current resource owner" do
74
- expect(Doorkeeper::AccessToken.first.resource_owner_id).to eq(user.id)
75
- end
76
- end
77
-
78
- describe "POST #create in API mode" do
79
- before do
80
- allow(Doorkeeper.config).to receive(:api_only).and_return(true)
81
- post :create, params: { client_id: client.uid, response_type: "token", redirect_uri: client.redirect_uri }
82
- end
83
-
84
- let(:response_json_body) { JSON.parse(response.body) }
85
- let(:redirect_uri) { response_json_body["redirect_uri"] }
86
-
87
- it "renders success after authorization" do
88
- expect(response).to be_successful
89
- end
90
-
91
- it "renders correct redirect uri" do
92
- expect(redirect_uri).to match(/^#{client.redirect_uri}/)
93
- end
94
-
95
- it "includes access token in fragment" do
96
- expect(redirect_uri.match(/access_token=([a-zA-Z0-9\-_]+)&?/)[1]).to eq(Doorkeeper::AccessToken.first.token)
97
- end
98
-
99
- it "includes token type in fragment" do
100
- expect(redirect_uri.match(/token_type=(\w+)&?/)[1]).to eq "Bearer"
101
- end
102
-
103
- it "includes token expiration in fragment" do
104
- expect(redirect_uri.match(/expires_in=(\d+)&?/)[1].to_i).to eq 1234
105
- end
106
-
107
- it "issues the token for the current client" do
108
- expect(Doorkeeper::AccessToken.first.application_id).to eq(client.id)
109
- end
110
-
111
- it "issues the token for the current resource owner" do
112
- expect(Doorkeeper::AccessToken.first.resource_owner_id).to eq(user.id)
113
- end
114
- end
115
-
116
- describe "POST #create with errors" do
117
- context "when missing client_id" do
118
- before do
119
- post :create, params: {
120
- client_id: "",
121
- response_type: "token",
122
- redirect_uri: client.redirect_uri,
123
- }
124
- end
125
-
126
- let(:response_json_body) { JSON.parse(response.body) }
127
-
128
- it "renders 400 error" do
129
- expect(response.status).to eq 400
130
- end
131
-
132
- it "includes error name" do
133
- expect(response_json_body["error"]).to eq("invalid_request")
134
- end
135
-
136
- it "includes error description" do
137
- expect(response_json_body["error_description"]).to eq(
138
- translated_invalid_request_error_message(:missing_param, :client_id),
139
- )
140
- end
141
-
142
- it "does not issue any access token" do
143
- expect(Doorkeeper::AccessToken.all).to be_empty
144
- end
145
- end
146
-
147
- context "when user cannot access application" do
148
- before do
149
- allow(Doorkeeper.configuration).to receive(:authorize_resource_owner_for_client).and_return(->(*_) { false })
150
- post :create, params: {
151
- client_id: client.uid,
152
- response_type: "token",
153
- redirect_uri: client.redirect_uri,
154
- }
155
- end
156
-
157
- let(:response_json_body) { JSON.parse(response.body) }
158
-
159
- it "renders 400 error" do
160
- expect(response.status).to eq 401
161
- end
162
-
163
- it "includes error name" do
164
- expect(response_json_body["error"]).to eq("invalid_client")
165
- end
166
-
167
- it "includes error description" do
168
- expect(response_json_body["error_description"]).to eq(
169
- translated_error_message(:invalid_client),
170
- )
171
- end
172
-
173
- it "does not issue any access token" do
174
- expect(Doorkeeper::AccessToken.all).to be_empty
175
- end
176
- end
177
-
178
- context "when other error happens" do
179
- before do
180
- default_scopes_exist :public
181
-
182
- post :create, params: {
183
- client_id: client.uid,
184
- response_type: "token",
185
- scope: "invalid",
186
- redirect_uri: client.redirect_uri,
187
- }
188
- end
189
-
190
- it "redirects after authorization" do
191
- expect(response).to be_redirect
192
- end
193
-
194
- it "redirects to client redirect uri" do
195
- expect(response.location).to match(/^#{client.redirect_uri}/)
196
- end
197
-
198
- it "does not include access token in fragment" do
199
- expect(response.query_params["access_token"]).to be_nil
200
- end
201
-
202
- it "includes error in fragment" do
203
- expect(response.query_params["error"]).to eq("invalid_scope")
204
- end
205
-
206
- it "includes error description in fragment" do
207
- expect(response.query_params["error_description"]).to eq(translated_error_message(:invalid_scope))
208
- end
209
-
210
- it "does not issue any access token" do
211
- expect(Doorkeeper::AccessToken.all).to be_empty
212
- end
213
- end
214
- end
215
-
216
- describe "POST #create in API mode with errors" do
217
- context "when missing client_id" do
218
- before do
219
- allow(Doorkeeper.config).to receive(:api_only).and_return(true)
220
-
221
- post :create, params: {
222
- client_id: "",
223
- response_type: "token",
224
- redirect_uri: client.redirect_uri,
225
- }
226
- end
227
-
228
- let(:response_json_body) { JSON.parse(response.body) }
229
-
230
- it "renders 400 error" do
231
- expect(response.status).to eq 400
232
- end
233
-
234
- it "includes error name" do
235
- expect(response_json_body["error"]).to eq("invalid_request")
236
- end
237
-
238
- it "includes error description" do
239
- expect(response_json_body["error_description"]).to eq(
240
- translated_invalid_request_error_message(:missing_param, :client_id),
241
- )
242
- end
243
-
244
- it "does not issue any access token" do
245
- expect(Doorkeeper::AccessToken.all).to be_empty
246
- end
247
- end
248
-
249
- context "when user cannot access application" do
250
- before do
251
- allow(Doorkeeper.configuration).to receive(:api_only).and_return(true)
252
- allow(Doorkeeper.configuration).to receive(:authorize_resource_owner_for_client).and_return(->(*_) { false })
253
-
254
- post :create, params: {
255
- client_id: client.uid,
256
- response_type: "token",
257
- redirect_uri: client.redirect_uri,
258
- }
259
- end
260
-
261
- let(:response_json_body) { JSON.parse(response.body) }
262
-
263
- it "renders 400 error" do
264
- expect(response.status).to eq 401
265
- end
266
-
267
- it "includes error name" do
268
- expect(response_json_body["error"]).to eq("invalid_client")
269
- end
270
-
271
- it "includes error description" do
272
- expect(response_json_body["error_description"]).to eq(
273
- translated_error_message(:invalid_client),
274
- )
275
- end
276
-
277
- it "does not issue any access token" do
278
- expect(Doorkeeper::AccessToken.all).to be_empty
279
- end
280
- end
281
-
282
- context "when other error happens" do
283
- before do
284
- allow(Doorkeeper.config).to receive(:api_only).and_return(true)
285
- default_scopes_exist :public
286
-
287
- post :create, params: {
288
- client_id: client.uid,
289
- response_type: "token",
290
- scope: "invalid",
291
- redirect_uri: client.redirect_uri,
292
- }
293
- end
294
-
295
- let(:response_json_body) { JSON.parse(response.body) }
296
- let(:redirect_uri) { response_json_body["redirect_uri"] }
297
-
298
- it "renders 400 error" do
299
- expect(response.status).to eq 400
300
- end
301
-
302
- it "includes correct redirect URI" do
303
- expect(redirect_uri).to match(/^#{client.redirect_uri}/)
304
- end
305
-
306
- it "does not include access token in fragment" do
307
- expect(redirect_uri.match(/access_token=([a-f0-9]+)&?/)).to be_nil
308
- end
309
-
310
- it "includes error in redirect uri" do
311
- expect(redirect_uri.match(/error=([a-z_]+)&?/)[1]).to eq "invalid_scope"
312
- end
313
-
314
- it "includes error description in redirect uri" do
315
- expect(redirect_uri.match(/error_description=(.+)&?/)[1]).not_to be_nil
316
- end
317
-
318
- it "does not issue any access token" do
319
- expect(Doorkeeper::AccessToken.all).to be_empty
320
- end
321
- end
322
- end
323
-
324
- describe "POST #create with application already authorized" do
325
- before do
326
- allow(Doorkeeper.config).to receive(:reuse_access_token).and_return(true)
327
-
328
- access_token.save!
329
-
330
- post :create, params: {
331
- client_id: client.uid,
332
- response_type: "token",
333
- redirect_uri: client.redirect_uri,
334
- }
335
- end
336
-
337
- it "returns the existing access token in a fragment" do
338
- expect(response.query_params["access_token"]).to eq(access_token.token)
339
- end
340
-
341
- it "does not creates a new access token" do
342
- expect(Doorkeeper::AccessToken.count).to eq(1)
343
- end
344
- end
345
-
346
- describe "POST #create with callbacks" do
347
- after do
348
- client.update_attribute :redirect_uri, "urn:ietf:wg:oauth:2.0:oob"
349
- end
350
-
351
- describe "when successful" do
352
- after do
353
- post :create, params: {
354
- client_id: client.uid,
355
- response_type: "token",
356
- redirect_uri: client.redirect_uri,
357
- }
358
- end
359
-
360
- it "calls :before_successful_authorization callback" do
361
- expect(Doorkeeper.config)
362
- .to receive_message_chain(:before_successful_authorization, :call)
363
- .with(instance_of(described_class), instance_of(Doorkeeper::OAuth::Hooks::Context))
364
- end
365
-
366
- it "calls :after_successful_authorization callback" do
367
- expect(Doorkeeper.config)
368
- .to receive_message_chain(:after_successful_authorization, :call)
369
- .with(instance_of(described_class), instance_of(Doorkeeper::OAuth::Hooks::Context))
370
- end
371
- end
372
-
373
- describe "with errors" do
374
- after do
375
- post :create, params: { client_id: client.uid, response_type: "token", redirect_uri: "bad_uri" }
376
- end
377
-
378
- it "does not call :before_successful_authorization callback" do
379
- expect(Doorkeeper.config).not_to receive(:before_successful_authorization)
380
- end
381
-
382
- it "does not call :after_successful_authorization callback" do
383
- expect(Doorkeeper.config).not_to receive(:after_successful_authorization)
384
- end
385
- end
386
- end
387
-
388
- describe "GET #new token request with native url and skip_authorization true" do
389
- before do
390
- allow(Doorkeeper.config).to receive(:skip_authorization).and_return(proc do
391
- true
392
- end)
393
-
394
- client.update_attribute :redirect_uri, "urn:ietf:wg:oauth:2.0:oob"
395
-
396
- get :new, params: {
397
- client_id: client.uid,
398
- response_type: "token",
399
- redirect_uri: client.redirect_uri,
400
- }
401
- end
402
-
403
- it "redirects immediately" do
404
- expect(response).to be_redirect
405
- expect(response.location).to match(%r{/oauth/token/info\?access_token=})
406
- end
407
-
408
- it "does not issue a grant" do
409
- expect(Doorkeeper::AccessGrant.count).to be 0
410
- end
411
-
412
- it "issues a token" do
413
- expect(Doorkeeper::AccessToken.count).to be 1
414
- end
415
- end
416
-
417
- describe "GET #new code request with native url and skip_authorization true" do
418
- before do
419
- allow(Doorkeeper.config).to receive(:grant_flows).and_return(%w[authorization_code])
420
- allow(Doorkeeper.config).to receive(:skip_authorization).and_return(proc do
421
- true
422
- end)
423
-
424
- client.update_attribute :redirect_uri, "urn:ietf:wg:oauth:2.0:oob"
425
-
426
- get :new, params: {
427
- client_id: client.uid,
428
- response_type: "code",
429
- redirect_uri: client.redirect_uri,
430
- }
431
- end
432
-
433
- it "redirects immediately" do
434
- expect(response).to be_redirect
435
- expect(response.location)
436
- .to match(%r{/oauth/authorize/native\?code=#{Doorkeeper::AccessGrant.first.token}})
437
- end
438
-
439
- it "issues a grant" do
440
- expect(Doorkeeper::AccessGrant.count).to be 1
441
- end
442
-
443
- it "does not issue a token" do
444
- expect(Doorkeeper::AccessToken.count).to be 0
445
- end
446
- end
447
-
448
- describe "GET #new with skip_authorization true" do
449
- before do
450
- allow(Doorkeeper.config).to receive(:skip_authorization).and_return(proc do
451
- true
452
- end)
453
-
454
- get :new, params: {
455
- client_id: client.uid,
456
- response_type: "token",
457
- redirect_uri: client.redirect_uri,
458
- }
459
- end
460
-
461
- it "redirects immediately" do
462
- expect(response).to be_redirect
463
- expect(response.location).to match(/^#{client.redirect_uri}/)
464
- end
465
-
466
- it "issues a token" do
467
- expect(Doorkeeper::AccessToken.count).to be 1
468
- end
469
-
470
- it "includes token type in fragment" do
471
- expect(response.query_params["token_type"]).to eq("Bearer")
472
- end
473
-
474
- it "includes token expiration in fragment" do
475
- expect(response.query_params["expires_in"].to_i).to eq(1234)
476
- end
477
-
478
- it "issues the token for the current client" do
479
- expect(Doorkeeper::AccessToken.first.application_id).to eq(client.id)
480
- end
481
-
482
- it "issues the token for the current resource owner" do
483
- expect(Doorkeeper::AccessToken.first.resource_owner_id).to eq(user.id)
484
- end
485
- end
486
-
487
- describe "GET #new in API mode" do
488
- before do
489
- allow(Doorkeeper.config).to receive(:api_only).and_return(true)
490
-
491
- get :new, params: {
492
- client_id: client.uid,
493
- response_type: "token",
494
- redirect_uri: client.redirect_uri,
495
- }
496
- end
497
-
498
- it "renders success" do
499
- expect(response).to be_successful
500
- end
501
-
502
- it "sets status to pre-authorization" do
503
- expect(json_response["status"]).to eq(I18n.t("doorkeeper.pre_authorization.status"))
504
- end
505
-
506
- it "sets correct values" do
507
- expect(json_response["client_id"]).to eq(client.uid)
508
- expect(json_response["redirect_uri"]).to eq(client.redirect_uri)
509
- expect(json_response["state"]).to be_nil
510
- expect(json_response["response_type"]).to eq("token")
511
- expect(json_response["scope"]).to eq("default")
512
- end
513
- end
514
-
515
- describe "GET #new in API mode with skip_authorization true" do
516
- before do
517
- allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc { true })
518
- allow(Doorkeeper.configuration).to receive(:api_only).and_return(true)
519
-
520
- get :new, params: {
521
- client_id: client.uid,
522
- response_type: "token",
523
- redirect_uri: client.redirect_uri,
524
- }
525
- end
526
-
527
- it "renders success" do
528
- expect(response).to be_successful
529
- end
530
-
531
- it "issues a token" do
532
- expect(Doorkeeper::AccessToken.count).to be 1
533
- end
534
-
535
- it "sets status to redirect" do
536
- expect(JSON.parse(response.body)["status"]).to eq("redirect")
537
- end
538
-
539
- it "sets redirect_uri to correct value" do
540
- redirect_uri = JSON.parse(response.body)["redirect_uri"]
541
- expect(redirect_uri).not_to be_nil
542
- expect(redirect_uri.match(/token_type=(\w+)&?/)[1]).to eq "Bearer"
543
- expect(redirect_uri.match(/expires_in=(\d+)&?/)[1].to_i).to eq 1234
544
- expect(
545
- redirect_uri.match(/access_token=([a-zA-Z0-9\-_]+)&?/)[1],
546
- ).to eq Doorkeeper::AccessToken.first.token
547
- end
548
-
549
- it "issues the token for the current client" do
550
- expect(Doorkeeper::AccessToken.first.application_id).to eq(client.id)
551
- end
552
-
553
- it "issues the token for the current resource owner" do
554
- expect(Doorkeeper::AccessToken.first.resource_owner_id).to eq(user.id)
555
- end
556
- end
557
-
558
- describe "GET #new with errors" do
559
- context "without valid params" do
560
- before do
561
- default_scopes_exist :public
562
- get :new, params: { an_invalid: "request" }
563
- end
564
-
565
- it "does not redirect" do
566
- expect(response).not_to be_redirect
567
- end
568
-
569
- it "does not issue any token" do
570
- expect(Doorkeeper::AccessGrant.count).to eq 0
571
- expect(Doorkeeper::AccessToken.count).to eq 0
572
- end
573
- end
574
-
575
- context "when user cannot access application" do
576
- before do
577
- allow(Doorkeeper.configuration).to receive(:authorize_resource_owner_for_client).and_return(->(*_) { false })
578
-
579
- get :new, params: {
580
- client_id: client.uid,
581
- response_type: "token",
582
- redirect_uri: client.redirect_uri,
583
- }
584
- end
585
-
586
- it "does not redirect" do
587
- expect(response).not_to be_redirect
588
- end
589
-
590
- it "does not issue any token" do
591
- expect(Doorkeeper::AccessGrant.count).to eq 0
592
- expect(Doorkeeper::AccessToken.count).to eq 0
593
- end
594
- end
595
- end
596
-
597
- describe "GET #new in API mode with errors" do
598
- before do
599
- allow(Doorkeeper.configuration).to receive(:api_only).and_return(true)
600
- default_scopes_exist :public
601
- end
602
-
603
- context "without valid params" do
604
- before do
605
- get :new, params: { an_invalid: "request" }
606
- end
607
-
608
- let(:response_json_body) { JSON.parse(response.body) }
609
-
610
- it "renders bad request" do
611
- expect(response).to have_http_status(:bad_request)
612
- end
613
-
614
- it "includes error in body" do
615
- expect(response_json_body["error"]).to eq("invalid_request")
616
- end
617
-
618
- it "includes error description in body" do
619
- expect(response_json_body["error_description"])
620
- .to eq(translated_invalid_request_error_message(:missing_param, :client_id))
621
- end
622
-
623
- it "does not issue any token" do
624
- expect(Doorkeeper::AccessGrant.count).to eq 0
625
- expect(Doorkeeper::AccessToken.count).to eq 0
626
- end
627
- end
628
-
629
- context "when user cannot access application" do
630
- before do
631
- allow(Doorkeeper.configuration).to receive(:authorize_resource_owner_for_client).and_return(->(*_) { false })
632
-
633
- get :new, params: {
634
- client_id: client.uid,
635
- response_type: "token",
636
- redirect_uri: client.redirect_uri,
637
- }
638
- end
639
-
640
- let(:response_json_body) { JSON.parse(response.body) }
641
-
642
- it "renders bad request" do
643
- expect(response).to have_http_status(:bad_request)
644
- end
645
-
646
- it "includes error in body" do
647
- expect(response_json_body["error"]).to eq("invalid_client")
648
- end
649
-
650
- it "includes error description in body" do
651
- expect(response_json_body["error_description"])
652
- .to eq(translated_error_message(:invalid_client))
653
- end
654
-
655
- it "does not issue any token" do
656
- expect(Doorkeeper::AccessGrant.count).to eq 0
657
- expect(Doorkeeper::AccessToken.count).to eq 0
658
- end
659
- end
660
- end
661
-
662
- describe "GET #new with callbacks" do
663
- after do
664
- client.update_attribute :redirect_uri, "urn:ietf:wg:oauth:2.0:oob"
665
- get :new, params: { client_id: client.uid, response_type: "token", redirect_uri: client.redirect_uri }
666
- end
667
-
668
- describe "when authorizing" do
669
- before do
670
- allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc { true })
671
- end
672
-
673
- it "calls :before_successful_authorization callback" do
674
- expect(Doorkeeper.configuration)
675
- .to receive_message_chain(:before_successful_authorization, :call)
676
- .with(instance_of(described_class), instance_of(Doorkeeper::OAuth::Hooks::Context))
677
- end
678
-
679
- it "calls :after_successful_authorization callback" do
680
- expect(Doorkeeper.configuration)
681
- .to receive_message_chain(:after_successful_authorization, :call)
682
- .with(instance_of(described_class), instance_of(Doorkeeper::OAuth::Hooks::Context))
683
- end
684
- end
685
-
686
- describe "when not authorizing" do
687
- before do
688
- allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc { false })
689
- end
690
-
691
- it "does not call :before_successful_authorization callback" do
692
- expect(Doorkeeper.configuration).not_to receive(:before_successful_authorization)
693
- end
694
-
695
- it "does not call :after_successful_authorization callback" do
696
- expect(Doorkeeper.configuration).not_to receive(:after_successful_authorization)
697
- end
698
- end
699
-
700
- describe "when not authorizing in api mode" do
701
- before do
702
- allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc { false })
703
- allow(Doorkeeper.configuration).to receive(:api_only).and_return(true)
704
- end
705
-
706
- it "does not call :before_successful_authorization callback" do
707
- expect(Doorkeeper.configuration).not_to receive(:before_successful_authorization)
708
- end
709
-
710
- it "does not call :after_successful_authorization callback" do
711
- expect(Doorkeeper.configuration).not_to receive(:after_successful_authorization)
712
- end
713
- end
714
- end
715
-
716
- describe "authorize response memoization" do
717
- it "memoizes the result of the authorization" do
718
- pre_auth = double(:pre_auth, authorizable?: true)
719
- allow(controller).to receive(:pre_auth) { pre_auth }
720
- strategy = double(:strategy, authorize: true)
721
- expect(strategy).to receive(:authorize).once
722
- allow(controller).to receive(:strategy) { strategy }
723
- allow(controller).to receive(:create) do
724
- 2.times { controller.send :authorize_response }
725
- controller.render json: {}, status: :ok
726
- end
727
-
728
- post :create
729
- end
730
- end
731
-
732
- describe "strong parameters" do
733
- it "ignores non-scalar scope parameter" do
734
- get :new, params: {
735
- client_id: client.uid,
736
- response_type: "token",
737
- redirect_uri: client.redirect_uri,
738
- scope: { "0" => "profile" },
739
- }
740
-
741
- expect(response).to be_successful
742
- end
743
- end
744
- end