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,7 +2,9 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe Doorkeeper::OAuth::RefreshTokenRequest do
5
+ RSpec.describe Doorkeeper::OAuth::RefreshTokenRequest do
6
+ subject { described_class.new(server, refresh_token, credentials) }
7
+
6
8
  let(:server) do
7
9
  double :server, access_token_expires_in: 2.minutes
8
10
  end
@@ -19,8 +21,6 @@ describe Doorkeeper::OAuth::RefreshTokenRequest do
19
21
  allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(false)
20
22
  end
21
23
 
22
- subject { described_class.new(server, refresh_token, credentials) }
23
-
24
24
  it "issues a new token for the client" do
25
25
  expect { subject.authorize }.to change { client.reload.access_tokens.count }.by(1)
26
26
  # #sort_by used for MongoDB ORM extensions for valid ordering
@@ -38,7 +38,7 @@ describe Doorkeeper::OAuth::RefreshTokenRequest do
38
38
  end
39
39
 
40
40
  it "revokes the previous token" do
41
- expect { subject.authorize }.to change { refresh_token.revoked? }.from(false).to(true)
41
+ expect { subject.authorize }.to change(refresh_token, :revoked?).from(false).to(true)
42
42
  end
43
43
 
44
44
  it "calls configured request callback methods" do
@@ -87,7 +87,7 @@ describe Doorkeeper::OAuth::RefreshTokenRequest do
87
87
  expect(subject).to be_valid
88
88
  end
89
89
 
90
- context "refresh tokens expire on access token use" do
90
+ context "when refresh tokens expire on access token use" do
91
91
  before do
92
92
  allow(Doorkeeper::AccessToken).to receive(:refresh_token_revoked_on_use?).and_return(true)
93
93
  end
@@ -110,17 +110,19 @@ describe Doorkeeper::OAuth::RefreshTokenRequest do
110
110
  end
111
111
  end
112
112
 
113
- context "clientless access tokens" do
114
- let!(:refresh_token) { FactoryBot.create(:clientless_access_token, use_refresh_token: true) }
115
-
113
+ context "with clientless access tokens" do
116
114
  subject { described_class.new server, refresh_token, nil }
117
115
 
116
+ let!(:refresh_token) { FactoryBot.create(:clientless_access_token, use_refresh_token: true) }
117
+
118
118
  it "issues a new token without a client" do
119
119
  expect { subject.authorize }.to change { Doorkeeper::AccessToken.count }.by(1)
120
120
  end
121
121
  end
122
122
 
123
123
  context "with scopes" do
124
+ subject { described_class.new server, refresh_token, credentials, parameters }
125
+
124
126
  let(:refresh_token) do
125
127
  FactoryBot.create :access_token,
126
128
  use_refresh_token: true,
@@ -128,8 +130,6 @@ describe Doorkeeper::OAuth::RefreshTokenRequest do
128
130
  end
129
131
  let(:parameters) { {} }
130
132
 
131
- subject { described_class.new server, refresh_token, credentials, parameters }
132
-
133
133
  it "transfers scopes from the old token to the new token" do
134
134
  subject.authorize
135
135
  expect(Doorkeeper::AccessToken.last.scopes).to eq(%i[public write])
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe Doorkeeper::OAuth::Scopes do
5
+ RSpec.describe Doorkeeper::OAuth::Scopes do
6
6
  describe "#add" do
7
7
  it "allows you to add scopes with symbols" do
8
8
  subject.add :public
@@ -27,28 +27,28 @@ describe Doorkeeper::OAuth::Scopes do
27
27
  end
28
28
 
29
29
  it "returns true if scope with given name is present" do
30
- expect(subject.exists?("public")).to be_truthy
30
+ expect(subject).to exist("public")
31
31
  end
32
32
 
33
33
  it "returns false if scope with given name does not exist" do
34
- expect(subject.exists?("other")).to be_falsey
34
+ expect(subject).not_to exist("other")
35
35
  end
