doorkeeper-mongodb 5.2.1 → 5.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -27
  3. data/lib/doorkeeper/orm/concerns/mongoid/ownership.rb +1 -1
  4. data/lib/doorkeeper/orm/concerns/mongoid/resource_ownerable.rb +1 -1
  5. data/lib/doorkeeper/orm/mongoid4.rb +18 -0
  6. data/lib/doorkeeper/orm/mongoid5.rb +18 -0
  7. data/lib/doorkeeper/orm/mongoid6.rb +18 -0
  8. data/lib/doorkeeper/orm/mongoid7.rb +18 -0
  9. data/lib/doorkeeper-mongodb/mixins/mongoid/access_grant_mixin.rb +7 -6
  10. data/lib/doorkeeper-mongodb/mixins/mongoid/access_token_mixin.rb +8 -5
  11. data/lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb +82 -5
  12. data/lib/doorkeeper-mongodb/mixins/mongoid/base_mixin.rb +0 -8
  13. data/lib/doorkeeper-mongodb/mixins/mongoid/json_serializable.rb +17 -0
  14. data/lib/doorkeeper-mongodb/version.rb +1 -1
  15. data/lib/doorkeeper-mongodb.rb +1 -0
  16. data/spec/controllers/application_metal_controller_spec.rb +4 -4
  17. data/spec/controllers/applications_controller_spec.rb +198 -202
  18. data/spec/controllers/authorizations_controller_spec.rb +32 -31
  19. data/spec/controllers/protected_resources_controller_spec.rb +10 -10
  20. data/spec/controllers/token_info_controller_spec.rb +1 -1
  21. data/spec/controllers/tokens_controller_spec.rb +105 -62
  22. data/spec/doorkeeper/redirect_uri_validator_spec.rb +183 -0
  23. data/spec/{lib → doorkeeper}/server_spec.rb +5 -4
  24. data/spec/{lib → doorkeeper}/stale_records_cleaner_spec.rb +8 -7
  25. data/spec/{version → doorkeeper}/version_spec.rb +3 -3
  26. data/spec/dummy/app/assets/config/manifest.js +0 -0
  27. data/spec/dummy/app/controllers/application_controller.rb +0 -0
  28. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +0 -0
  29. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +0 -0
  30. data/spec/dummy/app/controllers/home_controller.rb +0 -0
  31. data/spec/dummy/app/controllers/metal_controller.rb +0 -0
  32. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +0 -0
  33. data/spec/dummy/app/helpers/application_helper.rb +0 -0
  34. data/spec/dummy/app/models/user.rb +0 -1
  35. data/spec/dummy/app/views/home/index.html.erb +0 -0
  36. data/spec/dummy/app/views/layouts/application.html.erb +0 -0
  37. data/spec/dummy/config/application.rb +0 -0
  38. data/spec/dummy/config/boot.rb +0 -0
  39. data/spec/dummy/config/database.yml +0 -0
  40. data/spec/dummy/config/environment.rb +0 -0
  41. data/spec/dummy/config/environments/development.rb +0 -0
  42. data/spec/dummy/config/environments/production.rb +0 -0
  43. data/spec/dummy/config/environments/test.rb +0 -0
  44. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -0
  45. data/spec/dummy/config/initializers/doorkeeper.rb +0 -0
  46. data/spec/dummy/config/initializers/secret_token.rb +0 -0
  47. data/spec/dummy/config/initializers/session_store.rb +0 -0
  48. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -0
  49. data/spec/dummy/config/locales/doorkeeper.en.yml +0 -0
  50. data/spec/dummy/config/mongo.yml +2 -2
  51. data/spec/dummy/config/routes.rb +0 -0
  52. data/spec/dummy/config.ru +0 -0
  53. data/spec/dummy/db/migrate/20111122132257_create_users.rb +0 -0
  54. data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +0 -0
  55. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +0 -0
  56. data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +0 -0
  57. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +0 -0
  58. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +0 -0
  59. data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +0 -0
  60. data/spec/dummy/db/schema.rb +0 -0
  61. data/spec/dummy/public/404.html +0 -0
  62. data/spec/dummy/public/422.html +0 -0
  63. data/spec/dummy/public/500.html +0 -0
  64. data/spec/dummy/public/favicon.ico +0 -0
  65. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/-o/-ofn45zIfO5vx4VD6m6NXesLf6da5usA-Sbw2SVju3o.cache +0 -0
  66. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/0_/0_ouGcG_o_1zmVmBe-tdQYk594LBwVa1bumjrKtdfEw.cache +0 -0
  67. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/2X/2XMMcHbyTSRqh1GkV0xzyIETNtt-zgN6iniziShaKmQ.cache +0 -0
  68. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/4Q/4QQw-pMQ98JIj3xdcFhGBQdysdGPY9rWffRqWMmyjew.cache +0 -0
  69. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/7H/7HjRsym0tTpXFCVhWt6kteMs_-CozKVbr9s5syHm8es.cache +0 -0
  70. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8B/8BxJyv22HPFHu1se_l2J8qW1N9NzZ16UOWOy1YMSgs4.cache +0 -0
  71. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8D/8DJG7JfPvShfLLyeSom6NZ_TcQc6QH27tJ7prEWZPfI.cache +0 -0
  72. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/9x/9xjtGv-yKjj62x9uFwBZg8pTSh9ERPAgANwNo9uwIaA.cache +0 -0
  73. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Bt/BtXO7f0PZ8DNt3TMLYM-zY7LkbWa_KgyB0v1V98M1CQ.cache +0 -0
  74. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/E0/E02f1Q2tutWumMulGCFNfqQNjvEP_hMAK_5E83eWepI.cache +0 -0
  75. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/EZ/EZGpd6pUEJZxO6uT2yIS4Fpn5KX7VDgC9VB3AaemF5Q.cache +0 -0
  76. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/FJ/FJlQpfMtpRbrM5P8A7d2FAelFKwo6GrVs2xks8z5GKU.cache +0 -0
  77. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/L8/L8mOWakJlWKr6MU85rj0V7yGFfNyIR6vE6YXtqArPGw.cache +0 -0
  78. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Lk/LklIq5hrBAPESXVUpFMwQ9L-1qTj90sPVi6U19_Xi-Q.cache +0 -0
  79. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/MB/MBWRxa9S470ee8suxVKp0jYgv6K6FQOqKGV0kPGQNMs.cache +0 -0
  80. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ma/MaK3K1AoZZ4xM5fOOifhROd73hfZJpP4yGbkGdoYtEk.cache +0 -0
  81. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/PA/PAH_jI20wRw12tngeJ-V619c30avNLDu5U9Z-9Pc5SQ.cache +0 -0
  82. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ph/Ph7RtH_NvG2I8XpTa8mA8SBQXZDzBPVIh4CH6g7OXJ0.cache +0 -0
  83. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{eS/eSL1QMz46gKLM0GR6S9fL6uyARPxOImcappZ9_ZtSyg.cache → Pm/PmheG0PGFqDws1qgFOxOyIL-gpMof3Ar9eSRKVLYuik.cache} +0 -0
  84. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Pn/PnXU_mkG2fLZFm9BwiZ03BZdBTjKuInP-cRXjHS7yJo.cache +0 -0
  85. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Qs/QsVgO6vM5Yn9oeYTYlrqtyVnK6sdVDWDa083N7zpfHw.cache +0 -0
  86. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/So/So59ksdx2dw-_A3-zFZ6Palr7fROjm7_0JDZb04temw.cache +0 -0
  87. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Wt/WtXL_iDofLeTH_v0Yf3PM421r9b1V0g-VBvMPeu9KA0.cache +0 -0
  88. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/b6/b6QRH6ZdCc0e6bUWu4qni_kZmptaMgWciO8Jl9q6_p8.cache +0 -0
  89. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/dX/dX6FDdUIy8yBCOoaoXcjf71rX9N_bpiXGJ4Urt32NTk.cache +0 -0
  90. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/jC/jCTZ1jAldKBn4OTANBBmCKzxLrDgok1ur4meoTqlDNg.cache +0 -0
  91. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/qT/qTQIQsmS0Wbbg2JxNn9rxdI5qVOTg5SfyQdaTvr9vLo.cache +0 -0
  92. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/yN/yNOFGOsnHmxXNMkuEAWuL1u3jlmdvrdeoTx6DDJ1in8.cache +0 -0
  93. data/spec/factories.rb +0 -0
  94. data/spec/grape/grape_integration_spec.rb +1 -1
  95. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
  96. data/spec/lib/config_spec.rb +23 -12
  97. data/spec/lib/doorkeeper_spec.rb +4 -4
  98. data/spec/lib/models/expirable_spec.rb +9 -9
  99. data/spec/lib/models/reusable_spec.rb +2 -2
  100. data/spec/lib/models/revocable_spec.rb +4 -7
  101. data/spec/lib/models/scopes_spec.rb +7 -7
  102. data/spec/lib/models/secret_storable_spec.rb +9 -8
  103. data/spec/lib/oauth/authorization/uri_builder_spec.rb +23 -27
  104. data/spec/lib/oauth/authorization_code_request_spec.rb +6 -6
  105. data/spec/lib/oauth/base_request_spec.rb +11 -27
  106. data/spec/lib/oauth/base_response_spec.rb +2 -2
  107. data/spec/lib/oauth/client/credentials_spec.rb +25 -25
  108. data/spec/lib/oauth/client_credentials/creator_spec.rb +89 -91
  109. data/spec/lib/oauth/client_credentials/issuer_spec.rb +84 -86
  110. data/spec/lib/oauth/client_credentials/validation_spec.rb +72 -39
  111. data/spec/lib/oauth/client_credentials_integration_spec.rb +5 -5
  112. data/spec/lib/oauth/client_credentials_request_spec.rb +7 -10
  113. data/spec/lib/oauth/client_spec.rb +8 -8
  114. data/spec/lib/oauth/code_request_spec.rb +5 -5
  115. data/spec/lib/oauth/code_response_spec.rb +4 -4
  116. data/spec/lib/oauth/error_response_spec.rb +6 -5
  117. data/spec/lib/oauth/error_spec.rb +1 -1
  118. data/spec/lib/oauth/forbidden_token_response_spec.rb +2 -2
  119. data/spec/lib/oauth/helpers/scope_checker_spec.rb +37 -37
  120. data/spec/lib/oauth/helpers/unique_token_spec.rb +2 -2
  121. data/spec/lib/oauth/helpers/uri_checker_spec.rb +54 -54
  122. data/spec/lib/oauth/invalid_request_response_spec.rb +6 -6
  123. data/spec/lib/oauth/invalid_token_response_spec.rb +4 -4
  124. data/spec/lib/oauth/password_access_token_request_spec.rb +10 -9
  125. data/spec/lib/oauth/pre_authorization_spec.rb +20 -8
  126. data/spec/lib/oauth/refresh_token_request_spec.rb +10 -10
  127. data/spec/lib/oauth/scopes_spec.rb +14 -14
  128. data/spec/lib/oauth/token_request_spec.rb +9 -9
  129. data/spec/lib/oauth/token_response_spec.rb +5 -5
  130. data/spec/lib/oauth/token_spec.rb +5 -5
  131. data/spec/lib/option_spec.rb +1 -1
  132. data/spec/lib/request/strategy_spec.rb +34 -37
  133. data/spec/lib/secret_storing/base_spec.rb +3 -2
  134. data/spec/lib/secret_storing/bcrypt_spec.rb +2 -1
  135. data/spec/lib/secret_storing/plain_spec.rb +2 -1
  136. data/spec/lib/secret_storing/sha256_hash_spec.rb +2 -1
  137. data/spec/models/doorkeeper/access_grant_spec.rb +7 -9
  138. data/spec/models/doorkeeper/access_token_spec.rb +20 -26
  139. data/spec/models/doorkeeper/application_spec.rb +83 -26
  140. data/spec/requests/applications/applications_request_spec.rb +91 -93
  141. data/spec/requests/applications/authorized_applications_spec.rb +0 -0
  142. data/spec/requests/endpoints/authorization_spec.rb +1 -1
  143. data/spec/requests/endpoints/token_spec.rb +22 -16
  144. data/spec/requests/flows/authorization_code_errors_spec.rb +12 -8
  145. data/spec/requests/flows/authorization_code_spec.rb +108 -79
  146. data/spec/requests/flows/client_credentials_spec.rb +57 -45
  147. data/spec/requests/flows/implicit_grant_errors_spec.rb +0 -0
  148. data/spec/requests/flows/implicit_grant_spec.rb +4 -4
  149. data/spec/requests/flows/password_spec.rb +253 -213
  150. data/spec/requests/flows/refresh_token_spec.rb +53 -39
  151. data/spec/requests/flows/revoke_token_spec.rb +24 -24
  152. data/spec/requests/flows/skip_authorization_spec.rb +1 -1
  153. data/spec/requests/protected_resources/metal_spec.rb +2 -2
  154. data/spec/requests/protected_resources/private_api_spec.rb +0 -0
  155. data/spec/routing/custom_controller_routes_spec.rb +1 -1
  156. data/spec/routing/default_routes_spec.rb +1 -1
  157. data/spec/routing/scoped_routes_spec.rb +1 -1
  158. data/spec/spec_helper.rb +0 -0
  159. data/spec/spec_helper_integration.rb +0 -0
  160. data/spec/support/dependencies/factory_bot.rb +0 -0
  161. data/spec/support/doorkeeper_rspec.rb +0 -0
  162. data/spec/support/helpers/access_token_request_helper.rb +0 -0
  163. data/spec/support/helpers/authorization_request_helper.rb +0 -0
  164. data/spec/support/helpers/config_helper.rb +0 -0
  165. data/spec/support/helpers/model_helper.rb +0 -0
  166. data/spec/support/helpers/request_spec_helper.rb +1 -13
  167. data/spec/support/helpers/url_helper.rb +2 -2
  168. data/spec/support/orm/active_record.rb +0 -0
  169. data/spec/support/orm/mongoid4.rb +1 -1
  170. data/spec/support/orm/mongoid5.rb +1 -1
  171. data/spec/support/orm/mongoid6.rb +1 -1
  172. data/spec/support/orm/mongoid7.rb +1 -1
  173. data/spec/support/shared/controllers_shared_context.rb +5 -38
  174. data/spec/support/shared/hashing_shared_context.rb +4 -0
  175. data/spec/support/shared/models_shared_examples.rb +6 -6
  176. metadata +154 -167
  177. data/spec/dummy/log/test.log +0 -6108
