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
@@ -2,38 +2,34 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- module Doorkeeper::OAuth::Authorization
6
- describe URIBuilder do
7
- subject { URIBuilder }
8
-
9
- describe :uri_with_query do
10
- it "returns the uri with query" do
11
- uri = subject.uri_with_query "http://example.com/", parameter: "value"
12
- expect(uri).to eq("http://example.com/?parameter=value")
13
- end
5
+ RSpec.describe Doorkeeper::OAuth::Authorization::URIBuilder do
6
+ describe ".uri_with_query" do
7
+ it "returns the uri with query" do
8
+ uri = described_class.uri_with_query "http://example.com/", parameter: "value"
9
+ expect(uri).to eq("http://example.com/?parameter=value")
10
+ end
14
11
 
15
- it "rejects nil values" do
16
- uri = subject.uri_with_query "http://example.com/", parameter: ""
17
- expect(uri).to eq("http://example.com/?")
18
- end
12
+ it "rejects nil values" do
13
+ uri = described_class.uri_with_query "http://example.com/", parameter: ""
14
+ expect(uri).to eq("http://example.com/?")
15
+ end
19
16
 
20
- it "preserves original query parameters" do
21
- uri = subject.uri_with_query "http://example.com/?query1=value", parameter: "value"
22
- expect(uri).to match(/query1=value/)
23
- expect(uri).to match(/parameter=value/)
24
- end
17
+ it "preserves original query parameters" do
18
+ uri = described_class.uri_with_query "http://example.com/?query1=value", parameter: "value"
19
+ expect(uri).to match(/query1=value/)
20
+ expect(uri).to match(/parameter=value/)
25
21
  end
22
+ end
26
23
 
27
- describe :uri_with_fragment do
28
- it "returns uri with parameters as fragments" do
29
- uri = subject.uri_with_fragment "http://example.com/", parameter: "value"
30
- expect(uri).to eq("http://example.com/#parameter=value")
31
- end
24
+ describe ".uri_with_fragment" do
25
+ it "returns uri with parameters as fragments" do
26
+ uri = described_class.uri_with_fragment "http://example.com/", parameter: "value"
27
+ expect(uri).to eq("http://example.com/#parameter=value")
28
+ end
32
29
 
33
- it "preserves original query parameters" do
34
- uri = subject.uri_with_fragment "http://example.com/?query1=value1", parameter: "value"
35
- expect(uri).to eq("http://example.com/?query1=value1#parameter=value")
36
- end
30
+ it "preserves original query parameters" do
31
+ uri = described_class.uri_with_fragment "http://example.com/?query1=value1", parameter: "value"
32
+ expect(uri).to eq("http://example.com/?query1=value1#parameter=value")
37
33
  end
38
34
  end
39
35
  end
@@ -2,7 +2,11 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe Doorkeeper::OAuth::AuthorizationCodeRequest do
5
+ RSpec.describe Doorkeeper::OAuth::AuthorizationCodeRequest do
6
+ subject do
7
+ described_class.new(server, grant, client, params)
8
+ end
9
+
6
10
  let(:server) do
7
11
  double :server,
8
12
  access_token_expires_in: 2.days,
@@ -26,10 +30,6 @@ describe Doorkeeper::OAuth::AuthorizationCodeRequest do
26
30
  allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
27
31
  end
28
32
 
29
- subject do
30
- described_class.new(server, grant, client, params)
31
- end
32
-
33
33
  it "issues a new token for the client" do
34
34
  expect do
35
35
  subject.authorize
@@ -111,7 +111,7 @@ describe Doorkeeper::OAuth::AuthorizationCodeRequest do
111
111
  scopes: grant.scopes.to_s,
112
112
  )
113
113
 
114
- expect { subject.authorize }.to_not(change { Doorkeeper::AccessToken.count })
114
+ expect { subject.authorize }.not_to(change { Doorkeeper::AccessToken.count })
115
115
  end
116
116
 
117
117
  it "creates token if there is a matching one but non reusable" do
@@ -2,7 +2,11 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe Doorkeeper::OAuth::BaseRequest do
5
+ RSpec.describe Doorkeeper::OAuth::BaseRequest do
6
+ subject do
7
+ described_class.new
8
+ end
9
+
6
10
  let(:access_token) do
7
11
  double :access_token,
8
12
  plaintext_token: "some-token",
@@ -29,10 +33,6 @@ describe Doorkeeper::OAuth::BaseRequest do
29
33
  allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