36
36
 
37
37
  it "handles symbols" do
38
- expect(subject.exists?(:public)).to be_truthy
39
- expect(subject.exists?(:other)).to be_falsey
38
+ expect(subject).to exist(:public)
39
+ expect(subject).not_to exist(:other)
40
40
  end
41
41
  end
42
42
 
43
43
  describe ".from_string" do
44
- let(:string) { "public write" }
45
-
46
44
  subject { described_class.from_string(string) }
47
45
 
46
+ let(:string) { "public write" }
47
+
48
48
  it { expect(subject).to be_a(described_class) }
49
49
 
50
50
  describe "#all" do
51
- it "should be an array of the expected scopes" do
51
+ it "is an array of the expected scopes" do
52
52
  scopes_array = subject.all
53
53
  expect(scopes_array.size).to eq(2)
54
54
  expect(scopes_array).to include("public")
@@ -120,27 +120,27 @@ describe Doorkeeper::OAuth::Scopes do
120
120
  subject { described_class.from_string("public admin") }
121
121
 
122
122
  it "returns true when at least one scope is included" do
123
- expect(subject.has_scopes?(described_class.from_string("public"))).to be_truthy
123
+ expect(subject).to have_scopes(described_class.from_string("public"))
124
124
  end
125
125
 
126
126
  it "returns true when all scopes are included" do
127
- expect(subject.has_scopes?(described_class.from_string("public admin"))).to be_truthy
127
+ expect(subject).to have_scopes(described_class.from_string("public admin"))
128
128
  end
129
129
 
130
130
  it "is true if all scopes are included in any order" do
131
- expect(subject.has_scopes?(described_class.from_string("admin public"))).to be_truthy
131
+ expect(subject).to have_scopes(described_class.from_string("admin public"))
132
132
  end
133
133
 
134
134
  it "is false if no scopes are included" do
135
- expect(subject.has_scopes?(described_class.from_string("notexistent"))).to be_falsey
135
+ expect(subject).not_to have_scopes(described_class.from_string("notexistent"))
136
136
  end
137
137
 
138
138
  it "returns false when any scope is not included" do
139
- expect(subject.has_scopes?(described_class.from_string("public nope"))).to be_falsey
139
+ expect(subject).not_to have_scopes(described_class.from_string("public nope"))
140
140
  end
141
141
 
142
142
  it "is false if no scopes are included even for existing ones" do
143
- expect(subject.has_scopes?(described_class.from_string("public admin notexistent"))).to be_falsey
143
+ expect(subject).not_to have_scopes(described_class.from_string("public admin notexistent"))
144
144
  end
145
145
  end
146
146
  end
@@ -2,7 +2,11 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe Doorkeeper::OAuth::TokenRequest do
5
+ RSpec.describe Doorkeeper::OAuth::TokenRequest do
6
+ subject do
7
+ described_class.new(pre_auth, owner)
8
+ end
9
+
6
10
  let :application do
7
11
  FactoryBot.create(:application, scopes: "public")
8
12
  end
@@ -29,10 +33,6 @@ describe Doorkeeper::OAuth::TokenRequest do
29
33
  FactoryBot.create(:doorkeeper_testing_user)
30
34
  end
31
35
 
32
- subject do
33
- described_class.new(pre_auth, owner)
34
- end
35
-
36
36
  it "creates an access token" do
37
37
  expect do
38
38
  subject.authorize
@@ -61,7 +61,7 @@ describe Doorkeeper::OAuth::TokenRequest do
61
61
  end
62
62
  end
63
63
 
64
- it "should use the custom ttl" do
64
+ it "uses the custom ttl" do
65
65
  subject.authorize
66
66
  token = Doorkeeper::AccessToken.first
67
67
  expect(token.expires_in).to eq(1234)
@@ -79,7 +79,7 @@ describe Doorkeeper::OAuth::TokenRequest do
79
79
  end