@@ -8,31 +8,31 @@ module Doorkeeper::OAuth::Helpers
8
8
 
9
9
  it "is valid if scope is present" do
10
10
  server_scopes.add :scope
11
- expect(ScopeChecker.valid?(scope_str: "scope", server_scopes: server_scopes)).to be_truthy
11
+ expect(described_class).to be_valid(scope_str: "scope", server_scopes: server_scopes)
12
12
  end
13
13
 
14
14
  it "is invalid if includes tabs space" do
15
- expect(ScopeChecker.valid?(scope_str: "\tsomething", server_scopes: server_scopes)).to be_falsey
15
+ expect(described_class).not_to be_valid(scope_str: "\tsomething", server_scopes: server_scopes)
16
16
  end
17
17
 
18
18
  it "is invalid if scope is not present" do
19
- expect(ScopeChecker.valid?(scope_str: nil, server_scopes: server_scopes)).to be_falsey
19
+ expect(described_class).not_to be_valid(scope_str: nil, server_scopes: server_scopes)
20
20
  end
21
21
 
22
22
  it "is invalid if scope is blank" do
23
- expect(ScopeChecker.valid?(scope_str: " ", server_scopes: server_scopes)).to be_falsey
23
+ expect(described_class).not_to be_valid(scope_str: " ", server_scopes: server_scopes)
24
24
  end