30
34
  end
31
35
 
32
- subject do
33
- described_class.new
34
- end
35
-
36
36
  describe "#authorize" do
37
37
  before do
38
38
  allow(subject).to receive(:access_token).and_return(access_token)
@@ -43,7 +43,7 @@ describe Doorkeeper::OAuth::BaseRequest do
43
43
  subject.authorize
44
44
  end
45
45
 
46
- context "valid" do
46
+ context "when valid" do
47
47
  before do
48
48
  allow(subject).to receive(:valid?).and_return(true)
49
49
  end
@@ -64,7 +64,7 @@ describe Doorkeeper::OAuth::BaseRequest do
64
64
  end
65
65
  end
66
66
 
67
- context "invalid" do
67
+ context "when invalid" do
68
68
  context "with error other than invalid_request" do
69
69
  before do
70
70
  allow(subject).to receive(:valid?).and_return(false)
@@ -146,7 +146,7 @@ describe Doorkeeper::OAuth::BaseRequest do
146
146
  "public",
147
147
  server,
148
148
  )
149
- expect(result.expires_in).to eql(500)
149
+ expect(result.expires_in).to be(500)
150
150
  end
151
151
 
152
152
  it "respects use_refresh_token with a block" do
@@ -167,7 +167,7 @@ describe Doorkeeper::OAuth::BaseRequest do
167
167
  "public",
168
168
  server,
169
169
  )
170
- expect(result.refresh_token).to_not be_nil
170
+ expect(result.refresh_token).not_to be_nil
171
171
 