80
80
  end
81
81
 
82
- it "should fallback to access_token_expires_in" do
82
+ it "fallbacks to access_token_expires_in" do
83
83
  subject.authorize
84
84
  token = Doorkeeper::AccessToken.first
85
85
  expect(token.expires_in).to eq(654)
@@ -97,7 +97,7 @@ describe Doorkeeper::OAuth::TokenRequest do
97
97
  end
98
98
  end
99
99
 
100
- it "should fallback to access_token_expires_in" do
100
+ it "fallbacks to access_token_expires_in" do
101
101
  subject.authorize
102
102
  token = Doorkeeper::AccessToken.first
103
103
  expect(token.expires_in).to be_nil
@@ -105,7 +105,7 @@ describe Doorkeeper::OAuth::TokenRequest do
105
105
  end
106
106
  end
107
107
 
108
- context "token reuse" do
108
+ context "when reuse_access_token enabled" do
109
109
  it "creates a new token if there are no matching tokens" do
110
110
  allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
111
111
  expect do
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe Doorkeeper::OAuth::TokenResponse do
5
+ RSpec.describe Doorkeeper::OAuth::TokenResponse do
6
6
  subject { described_class.new(double.as_null_object) }
7
7
 
8
8
  it "includes access token response headers" do
@@ -16,6 +16,8 @@ describe Doorkeeper::OAuth::TokenResponse do
16
16
  end
17
17
 
18
18
  describe ".body" do
19
+ subject { described_class.new(access_token).body }
20
+
19
21
  let(:access_token) do
20
22
  double :access_token,
21
23
  plaintext_token: "some-token",
@@ -27,8 +29,6 @@ describe Doorkeeper::OAuth::TokenResponse do
27
29
  created_at: 0
28
30
  end
29
31
 
30
- subject { described_class.new(access_token).body }
31
-
32
32
  it "includes :access_token" do
33
33
  expect(subject["access_token"]).to eq("some-token")
34
34
  end
@@ -57,6 +57,8 @@ describe Doorkeeper::OAuth::TokenResponse do
57
57
  end
58
58
 
59
59
  describe ".body filters out empty values" do
60
+ subject { described_class.new(access_token).body }
61
+
60
62
  let(:access_token) do
61
63
  double :access_token,
62
64
  plaintext_token: "some-token",
@@ -67,8 +69,6 @@ describe Doorkeeper::OAuth::TokenResponse do
67
69
  created_at: 0
68
70
  end
69
71
 
70
- subject { described_class.new(access_token).body }
71
-
72
72
  it "includes :expires_in" do
73
73
  expect(subject["expires_in"]).to be_nil
74
74
  end
@@ -9,7 +9,7 @@ module Doorkeeper
9
9
  end
10
10
  end
11
11
 
12
- describe Doorkeeper::OAuth::Token do
12
+ RSpec.describe Doorkeeper::OAuth::Token do
13
13
  describe ".from_request" do
14
14
  let(:request) { double.as_null_object }
15
15
 
@@ -96,8 +96,8 @@ describe Doorkeeper::OAuth::Token do
96
96
  end
97
97
 
98
98
  describe ".authenticate" do
99
- context "refresh tokens are disabled (default)" do
100
- context "refresh tokens are enabled" do
99
+ context "when refresh tokens are disabled (default)" do
100
+ context "when refresh tokens are enabled" do
101
101
  it "does not revoke previous refresh_token if token was found" do
102
102
  token = ->(_r) { "token" }