25
25
 
26
26
  it "is invalid if includes return space" do
27
- expect(ScopeChecker.valid?(scope_str: "scope\r", server_scopes: server_scopes)).to be_falsey
27
+ expect(described_class).not_to be_valid(scope_str: "scope\r", server_scopes: server_scopes)
28
28
  end
29
29
 
30
30
  it "is invalid if includes new lines" do
31
- expect(ScopeChecker.valid?(scope_str: "scope\nanother", server_scopes: server_scopes)).to be_falsey
31
+ expect(described_class).not_to be_valid(scope_str: "scope\nanother", server_scopes: server_scopes)
32
32
  end
33
33
 
34
34
  it "is invalid if any scope is not included in server scopes" do
35
- expect(ScopeChecker.valid?(scope_str: "scope another", server_scopes: server_scopes)).to be_falsey
35
+ expect(described_class).not_to be_valid(scope_str: "scope another", server_scopes: server_scopes)
36
36
  end
37
37
 
38
38
  context "with application_scopes" do
@@ -44,19 +44,19 @@ module Doorkeeper::OAuth::Helpers
44
44
  end
45
45
 
46
46
  it "is valid if scope is included in the application scope list" do
47
- expect(ScopeChecker.valid?(
48
- scope_str: "app123",
49
- server_scopes: server_scopes,
50
- app_scopes: application_scopes,
51
- )).to be_truthy
47
+ expect(described_class).to be_valid(
48
+ scope_str: "app123",
49
+ server_scopes: server_scopes,
50
+ app_scopes: application_scopes,
51
+ )
52
52
  end