172
172
  result = subject.find_or_create_access_token(
173
173
  client,
@@ -180,7 +180,7 @@ describe Doorkeeper::OAuth::BaseRequest do
180
180
  end
181
181
 
182
182
  describe "#scopes" do
183
- context "@original_scopes is present" do
183
+ context "when @original_scopes is present" do
184
184
  before do
185
185
  subject.instance_variable_set(:@original_scopes, "public write")
186
186
  end
@@ -192,7 +192,7 @@ describe Doorkeeper::OAuth::BaseRequest do
192
192
  end
193
193
  end
194
194
 
195
- context "@original_scopes is not present" do
195
+ context "when @original_scopes is blank" do
196
196
  before do
197
197
  subject.instance_variable_set(:@original_scopes, "")
198
198
  end
@@ -207,20 +207,4 @@ describe Doorkeeper::OAuth::BaseRequest do
207
207
  end
208
208
  end
209
209
  end
210
-
211
- describe "#valid?" do
212
- context "error is nil" do
213
- it "returns true" do
214
- allow(subject).to receive(:error).and_return(nil).once
215
- expect(subject.valid?).to eq(true)
216
- end
217
- end
218
-
219
- context "error is not nil" do
220
- it "returns false" do
221
- allow(subject).to receive(:error).and_return(Object.new).once
222
- expect(subject.valid?).to eq(false)
223
- end
224
- end
225
- end
226
210
  end
@@ -2,9 +2,9 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe Doorkeeper::OAuth::BaseResponse do
5
+ RSpec.describe Doorkeeper::OAuth::BaseResponse do
6
6
  subject do
7
- Doorkeeper::OAuth::BaseResponse.new
7
+ described_class.new
8
8
  end
9
9
 
10
10
  describe "#body" do
@@ -8,10 +8,10 @@ class Doorkeeper::OAuth::Client
8
8
  let(:client_secret) { "some-secret" }
9
9
 
10
10
  it "is blank when the uid in credentials is blank" do
11
- expect(Credentials.new(nil, nil)).to be_blank
12
- expect(Credentials.new(nil, "something")).to be_blank
13
- expect(Credentials.new("something", nil)).to be_present
14
- expect(Credentials.new("something", "something")).to be_present
11
+ expect(described_class.new(nil, nil)).to be_blank
12
+ expect(described_class.new(nil, "something")).to be_blank
13
+ expect(described_class.new("something", nil)).to be_present
14
+ expect(described_class.new("something", "something")).to be_present
15
15
  end
16
16
 
17
17
  describe ".from_request" do
@@ -23,66 +23,66 @@ class Doorkeeper::OAuth::Client
23
23
 
24
24
  it "accepts anything that responds to #call" do
25
25
  expect(method).to receive(:call).with(request)
26
- Credentials.from_request request, method
26
+ described_class.from_request request, method
27
27
  end
28
28
 
29
29
  it "delegates methods received as symbols to Credentials class" do
30
- expect(Credentials).to receive(:from_params).with(request)
31
- Credentials.from_request request, :from_params
30
+ expect(described_class).to receive(:from_params).with(request)
31
+ described_class.from_request request, :from_params
32
32
  end
33
33
 
34
34
  it "stops at the first credentials found" do
35
35
  not_called_method = double
36
36
  expect(not_called_method).not_to receive(:call)
37
- Credentials.from_request request, ->(_) {}, method, not_called_method
37
+ described_class.from_request request, ->(_) {}, method, not_called_method
38
38
  end
39
39
 
40
40
  it "returns new Credentials" do
41
- credentials = Credentials.from_request request, method
42
- expect(credentials).to be_a(Credentials)
41
+ credentials = described_class.from_request request, method
42
+ expect(credentials).to be_a(described_class)
43
43
  end
44
44
 
45
45
  it "returns uid and secret from extractor method" do
46
- credentials = Credentials.from_request request, method
46
+ credentials = described_class.from_request request, method
47
47
  expect(credentials.uid).to eq("uid")
48
48
  expect(credentials.secret).to eq("secret")
49
49
  end
50
50
  end
51
51
 
52
- describe :from_params do
52
+ describe ".from_params" do
53
53
  it "returns credentials from parameters when Authorization header is not available" do
54
- request = double parameters: { client_id: client_id, client_secret: client_secret }
55
- uid, secret = Credentials.from_params(request)
54
+ request = double parameters: { client_id: client_id, client_secret: client_secret }
55
+ uid, secret = described_class.from_params(request)
56
56
 
57
- expect(uid).to eq("some-uid")
57
+ expect(uid).to eq("some-uid")
58
58
  expect(secret).to eq("some-secret")
59
59
  end
60
60
 
61
61
  it "is blank when there are no credentials" do
62
- request = double parameters: {}
63
- uid, secret = Credentials.from_params(request)
62
+ request = double parameters: {}
63
+ uid, secret = described_class.from_params(request)
64
64
 
65
- expect(uid).to be_blank
65
+ expect(uid).to be_blank
66
66
  expect(secret).to be_blank
67
67
  end
68
68
  end
69
69
 
70
- describe :from_basic do
70
+ describe ".from_basic" do
71
71
  let(:credentials) { Base64.encode64("#{client_id}:#{client_secret}") }
72
72
 
73
73
  it "decodes the credentials" do
74
- request = double authorization: "Basic #{credentials}"
75
- uid, secret = Credentials.from_basic(request)
74
+ request = double authorization: "Basic #{credentials}"
75
+ uid, secret = described_class.from_basic(request)
76
76
 
77
- expect(uid).to eq("some-uid")
77
+ expect(uid).to eq("some-uid")
78
78
  expect(secret).to eq("some-secret")
79
79
  end
80
80
 
81
81
  it "is blank if Authorization is not Basic" do
82
- request = double authorization: credentials.to_s
83
- uid, secret = Credentials.from_basic(request)
82
+ request = double authorization: credentials.to_s
83
+ uid, secret = described_class.from_basic(request)
84
84
 
85
- expect(uid).to be_blank
85
+ expect(uid).to be_blank
86
86
  expect(secret).to be_blank
87
87
  end
88
88
  end
@@ -2,136 +2,134 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- class Doorkeeper::OAuth::ClientCredentialsRequest
6
- describe Creator do
7
- let(:client) { FactoryBot.create :application }
8
- let(:scopes) { Doorkeeper::OAuth::Scopes.from_string("public") }
5
+ RSpec.describe Doorkeeper::OAuth::ClientCredentials::Creator do
6
+ let(:client) { FactoryBot.create :application }
7
+ let(:scopes) { Doorkeeper::OAuth::Scopes.from_string("public") }
9
8
 
9
+ before do
10
+ default_scopes_exist :public
11
+ end
12
+
13
+ it "creates a new token" do
14
+ expect do
15
+ subject.call(client, scopes)
16
+ end.to change { Doorkeeper::AccessToken.count }.by(1)
17
+ end
18
+
19
+ context "when reuse_access_token is true" do
10
20
  before do
11
- default_scopes_exist :public
21
+ allow(Doorkeeper.config).to receive(:reuse_access_token).and_return(true)
12
22
  end
13
23
 
14
- it "creates a new token" do
15
- expect do
16
- subject.call(client, scopes)
17
- end.to change { Doorkeeper::AccessToken.count }.by(1)
24
+ context "when expiration is disabled" do
25
+ it "returns the existing valid token" do
26
+ existing_token = subject.call(client, scopes)
27
+
28
+ result = subject.call(client, scopes)
29
+
30
+ expect(Doorkeeper::AccessToken.count).to eq(1)
31
+ expect(result).to eq(existing_token)
32
+ end
18
33
  end
19
34
 
20
- context "when reuse_access_token is true" do
35
+ context "when existing token has not crossed token_reuse_limit" do
36
+ let!(:existing_token) { subject.call(client, scopes, expires_in: 1000) }
37
+
21
38
  before do
22
- allow(Doorkeeper.config).to receive(:reuse_access_token).and_return(true)
39
+ allow(Doorkeeper.config).to receive(:token_reuse_limit).and_return(50)
40
+ allow_any_instance_of(Doorkeeper::AccessToken).to receive(:expires_in_seconds).and_return(600)
23
41
  end
24
42
 
25
- context "when expiration is disabled" do
26
- it "returns the existing valid token" do
27
- existing_token = subject.call(client, scopes)
43
+ it "returns the existing valid token" do
44
+ result = subject.call(client, scopes, expires_in: 1000)
28
45
 
29
- result = subject.call(client, scopes)
30
-
31
- expect(Doorkeeper::AccessToken.count).to eq(1)
32
- expect(result).to eq(existing_token)
33
- end
46
+ expect(Doorkeeper::AccessToken.count).to eq(1)
47
+ expect(result).to eq(existing_token)
34
48
  end
35
49
 
36
- context "when existing token has not crossed token_reuse_limit" do
37
- let!(:existing_token) { subject.call(client, scopes, expires_in: 1000) }
38
-
50
+ context "when revoke_previous_client_credentials_token is false" do
39
51
  before do
40
- allow(Doorkeeper.config).to receive(:token_reuse_limit).and_return(50)
41
- allow_any_instance_of(Doorkeeper::AccessToken).to receive(:expires_in_seconds).and_return(600)
52
+ allow(Doorkeeper.config).to receive(:revoke_previous_client_credentials_token).and_return(false)
42
53
  end
43
54
 
44
- it "returns the existing valid token" do
45
- result = subject.call(client, scopes, expires_in: 1000)
46
-
47
- expect(Doorkeeper::AccessToken.count).to eq(1)
48
- expect(result).to eq(existing_token)
49
- end
50
-
51
- context "and when revoke_previous_client_credentials_token is false" do
52
- before do
53
- allow(Doorkeeper.config).to receive(:revoke_previous_client_credentials_token).and_return(false)
54
- end
55
-
56
- it "does not revoke the existing valid token" do
57
- subject.call(client, scopes, expires_in: 1000)
58
- expect(existing_token.reload).not_to be_revoked
59
- end
60
- end
61
- end
62
-
63
- context "when existing token has crossed token_reuse_limit" do
64
- it "returns a new token" do
65
- allow(Doorkeeper.config).to receive(:token_reuse_limit).and_return(50)
66
- existing_token = subject.call(client, scopes, expires_in: 1000)
67
-
68
- allow_any_instance_of(Doorkeeper::AccessToken).to receive(:expires_in_seconds).and_return(400)
69
- result = subject.call(client, scopes, expires_in: 1000)
70
-
71
- expect(Doorkeeper::AccessToken.count).to eq(2)
72
- expect(result).not_to eq(existing_token)
55
+ it "does not revoke the existing valid token" do
56
+ subject.call(client, scopes, expires_in: 1000)
57
+ expect(existing_token.reload).not_to be_revoked
73
58
  end
74
59
  end
60
+ end
75
61
 
76
- context "when existing token has been expired" do
77
- it "returns a new token" do
78
- allow(Doorkeeper.configuration).to receive(:token_reuse_limit).and_return(50)
79
- existing_token = subject.call(client, scopes, expires_in: 1000)
62
+ context "when existing token has crossed token_reuse_limit" do
63
+ it "returns a new token" do
64
+ allow(Doorkeeper.config).to receive(:token_reuse_limit).and_return(50)
65
+ existing_token = subject.call(client, scopes, expires_in: 1000)
80
66
 
81
- allow_any_instance_of(Doorkeeper::AccessToken).to receive(:expired?).and_return(true)
82
- result = subject.call(client, scopes, expires_in: 1000)
67
+ allow_any_instance_of(Doorkeeper::AccessToken).to receive(:expires_in_seconds).and_return(400)
68
+ result = subject.call(client, scopes, expires_in: 1000)
83
69
 
84
- expect(Doorkeeper::AccessToken.count).to eq(2)
85
- expect(result).not_to eq(existing_token)
86
- end
70
+ expect(Doorkeeper::AccessToken.count).to eq(2)
71
+ expect(result).not_to eq(existing_token)
87
72
  end
88
73
  end
89
74
 
90
- context "when reuse_access_token is false" do
91
- before do
92
- allow(Doorkeeper.config).to receive(:reuse_access_token).and_return(false)
93
- end
94
-
75
+ context "when existing token has been expired" do
95
76
  it "returns a new token" do
96
- existing_token = subject.call(client, scopes)
77
+ allow(Doorkeeper.configuration).to receive(:token_reuse_limit).and_return(50)
78
+ existing_token = subject.call(client, scopes, expires_in: 1000)
97
79
 
98
- result = subject.call(client, scopes)
80
+ allow_any_instance_of(Doorkeeper::AccessToken).to receive(:expired?).and_return(true)
81
+ result = subject.call(client, scopes, expires_in: 1000)
99
82
 
100
83
  expect(Doorkeeper::AccessToken.count).to eq(2)
101
84
  expect(result).not_to eq(existing_token)
102
85
  end
103
86
  end
87
+ end
104
88
 
105
- context "when revoke_previous_client_credentials_token is true" do
106
- let!(:existing_token) { subject.call(client, scopes, expires_in: 1000) }
89
+ context "when reuse_access_token is false" do
90
+ before do
91
+ allow(Doorkeeper.config).to receive(:reuse_access_token).and_return(false)
92
+ end
107
93
 
108
- before do
109
- allow(Doorkeeper.configuration).to receive(:revoke_previous_client_credentials_token).and_return(true)
110
- end
94
+ it "returns a new token" do
95
+ existing_token = subject.call(client, scopes)
111
96
 
112
- it "revokes the existing token" do
113
- subject.call(client, scopes, expires_in: 1000)
114
- expect(existing_token.reload).to be_revoked
115
- end
97
+ result = subject.call(client, scopes)
98
+
99
+ expect(Doorkeeper::AccessToken.count).to eq(2)
100
+ expect(result).not_to eq(existing_token)
116
101
  end
102
+ end
117
103
 
118
- context "when revoke_previous_client_credentials_token is false" do
119
- let!(:existing_token) { subject.call(client, scopes, expires_in: 1000) }
104
+ context "when revoke_previous_client_credentials_token is true" do
105
+ let!(:existing_token) { subject.call(client, scopes, expires_in: 1000) }
120
106
 
121
- before do
122
- allow(Doorkeeper.configuration).to receive(:revoke_previous_client_credentials_token).and_return(false)
123
- end
107
+ before do
108
+ allow(Doorkeeper.configuration).to receive(:revoke_previous_client_credentials_token?).and_return(true)
109
+ end
124
110
 
125
- it "does not revoke the existing token" do
126
- subject.call(client, scopes, expires_in: 1000)
127
- expect(existing_token.reload).not_to be_revoked
128
- end
111
+ it "revokes the existing token" do
112
+ subject.call(client, scopes, expires_in: 1000)
113
+ expect(existing_token.reload).to be_revoked
129
114
  end
115
+ end
130
116
 
131
- it "returns false if creation fails" do
132
- expect(Doorkeeper::AccessToken).to receive(:find_or_create_for).and_return(false)
133
- created = subject.call(client, scopes)
134
- expect(created).to be_falsey
117
+ context "when revoke_previous_client_credentials_token is false" do
118
+ let!(:existing_token) { subject.call(client, scopes, expires_in: 1000) }
119
+
120
+ before do
121
+ allow(Doorkeeper.configuration).to receive(:revoke_previous_client_credentials_token?).and_return(false)
122
+ end
123
+
124
+ it "does not revoke the existing token" do
125
+ subject.call(client, scopes, expires_in: 1000)
126
+ expect(existing_token.reload).not_to be_revoked
135
127
  end
136
128
  end
129
+
130
+ it "returns false if creation fails" do
131
+ expect(Doorkeeper::AccessToken).to receive(:find_or_create_for).and_return(false)
132
+ created = subject.call(client, scopes)
133
+ expect(created).to be_falsey
134
+ end
137
135
  end