103
103
  expect(
@@ -115,7 +115,7 @@ describe Doorkeeper::OAuth::Token do
115
115
  end
116
116
  end
117
117
 
118
- context "token hashing is enabled" do
118
+ context "when token hashing is enabled" do
119
119
  include_context "with token hashing enabled"
120
120
 
121
121
  let(:hashed_token) { hashed_or_plain_token_func.call("token") }
@@ -129,7 +129,7 @@ describe Doorkeeper::OAuth::Token do
129
129
  end
130
130
  end
131
131
 
132
- context "refresh tokens are enabled" do
132
+ context "when refresh tokens are enabled" do
133
133
  before do
134
134
  Doorkeeper.configure do
135
135
  orm DOORKEEPER_ORM
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe Doorkeeper, "configuration option DSL" do
5
+ RSpec.describe Doorkeeper::Config::Option do
6
6
  class Extension
7
7
  def self.configure(&block)
8
8
  @config = Config::Builder.new(Config.new, &block).build
@@ -2,53 +2,50 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- module Doorkeeper
6
- module Request
7
- describe Strategy do
8
- let(:server) { double }
9
- subject(:strategy) { Strategy.new(server) }
10
-
11
- describe :initialize do
12
- it "sets the server attribute" do
13
- expect(strategy.server).to eq server
14
- end
15
- end
16
-
17
- describe :request do
18
- it "requires an implementation" do
19
- expect { strategy.request }.to raise_exception NotImplementedError
20
- end
21
- end
5
+ RSpec.describe Doorkeeper::Request::Strategy do
6
+ subject(:strategy) { described_class.new(server) }
22
7
 
23
- describe "a sample Strategy subclass" do
24
- let(:fake_request) { double }
8
+ let(:server) { double }
25
9
 
26
- let(:strategy_class) do
27
- subclass = Class.new(Strategy) do
28
- class << self
29
- attr_accessor :fake_request
30
- end
10
+ describe "#initialize" do
11
+ it "sets the server attribute" do
12
+ expect(strategy.server).to eq server
13
+ end
14
+ end
31
15
 
32
- def request
33
- self.class.fake_request
34
- end
35
- end
16
+ describe "#request" do
17
+ it "requires an implementation" do
18
+ expect { strategy.request }.to raise_exception NotImplementedError
19
+ end
20
+ end
36
21
 
37
- subclass.fake_request = fake_request
38
- subclass
39
- end
22
+ describe "a sample Strategy subclass" do
23
+ subject(:strategy) { strategy_class.new(server) }
40
24
 
41
- subject(:strategy) { strategy_class.new(server) }
25
+ let(:fake_request) { double }
42
26
 
43
- it "provides a request implementation" do
44
- expect(strategy.request).to eq fake_request
27
+ let(:strategy_class) do
28
+ subclass = Class.new(described_class) do
29
+ class << self
30
+ attr_accessor :fake_request
45
31
  end
46
32
 
47
- it "authorizes the request" do
48
- expect(fake_request).to receive :authorize
49
- strategy.authorize
33
+ def request
34
+ self.class.fake_request
50
35
  end
51
36
  end
37
+
38
+ subclass.fake_request = fake_request
39
+ subclass
40
+ end
41
+
42
+ it "provides a request implementation" do
43
+ expect(strategy.request).to eq fake_request
44
+ end
45
+
46
+ it "authorizes the request" do
47
+ expect(fake_request).to receive :authorize
48
+ strategy.authorize
52
49
  end
53
50
  end
54
51
  end
@@ -2,10 +2,11 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe ::Doorkeeper::SecretStoring::Base do
6
- let(:instance) { double("instance", token: "foo") }
5
+ RSpec.describe ::Doorkeeper::SecretStoring::Base do
7
6
  subject { described_class }
8
7
 
8
+ let(:instance) { double("instance", token: "foo") }
9
+
9
10
  describe "#transform_secret" do
10
11
  it "raises" do
11
12
  expect { subject.transform_secret("foo") }.to raise_error(NotImplementedError)
@@ -3,8 +3,9 @@
3
3
  require "spec_helper"
4
4
  require "bcrypt"
5
5
 
6
- describe ::Doorkeeper::SecretStoring::BCrypt do
6
+ RSpec.describe ::Doorkeeper::SecretStoring::BCrypt do
7
7
  subject { described_class }
8
+
8
9
  let(:instance) { double("instance", token: "foo") }
9
10
 
10
11
  describe "#transform_secret" do
@@ -2,8 +2,9 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe ::Doorkeeper::SecretStoring::Plain do
5
+ RSpec.describe ::Doorkeeper::SecretStoring::Plain do
6
6
  subject { described_class }
7
+
7
8
  let(:instance) { double("instance", token: "foo") }
8
9
 
9
10
  describe "#transform_secret" do
@@ -2,8 +2,9 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe ::Doorkeeper::SecretStoring::Sha256Hash do
5
+ RSpec.describe ::Doorkeeper::SecretStoring::Sha256Hash do
6
6
  subject { described_class }
7
+
7
8
  let(:instance) { double("instance") }
8
9
 
9
10
  let(:hash_function) do
@@ -2,11 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe Doorkeeper::AccessGrant do
6
- let(:resource_owner) { FactoryBot.create(:resource_owner) }
7
- let(:client) { FactoryBot.build_stubbed(:application) }
8
- let(:clazz) { Doorkeeper::AccessGrant }
9
-
5
+ RSpec.describe Doorkeeper::AccessGrant do
10
6
  subject do
11
7
  FactoryBot.build(
12
8
  :access_grant,
@@ -16,6 +12,10 @@ describe Doorkeeper::AccessGrant do
16
12
  )
17
13
  end
18
14
 
15
+ let(:resource_owner) { FactoryBot.create(:resource_owner) }
16
+ let(:client) { FactoryBot.build_stubbed(:application) }
17
+ let(:clazz) { described_class }
18
+
19
19
  it { expect(subject).to be_valid }
20
20
 
21
21
  it_behaves_like "an accessible token"
@@ -31,6 +31,7 @@ describe Doorkeeper::AccessGrant do
31
31
  resource_owner_id: resource_owner.id,
32
32
  resource_owner_type: resource_owner.class.name
33
33
  end
34
+
34
35
  include_context "with token hashing enabled"
35
36
 
36
37
  it "holds a volatile plaintext token when created" do
@@ -143,10 +144,7 @@ describe Doorkeeper::AccessGrant do
143
144
  FactoryBot.create :access_grant, default_attributes
144
145
 
145
146
  described_class.revoke_all_for(application.id, resource_owner)
146
-
147
- described_class.all.each do |token|
148
- expect(token).to be_revoked
149
- end
147
+ expect(described_class.all).to all(be_revoked)
150
148
  end
151
149
 
152
150
  it "matches application" do
@@ -27,6 +27,7 @@ RSpec.describe Doorkeeper::AccessToken do
27
27
 
28
28
  context "with hashing enabled" do
29
29
  let(:token) { FactoryBot.create :access_token }
30
+
30
31
  include_context "with token hashing enabled"
31
32
 
32
33
  it "holds a volatile plaintext token when created" do
@@ -385,14 +386,15 @@ RSpec.describe Doorkeeper::AccessToken do
385
386
  end
386
387
  let(:access_token1) { FactoryBot.create :access_token, default_attributes }
387
388
 
388
- context "the second token has the same owner and same app" do
389
+ context "when the second token has the same owner and same app" do
389
390
  let(:access_token2) { FactoryBot.create :access_token, default_attributes }
391
+
390
392
  it "success" do
391
- expect(access_token1.same_credential?(access_token2)).to be_truthy
393
+ expect(access_token1).to be_same_credential(access_token2)
392
394
  end
393
395
  end
394
396
 
395
- context "the second token has same owner and different app" do
397
+ context "when the second token has same owner and different app" do
396
398
  let(:other_application) { FactoryBot.create :application }
397
399
  let(:access_token2) do
398
400
  FactoryBot.create :access_token,
@@ -401,12 +403,12 @@ RSpec.describe Doorkeeper::AccessToken do
401
403
  resource_owner_type: resource_owner.class.name
402
404
  end
403
405
 
404
- it "fail" do
405
- expect(access_token1.same_credential?(access_token2)).to be_falsey
406
+ it "fails" do
407
+ expect(access_token1).not_to be_same_credential(access_token2)
406
408
  end
407
409
  end
408
410
 
409
- context "the second token has different owner and different app" do
411
+ context "when the second token has different owner and different app" do
410
412
  let(:other_application) { FactoryBot.create :application }
411
413
  let(:access_token2) do
412
414
  FactoryBot.create :access_token,
@@ -414,50 +416,50 @@ RSpec.describe Doorkeeper::AccessToken do
414
416
  resource_owner_id: resource_owner.id + 1
415
417
  end
416
418
 
417
- it "fail" do
418
- expect(access_token1.same_credential?(access_token2)).to be_falsey
419
+ it "fails" do
420
+ expect(access_token1).not_to be_same_credential(access_token2)
419
421
  end
420
422
  end
421
423
 
422
- context "the second token has different owner and same app" do
424
+ context "when the second token has different owner and same app" do
423
425
  let(:access_token2) do
424
426
  FactoryBot.create :access_token,
425
427
  application: application,
426
428
  resource_owner_id: resource_owner.id + 1
427
429
  end
428
430
 
429
- it "fail" do
430
- expect(access_token1.same_credential?(access_token2)).to be_falsey
431
+ it "fails" do
432
+ expect(access_token1).not_to be_same_credential(access_token2)
431
433
  end
432
434
  end
433
435
  end
434
436
  end
435
437
 
436
438
  describe "#acceptable?" do
437
- context "a token that is not accessible" do
439
+ context "when token is not accessible" do
438
440
  let(:token) { FactoryBot.create(:access_token, created_at: 6.hours.ago) }
439
441
 
440
- it "should return false" do
442
+ it "returns false" do
441
443
  expect(token.acceptable?(nil)).to be false
442
444
  end
443
445
  end
444
446
 
445
- context "a token that has the incorrect scopes" do
447
+ context "when token has the incorrect scopes" do
446
448
  let(:token) { FactoryBot.create(:access_token) }
447
449
 
448
- it "should return false" do
450
+ it "returns false" do
449
451
  expect(token.acceptable?(["public"])).to be false
450
452
  end
451
453
  end
452
454
 
453
- context "a token is acceptable with the correct scopes" do
455
+ context "when token is acceptable with the correct scopes" do
454
456
  let(:token) do
455
457
  token = FactoryBot.create(:access_token)
456
458
  token[:scopes] = "public"
457
459
  token
458
460
  end
459
461
 
460
- it "should return true" do
462
+ it "returns true" do
461
463
  expect(token.acceptable?(["public"])).to be true
462
464
  end
463
465
  end
@@ -477,9 +479,7 @@ RSpec.describe Doorkeeper::AccessToken do
477
479
  it "revokes all tokens for given application and resource owner" do
478
480
  FactoryBot.create :access_token, default_attributes
479
481
  described_class.revoke_all_for application.id, resource_owner
480
- described_class.all.each do |token|
481
- expect(token).to be_revoked
482
- end
482
+ expect(described_class.all).to all(be_revoked)
483
483
  end
484
484
 
485
485
  it "matches application" do
@@ -529,12 +529,6 @@ RSpec.describe Doorkeeper::AccessToken do
529
529
  expect(last_token).to eq(token)
530
530
  end
531
531
 
532
- it "accepts resource owner as object" do
533
- token = FactoryBot.create :access_token, default_attributes
534
- last_token = described_class.matching_token_for(application, resource_owner, scopes)
535
- expect(last_token).to eq(token)
536
- end
537
-
538
532
  it "accepts nil as resource owner" do
539
533
  token = FactoryBot.create :access_token,
540
534
  default_attributes.merge(resource_owner_id: nil, resource_owner_type: nil)