53
53
 
54
54
  it "is invalid if any scope is not included in the application" do
55
- expect(ScopeChecker.valid?(
56
- scope_str: "svr",
57
- server_scopes: server_scopes,
58
- app_scopes: application_scopes,
59
- )).to be_falsey
55
+ expect(described_class).not_to be_valid(
56
+ scope_str: "svr",
57
+ server_scopes: server_scopes,
58
+ app_scopes: application_scopes,
59
+ )
60
60
  end
61
61
  end
62
62
 
@@ -67,19 +67,19 @@ module Doorkeeper::OAuth::Helpers
67
67
 
68
68
  context "with scopes_by_grant_type not configured for grant_type" do
69
69
  it "is valid if the scope is in server scopes" do
70
- expect(ScopeChecker.valid?(
71
- scope_str: "scope1",
72
- server_scopes: server_scopes,
73
- grant_type: Doorkeeper::OAuth::PASSWORD,
74
- )).to be_truthy
70
+ expect(described_class).to be_valid(
71
+ scope_str: "scope1",
72
+ server_scopes: server_scopes,
73
+ grant_type: Doorkeeper::OAuth::PASSWORD,
74
+ )
75
75
  end
76
76
 
77
77
  it "is invalid if the scope is not in server scopes" do
78
- expect(ScopeChecker.valid?(
79
- scope_str: "unknown",
80
- server_scopes: server_scopes,
81
- grant_type: Doorkeeper::OAuth::PASSWORD,
82
- )).to be_falsey
78
+ expect(described_class).not_to be_valid(
79
+ scope_str: "unknown",
80
+ server_scopes: server_scopes,
81
+ grant_type: Doorkeeper::OAuth::PASSWORD,
82
+ )
83
83
  end
84
84
  end
85
85
 
@@ -90,19 +90,19 @@ module Doorkeeper::OAuth::Helpers
90
90
  end
91
91
 
92
92
  it "is valid if the scope is permitted for grant_type" do
93
- expect(ScopeChecker.valid?(
94
- scope_str: "scope1",
95
- server_scopes: server_scopes,
96
- grant_type: Doorkeeper::OAuth::PASSWORD,
97
- )).to be_truthy
93
+ expect(described_class).to be_valid(
94
+ scope_str: "scope1",
95
+ server_scopes: server_scopes,
96
+ grant_type: Doorkeeper::OAuth::PASSWORD,
97
+ )
98
98
  end
99
99
 
100
100
  it "is invalid if the scope is permitted for grant_type" do
101
- expect(ScopeChecker.valid?(
102
- scope_str: "scope2",
103
- server_scopes: server_scopes,
104
- grant_type: Doorkeeper::OAuth::PASSWORD,
105
- )).to be_falsey
101
+ expect(described_class).not_to be_valid(
102
+ scope_str: "scope2",
103
+ server_scopes: server_scopes,
104
+ grant_type: Doorkeeper::OAuth::PASSWORD,
105
+ )
106
106
  end
107
107
  end
108
108
  end
@@ -9,12 +9,12 @@ module Doorkeeper::OAuth::Helpers
9
9
  end
10
10
 
11
11
  it "is able to customize the generator method" do
12
- token = UniqueToken.generate(generator: generator)
12
+ token = described_class.generate(generator: generator)
13
13
  expect(token).to eq("a" * 32)
14
14
  end
15
15
 
16
16
  it "is able to customize the size of the token" do
17
- token = UniqueToken.generate(generator: generator, size: 2)
17
+ token = described_class.generate(generator: generator, size: 2)
18
18
  expect(token).to eq("aa")
19
19
  end
20
20
  end
@@ -7,142 +7,142 @@ module Doorkeeper::OAuth::Helpers
7
7
  describe ".valid?" do
8
8
  it "is valid for valid uris" do
9
9
  uri = "http://app.co"
10
- expect(URIChecker.valid?(uri)).to be_truthy
10
+ expect(described_class).to be_valid(uri)
11
11
  end
12
12
 
13
13
  it "is valid if include path param" do
14
14
  uri = "http://app.co/path"
15
- expect(URIChecker.valid?(uri)).to be_truthy
15
+ expect(described_class).to be_valid(uri)
16
16
  end
17
17
 
18
18
  it "is valid if include query param" do
19
19
  uri = "http://app.co/?query=1"
20
- expect(URIChecker.valid?(uri)).to be_truthy
20
+ expect(described_class).to be_valid(uri)
21
21
  end
22
22
 
23
23
  it "is invalid if uri includes fragment" do
24
24
  uri = "http://app.co/test#fragment"
25
- expect(URIChecker.valid?(uri)).to be_falsey
25
+ expect(described_class).not_to be_valid(uri)
26
26
  end
27
27
 
28
28
  it "is invalid if scheme is missing" do
29
29
  uri = "app.co"
30
- expect(URIChecker.valid?(uri)).to be_falsey
30
+ expect(described_class).not_to be_valid(uri)
31
31
  end
32
32
 
33
33
  it "is invalid if is a relative uri" do
34
34
  uri = "/abc/123"
35
- expect(URIChecker.valid?(uri)).to be_falsey
35
+ expect(described_class).not_to be_valid(uri)
36
36
  end
37
37
 
38
38
  it "is invalid if is not a url" do
39
39
  uri = "http://"
40
- expect(URIChecker.valid?(uri)).to be_falsey
40
+ expect(described_class).not_to be_valid(uri)
41
41
  end
42
42
 
43
43
  it "is invalid if localhost is resolved as as scheme (no scheme specified)" do
44
44
  uri = "localhost:8080"
45
- expect(URIChecker.valid?(uri)).to be_falsey
45
+ expect(described_class).not_to be_valid(uri)
46
46
  end
47
47
 
48
48
  it "is invalid if scheme is missing #2" do
49
49
  uri = "app.co:80"
50
- expect(URIChecker.valid?(uri)).to be_falsey
50
+ expect(described_class).not_to be_valid(uri)
51
51
  end
52
52
 
53
53
  it "is invalid if is not an uri" do
54
54
  uri = " "
55
- expect(URIChecker.valid?(uri)).to be_falsey
55
+ expect(described_class).not_to be_valid(uri)
56
56
  end
57
57
 
58
58
  it "is valid for custom schemes" do
59
59
  uri = "com.example.app:/test"
60
- expect(URIChecker.valid?(uri)).to be_truthy
60
+ expect(described_class).to be_valid(uri)
61
61
  end
62
62
 
63
63
  it "is valid for custom schemes with authority marker (common misconfiguration)" do
64
64
  uri = "com.example.app://test"
65
- expect(URIChecker.valid?(uri)).to be_truthy
65
+ expect(described_class).to be_valid(uri)
66
66
  end
67
67
  end
68
68
 
69
69
  describe ".matches?" do
70
70
  it "is true if both url matches" do
71
71
  uri = client_uri = "http://app.co/aaa"
72
- expect(URIChecker.matches?(uri, client_uri)).to be_truthy
72
+ expect(described_class).to be_matches(uri, client_uri)
73
73
  end
74
74
 
75
- it "ignores query parameter on comparsion" do
75
+ it "ignores query parameter on comparison" do
76
76
  uri = "http://app.co/?query=hello"
77
77
  client_uri = "http://app.co"
78
- expect(URIChecker.matches?(uri, client_uri)).to be_truthy
78
+ expect(described_class).to be_matches(uri, client_uri)
79
79
  end
80
80
 
81
81
  it "doesn't allow non-matching domains through" do
82
82
  uri = "http://app.abc/?query=hello"
83
83
  client_uri = "http://app.co"
84
- expect(URIChecker.matches?(uri, client_uri)).to be_falsey
84
+ expect(described_class).not_to be_matches(uri, client_uri)
85
85
  end
86
86
 
87
87
  it "doesn't allow non-matching domains that don't start at the beginning" do
88
88
  uri = "http://app.co/?query=hello"
89
89
  client_uri = "http://example.com?app.co=test"
90
- expect(URIChecker.matches?(uri, client_uri)).to be_falsey
90
+ expect(described_class).not_to be_matches(uri, client_uri)
91
91
  end
92
92
 
93
- context "loopback IP redirect URIs" do
93
+ context "when loopback IP redirect URIs" do
94
94
  it "ignores port for same URIs" do
95
95
  uri = "http://127.0.0.1:5555/auth/callback"
96
96
  client_uri = "http://127.0.0.1:48599/auth/callback"
97
- expect(URIChecker.matches?(uri, client_uri)).to be_truthy
97
+ expect(described_class).to be_matches(uri, client_uri)
98
98
 
99
99
  uri = "http://[::1]:5555/auth/callback"
100
100
  client_uri = "http://[::1]:5555/auth/callback"
101
- expect(URIChecker.matches?(uri, client_uri)).to be_truthy
101
+ expect(described_class).to be_matches(uri, client_uri)
102
102
  end
103
103
 
104
104
  it "doesn't ignore port for URIs with different queries" do
105
105
  uri = "http://127.0.0.1:5555/auth/callback"
106
106
  client_uri = "http://127.0.0.1:48599/auth/callback2"
107
- expect(URIChecker.matches?(uri, client_uri)).to be_falsey
107
+ expect(described_class).not_to be_matches(uri, client_uri)
108
108
  end
109
109
  end
110
110
 
111
- context "client registered query params" do
111
+ context "when client registered query params" do
112
112
  it "doesn't allow query being absent" do
113
113
  uri = "http://app.co"
114
114
  client_uri = "http://app.co/?vendorId=AJ4L7XXW9"
115
- expect(URIChecker.matches?(uri, client_uri)).to be_falsey
115
+ expect(described_class).not_to be_matches(uri, client_uri)
116
116
  end
117
117
 
118
118
  it "is false if query values differ but key same" do
119
119
  uri = "http://app.co/?vendorId=pancakes"
120
120
  client_uri = "http://app.co/?vendorId=waffles"
121
- expect(URIChecker.matches?(uri, client_uri)).to be_falsey
121
+ expect(described_class).not_to be_matches(uri, client_uri)
122
122
  end
123
123
 
124
124
  it "is false if query values same but key differs" do
125
125
  uri = "http://app.co/?foo=pancakes"
126
126
  client_uri = "http://app.co/?bar=pancakes"
127
- expect(URIChecker.matches?(uri, client_uri)).to be_falsey
127
+ expect(described_class).not_to be_matches(uri, client_uri)
128
128
  end
129
129
 
130
130
  it "is false if query present and match, but unknown queries present" do
131
131
  uri = "http://app.co/?vendorId=pancakes&unknown=query"
132
132
  client_uri = "http://app.co/?vendorId=waffles"
133
- expect(URIChecker.matches?(uri, client_uri)).to be_falsey
133
+ expect(described_class).not_to be_matches(uri, client_uri)
134
134
  end
135
135
 
136
136
  it "is true if queries are present and matche" do
137
137
  uri = "http://app.co/?vendorId=AJ4L7XXW9&foo=bar"
138
138
  client_uri = "http://app.co/?vendorId=AJ4L7XXW9&foo=bar"
139
- expect(URIChecker.matches?(uri, client_uri)).to be_truthy
139
+ expect(described_class).to be_matches(uri, client_uri)
140
140
  end
141
141
 
142
142
  it "is true if queries are present, match and in different order" do
143
143
  uri = "http://app.co/?bing=bang&foo=bar"
144
144
  client_uri = "http://app.co/?foo=bar&bing=bang"
145
- expect(URIChecker.matches?(uri, client_uri)).to be_truthy
145
+ expect(described_class).to be_matches(uri, client_uri)
146
146
  end
147
147
  end
148
148
  end
@@ -150,112 +150,112 @@ module Doorkeeper::OAuth::Helpers
150
150
  describe ".valid_for_authorization?" do
151
151
  it "is true if valid and matches" do
152
152
  uri = client_uri = "http://app.co/aaa"
153
- expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be_truthy
153
+ expect(described_class).to be_valid_for_authorization(uri, client_uri)
154
154
 
155
155
  uri = client_uri = "http://app.co/aaa?b=c"
156
- expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be_truthy
156
+ expect(described_class).to be_valid_for_authorization(uri, client_uri)
157
157
  end
158
158
 
159
159
  it "is true if uri includes blank query" do
160
160
  uri = client_uri = "http://app.co/aaa?"
161
- expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be_truthy
161
+ expect(described_class).to be_valid_for_authorization(uri, client_uri)
162
162
 
163
163
  uri = "http://app.co/aaa?"
164
164
  client_uri = "http://app.co/aaa"
165
- expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be_truthy
165
+ expect(described_class).to be_valid_for_authorization(uri, client_uri)
166
166
 
167
167
  uri = "http://app.co/aaa"
168
168
  client_uri = "http://app.co/aaa?"
169
- expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be_truthy
169
+ expect(described_class).to be_valid_for_authorization(uri, client_uri)
170
170
  end
171
171
 
172
172
  it "is false if valid and mismatches" do
173
173
  uri = "http://app.co/aaa"
174
174
  client_uri = "http://app.co/bbb"
175
- expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be_falsey
175
+ expect(described_class).not_to be_valid_for_authorization(uri, client_uri)
176
176
  end
177
177
 
178
178
  it "is true if valid and included in array" do
179
179
  uri = "http://app.co/aaa"
180
180
  client_uri = "http://example.com/bbb\nhttp://app.co/aaa"
181
- expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be_truthy
181
+ expect(described_class).to be_valid_for_authorization(uri, client_uri)
182
182
  end
183
183
 
184
184
  it "is false if valid and not included in array" do
185
185
  uri = "http://app.co/aaa"
186
186
  client_uri = "http://example.com/bbb\nhttp://app.co/cc"
187
- expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be_falsey
187
+ expect(described_class).not_to be_valid_for_authorization(uri, client_uri)
188
188
  end
189
189
 
190
190
  it "is false if queries does not match" do
191
191
  uri = "http://app.co/aaa?pankcakes=abc"
192
192
  client_uri = "http://app.co/aaa?waffles=abc"
193
- expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be false
193
+ expect(described_class.valid_for_authorization?(uri, client_uri)).to be false
194
194
  end
195
195
 
196
196
  it "calls .matches?" do
197
197
  uri = "http://app.co/aaa?pankcakes=abc"
198
198
  client_uri = "http://app.co/aaa?waffles=abc"
199
- expect(URIChecker).to receive(:matches?).with(uri, client_uri).once
200
- URIChecker.valid_for_authorization?(uri, client_uri)
199
+ expect(described_class).to receive(:matches?).with(uri, client_uri).once
200
+ described_class.valid_for_authorization?(uri, client_uri)
201
201
  end
202
202
 
203
203
  it "calls .valid?" do
204
204
  uri = "http://app.co/aaa?pankcakes=abc"
205
205
  client_uri = "http://app.co/aaa?waffles=abc"
206
- expect(URIChecker).to receive(:valid?).with(uri).once
207
- URIChecker.valid_for_authorization?(uri, client_uri)
206
+ expect(described_class).to receive(:valid?).with(uri).once
207
+ described_class.valid_for_authorization?(uri, client_uri)
208
208
  end
209
209
  end
210
210
 
211
211
  describe ".query_matches?" do
212
212
  it "is true if no queries" do
213
- expect(URIChecker.query_matches?("", "")).to be_truthy
214
- expect(URIChecker.query_matches?(nil, nil)).to be_truthy
213
+ expect(described_class).to be_query_matches("", "")
214
+ expect(described_class).to be_query_matches(nil, nil)
215
215
  end
216
216
 
217
217
  it "is true if same query" do
218
- expect(URIChecker.query_matches?("foo", "foo")).to be_truthy
218
+ expect(described_class).to be_query_matches("foo", "foo")
219
219
  end
220
220
 
221
221
  it "is false if different query" do
222
- expect(URIChecker.query_matches?("foo", "bar")).to be_falsey
222
+ expect(described_class).not_to be_query_matches("foo", "bar")
223
223
  end
224
224
 
225
225
  it "is true if same queries" do
226
- expect(URIChecker.query_matches?("foo&bar", "foo&bar")).to be_truthy
226
+ expect(described_class).to be_query_matches("foo&bar", "foo&bar")
227
227
  end
228
228
 
229
229
  it "is true if same queries, different order" do
230
- expect(URIChecker.query_matches?("foo&bar", "bar&foo")).to be_truthy
230
+ expect(described_class).to be_query_matches("foo&bar", "bar&foo")
231
231
  end
232
232
 
233
233
  it "is false if one different query" do
234
- expect(URIChecker.query_matches?("foo&bang", "foo&bing")).to be_falsey
234
+ expect(described_class).not_to be_query_matches("foo&bang", "foo&bing")
235
235
  end
236
236
 
237
237
  it "is true if same query with same value" do
238
- expect(URIChecker.query_matches?("foo=bar", "foo=bar")).to be_truthy
238
+ expect(described_class).to be_query_matches("foo=bar", "foo=bar")
239
239
  end
240
240
 
241
241
  it "is true if same queries with same values" do
242
- expect(URIChecker.query_matches?("foo=bar&bing=bang", "foo=bar&bing=bang")).to be_truthy
242
+ expect(described_class).to be_query_matches("foo=bar&bing=bang", "foo=bar&bing=bang")
243
243
  end
244
244
 
245
245
  it "is true if same queries with same values, different order" do
246
- expect(URIChecker.query_matches?("foo=bar&bing=bang", "bing=bang&foo=bar")).to be_truthy
246
+ expect(described_class).to be_query_matches("foo=bar&bing=bang", "bing=bang&foo=bar")
247
247
  end
248
248
 
249
249
  it "is false if same query with different value" do
250
- expect(URIChecker.query_matches?("foo=bar", "foo=bang")).to be_falsey
250
+ expect(described_class).not_to be_query_matches("foo=bar", "foo=bang")
251
251
  end
252
252
 
253
253
  it "is false if some queries missing" do
254
- expect(URIChecker.query_matches?("foo=bar", "foo=bar&bing=bang")).to be_falsey
254
+ expect(described_class).not_to be_query_matches("foo=bar", "foo=bar&bing=bang")
255
255
  end
256
256
 
257
257
  it "is false if some queries different value" do
258
- expect(URIChecker.query_matches?("foo=bar&bing=bang", "foo=bar&bing=banana")).to be_falsey
258
+ expect(described_class).not_to be_query_matches("foo=bar&bing=bang", "foo=bar&bing=banana")
259
259
  end
260
260
  end
261
261
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe Doorkeeper::OAuth::InvalidRequestResponse do
5
+ RSpec.describe Doorkeeper::OAuth::InvalidRequestResponse do
6
6
  describe "#name" do
7
7
  it { expect(subject.name).to eq(:invalid_request) }
8
8
  end
@@ -14,7 +14,7 @@ describe Doorkeeper::OAuth::InvalidRequestResponse do
14
14
  describe ".from_request" do
15
15
  let(:response) { described_class.from_request(request) }
16
16
 
17
- context "missing param" do
17
+ context "when param missed" do
18
18
  let(:request) { double(missing_param: "some_param") }
19
19
 
20
20
  it "sets a description" do
@@ -28,7 +28,7 @@ describe Doorkeeper::OAuth::InvalidRequestResponse do
28
28
  end
29
29
  end
30
30
 
31
- context "server doesn't support_pkce" do
31
+ context "when server doesn't support PKCE" do
32
32
  let(:request) { double(invalid_request_reason: :not_support_pkce) }
33
33
 
34
34
  it "sets a description" do
@@ -42,7 +42,7 @@ describe Doorkeeper::OAuth::InvalidRequestResponse do
42
42
  end
43
43
  end
44
44
 
45
- context "request is not authorized" do
45
+ context "when request is not authorized" do
46
46
  let(:request) { double(invalid_request_reason: :request_not_authorized) }
47
47
 
48
48
  it "sets a description" do
@@ -56,7 +56,7 @@ describe Doorkeeper::OAuth::InvalidRequestResponse do
56
56
  end
57
57
  end
58
58
 
59
- context "unknown reason" do
59
+ context "when unknown reason" do
60
60
  let(:request) { double(invalid_request_reason: :unknown_reason) }
61
61
 
62
62
  it "sets a description" do
@@ -65,7 +65,7 @@ describe Doorkeeper::OAuth::InvalidRequestResponse do
65
65
  )
66
66
  end
67
67
 
68
- it "unknown reason" do
68
+ it "sets the reason to unknown" do
69
69
  expect(response.reason).to eq(:unknown_reason)
70
70
  end
71
71
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe Doorkeeper::OAuth::InvalidTokenResponse do
5
+ RSpec.describe Doorkeeper::OAuth::InvalidTokenResponse do
6
6
  describe "#name" do
7
7
  it { expect(subject.name).to eq(:invalid_token) }
8
8
  end
@@ -14,7 +14,7 @@ describe Doorkeeper::OAuth::InvalidTokenResponse do
14
14
  describe ".from_access_token" do
15
15
  let(:response) { described_class.from_access_token(access_token) }
16
16
 
17
- context "revoked" do
17
+ context "when token revoked" do
18
18
  let(:access_token) { double(revoked?: true, expired?: true) }
19
19
 
20
20
  it "sets a description" do
@@ -26,7 +26,7 @@ describe Doorkeeper::OAuth::InvalidTokenResponse do
26
26
  end
27
27
  end
28
28
 
29
- context "expired" do
29
+ context "when token expired" do
30
30
  let(:access_token) { double(revoked?: false, expired?: true) }
31
31
 
32
32
  it "sets a description" do
@@ -38,7 +38,7 @@ describe Doorkeeper::OAuth::InvalidTokenResponse do
38
38
  end
39
39
  end
40
40
 
41
- context "unknown" do
41
+ context "when unknown" do
42
42
  let(:access_token) { double(revoked?: false, expired?: false) }
43
43
 
44
44
  it "sets a description" do
@@ -2,7 +2,11 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe Doorkeeper::OAuth::PasswordAccessTokenRequest do
5
+ RSpec.describe Doorkeeper::OAuth::PasswordAccessTokenRequest do
6
+ subject do
7
+ described_class.new(server, client, owner)
8
+ end
9
+
6
10
  let(:server) do
7
11
  double(
8
12
  :server,
@@ -14,23 +18,20 @@ describe Doorkeeper::OAuth::PasswordAccessTokenRequest do
14
18
  },
15
19
  )
16
20
  end
17
- let(:client) { FactoryBot.create(:application) }
18
- let(:owner) { FactoryBot.create(:resource_owner) }
21
+ let(:client) { Doorkeeper::OAuth::Client.new(FactoryBot.create(:application)) }
22
+ let(:application) { client.application }
23
+ let(:owner) { FactoryBot.build_stubbed(:resource_owner) }
19
24
 
20
25
  before do
21
26
  allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
22
27
  end
23
28
 
24
- subject do
25
- described_class.new(server, client, owner)
26
- end
27
-
28
29
  it "issues a new token for the client" do
29
30
  expect do
30
31
  subject.authorize
31
- end.to change { client.reload.access_tokens.count }.by(1)
32
+ end.to change { application.reload.access_tokens.count }.by(1)
32
33
 
33
- expect(client.reload.access_tokens.max_by(&:created_at).expires_in).to eq(1234)
34
+ expect(application.reload.access_tokens.max_by(&:created_at).expires_in).to eq(1234)
34
35
  end
35
36
 
36
37
  it "issues a new token without a client" do
@@ -2,7 +2,11 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe Doorkeeper::OAuth::PreAuthorization do
5
+ RSpec.describe Doorkeeper::OAuth::PreAuthorization do
6
+ subject do
7
+ described_class.new(server, attributes)
8
+ end
9
+
6
10
  let(:server) do
7
11
  server = Doorkeeper.configuration
8
12
  allow(server).to receive(:default_scopes).and_return(Doorkeeper::OAuth::Scopes.from_string("default"))
@@ -23,10 +27,6 @@ describe Doorkeeper::OAuth::PreAuthorization do
23
27
  }
24
28
  end
25
29
 
26
- subject do
27
- described_class.new(server, attributes)
28
- end
29
-
30
30
  it "is authorizable when request is valid" do
31
31
  expect(subject).to be_authorizable
32
32
  end
@@ -77,7 +77,19 @@ describe Doorkeeper::OAuth::PreAuthorization do
77
77
  end
78
78
  end
79
79
 
80
- context "client application does not restrict valid scopes" do
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
81
93
  it "accepts valid scopes" do
82
94
  attributes[:scope] = "public"
83
95
  expect(subject).to be_authorizable
@@ -101,7 +113,7 @@ describe Doorkeeper::OAuth::PreAuthorization do
101
113
  end
102
114
  end
103
115
 
104
- context "client application restricts valid scopes" do
116
+ context "when client application restricts valid scopes" do
105
117
  let(:application) do
106
118
  FactoryBot.create(:application, scopes: Doorkeeper::OAuth::Scopes.from_string("public nonsense"))
107
119
  end
@@ -118,7 +130,7 @@ describe Doorkeeper::OAuth::PreAuthorization do
118
130
 
119
131
  it "rejects (application level) non-valid scopes" do
120
132
  attributes[:scope] = "profile"
121
- expect(subject).to_not be_authorizable
133
+ expect(subject).not_to be_authorizable
122
134
  end
123
135
 
124
136
  it "accepts scopes which are permitted for grant_type" do