doorkeeper 4.4.3 → 5.0.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of doorkeeper might be problematic. Click here for more details.

Files changed (223) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.gitlab-ci.yml +16 -0
  4. data/.travis.yml +7 -0
  5. data/Appraisals +2 -2
  6. data/Dangerfile +64 -0
  7. data/Gemfile +1 -1
  8. data/NEWS.md +98 -8
  9. data/README.md +110 -12
  10. data/Rakefile +6 -0
  11. data/UPGRADE.md +2 -0
  12. data/app/assets/stylesheets/doorkeeper/admin/application.css +2 -2
  13. data/app/controllers/doorkeeper/application_controller.rb +6 -3
  14. data/app/controllers/doorkeeper/application_metal_controller.rb +6 -0
  15. data/app/controllers/doorkeeper/applications_controller.rb +46 -24
  16. data/app/controllers/doorkeeper/authorizations_controller.rb +55 -12
  17. data/app/controllers/doorkeeper/authorized_applications_controller.rb +21 -2
  18. data/app/controllers/doorkeeper/token_info_controller.rb +2 -0
  19. data/app/controllers/doorkeeper/tokens_controller.rb +4 -6
  20. data/app/helpers/doorkeeper/dashboard_helper.rb +9 -7
  21. data/app/validators/redirect_uri_validator.rb +5 -2
  22. data/app/views/doorkeeper/applications/_delete_form.html.erb +3 -1
  23. data/app/views/doorkeeper/applications/_form.html.erb +25 -24
  24. data/app/views/doorkeeper/applications/edit.html.erb +1 -1
  25. data/app/views/doorkeeper/applications/index.html.erb +17 -7
  26. data/app/views/doorkeeper/applications/new.html.erb +1 -1
  27. data/app/views/doorkeeper/applications/show.html.erb +6 -6
  28. data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
  29. data/app/views/doorkeeper/authorizations/new.html.erb +4 -0
  30. data/app/views/layouts/doorkeeper/admin.html.erb +15 -15
  31. data/config/locales/en.yml +10 -1
  32. data/doorkeeper.gemspec +25 -26
  33. data/gemfiles/rails_5_2.gemfile +1 -1
  34. data/gemfiles/rails_master.gemfile +4 -1
  35. data/lib/doorkeeper/config.rb +81 -40
  36. data/lib/doorkeeper/engine.rb +6 -0
  37. data/lib/doorkeeper/errors.rb +17 -3
  38. data/lib/doorkeeper/grape/authorization_decorator.rb +2 -0
  39. data/lib/doorkeeper/grape/helpers.rb +3 -1
  40. data/lib/doorkeeper/helpers/controller.rb +9 -2
  41. data/lib/doorkeeper/models/access_grant_mixin.rb +73 -0
  42. data/lib/doorkeeper/models/access_token_mixin.rb +44 -25
  43. data/lib/doorkeeper/models/application_mixin.rb +2 -0
  44. data/lib/doorkeeper/models/concerns/accessible.rb +2 -0
  45. data/lib/doorkeeper/models/concerns/expirable.rb +2 -0
  46. data/lib/doorkeeper/models/concerns/orderable.rb +2 -0
  47. data/lib/doorkeeper/models/concerns/ownership.rb +2 -0
  48. data/lib/doorkeeper/models/concerns/revocable.rb +2 -0
  49. data/lib/doorkeeper/models/concerns/scopes.rb +3 -1
  50. data/lib/doorkeeper/oauth/authorization/code.rb +33 -8
  51. data/lib/doorkeeper/oauth/authorization/context.rb +17 -0
  52. data/lib/doorkeeper/oauth/authorization/token.rb +38 -14
  53. data/lib/doorkeeper/oauth/authorization/uri_builder.rb +2 -0
  54. data/lib/doorkeeper/oauth/authorization_code_request.rb +29 -2
  55. data/lib/doorkeeper/oauth/base_request.rb +22 -9
  56. data/lib/doorkeeper/oauth/base_response.rb +2 -0
  57. data/lib/doorkeeper/oauth/client/credentials.rb +3 -1
  58. data/lib/doorkeeper/oauth/client.rb +1 -1
  59. data/lib/doorkeeper/oauth/client_credentials/creator.rb +4 -1
  60. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +7 -2
  61. data/lib/doorkeeper/oauth/client_credentials/validation.rb +5 -5
  62. data/lib/doorkeeper/oauth/client_credentials_request.rb +1 -3
  63. data/lib/doorkeeper/oauth/code_request.rb +2 -0
  64. data/lib/doorkeeper/oauth/code_response.rb +2 -0
  65. data/lib/doorkeeper/oauth/error.rb +2 -0
  66. data/lib/doorkeeper/oauth/error_response.rb +21 -3
  67. data/lib/doorkeeper/oauth/forbidden_token_response.rb +9 -2
  68. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +2 -8
  69. data/lib/doorkeeper/oauth/helpers/unique_token.rb +2 -0
  70. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +5 -2
  71. data/lib/doorkeeper/oauth/invalid_token_response.rb +18 -0
  72. data/lib/doorkeeper/oauth/password_access_token_request.rb +9 -4
  73. data/lib/doorkeeper/oauth/pre_authorization.rb +43 -11
  74. data/lib/doorkeeper/oauth/refresh_token_request.rb +16 -3
  75. data/lib/doorkeeper/oauth/scopes.rb +3 -1
  76. data/lib/doorkeeper/oauth/token.rb +7 -2
  77. data/lib/doorkeeper/oauth/token_introspection.rb +4 -2
  78. data/lib/doorkeeper/oauth/token_request.rb +2 -0
  79. data/lib/doorkeeper/oauth/token_response.rb +6 -2
  80. data/lib/doorkeeper/oauth.rb +13 -0
  81. data/lib/doorkeeper/orm/active_record/application.rb +75 -12
  82. data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +26 -0
  83. data/lib/doorkeeper/orm/active_record.rb +4 -0
  84. data/lib/doorkeeper/rails/helpers.rb +6 -4
  85. data/lib/doorkeeper/rails/routes/mapper.rb +2 -0
  86. data/lib/doorkeeper/rails/routes/mapping.rb +2 -0
  87. data/lib/doorkeeper/rails/routes.rb +23 -8
  88. data/lib/doorkeeper/rake/db.rake +40 -0
  89. data/lib/doorkeeper/rake/setup.rake +6 -0
  90. data/lib/doorkeeper/rake.rb +14 -0
  91. data/lib/doorkeeper/request/authorization_code.rb +1 -1
  92. data/lib/doorkeeper/request/client_credentials.rb +1 -1
  93. data/lib/doorkeeper/request/code.rb +1 -1
  94. data/lib/doorkeeper/request/password.rb +1 -1
  95. data/lib/doorkeeper/request/refresh_token.rb +1 -1
  96. data/lib/doorkeeper/request/strategy.rb +2 -0
  97. data/lib/doorkeeper/request/token.rb +1 -1
  98. data/lib/doorkeeper/request.rb +29 -34
  99. data/lib/doorkeeper/server.rb +2 -0
  100. data/lib/doorkeeper/stale_records_cleaner.rb +20 -0
  101. data/lib/doorkeeper/validations.rb +2 -0
  102. data/lib/doorkeeper/version.rb +6 -24
  103. data/lib/doorkeeper.rb +20 -17
  104. data/lib/generators/doorkeeper/application_owner_generator.rb +23 -18
  105. data/lib/generators/doorkeeper/confidential_applications_generator.rb +32 -0
  106. data/lib/generators/doorkeeper/install_generator.rb +17 -9
  107. data/lib/generators/doorkeeper/migration_generator.rb +23 -18
  108. data/lib/generators/doorkeeper/pkce_generator.rb +32 -0
  109. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -24
  110. data/lib/generators/doorkeeper/templates/add_confidential_to_applications.rb.erb +13 -0
  111. data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +6 -0
  112. data/lib/generators/doorkeeper/templates/initializer.rb +96 -13
  113. data/lib/generators/doorkeeper/templates/migration.rb.erb +2 -3
  114. data/lib/generators/doorkeeper/views_generator.rb +3 -1
  115. data/spec/controllers/application_metal_controller_spec.rb +50 -0
  116. data/spec/controllers/applications_controller_spec.rb +123 -14
  117. data/spec/controllers/authorizations_controller_spec.rb +334 -51
  118. data/spec/controllers/protected_resources_controller_spec.rb +60 -18
  119. data/spec/controllers/token_info_controller_spec.rb +4 -12
  120. data/spec/controllers/tokens_controller_spec.rb +17 -20
  121. data/spec/dummy/Rakefile +1 -1
  122. data/spec/dummy/app/assets/config/manifest.js +2 -0
  123. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +1 -1
  124. data/spec/dummy/app/controllers/home_controller.rb +1 -2
  125. data/spec/dummy/config/application.rb +1 -1
  126. data/spec/dummy/config/boot.rb +2 -4
  127. data/spec/dummy/config/environment.rb +1 -1
  128. data/spec/dummy/config/environments/test.rb +5 -6
  129. data/spec/dummy/config/initializers/doorkeeper.rb +12 -6
  130. data/spec/dummy/config/initializers/new_framework_defaults.rb +2 -0
  131. data/spec/dummy/config/initializers/secret_token.rb +1 -1
  132. data/spec/dummy/config/routes.rb +3 -42
  133. data/spec/dummy/config.ru +1 -1
  134. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +4 -4
  135. data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +1 -1
  136. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +6 -0
  137. data/spec/dummy/db/migrate/{20180210183654_add_confidential_to_application.rb → 20180210183654_add_confidential_to_applications.rb} +1 -1
  138. data/spec/dummy/db/schema.rb +36 -36
  139. data/spec/dummy/script/rails +4 -3
  140. data/spec/factories.rb +6 -6
  141. data/spec/generators/application_owner_generator_spec.rb +1 -1
  142. data/spec/generators/confidential_applications_generator_spec.rb +45 -0
  143. data/spec/generators/install_generator_spec.rb +5 -2
  144. data/spec/generators/migration_generator_spec.rb +1 -1
  145. data/spec/generators/pkce_generator_spec.rb +43 -0
  146. data/spec/generators/previous_refresh_token_generator_spec.rb +1 -1
  147. data/spec/generators/templates/routes.rb +0 -1
  148. data/spec/generators/views_generator_spec.rb +2 -2
  149. data/spec/grape/grape_integration_spec.rb +2 -2
  150. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
  151. data/spec/lib/config_spec.rb +105 -39
  152. data/spec/lib/doorkeeper_spec.rb +6 -131
  153. data/spec/lib/models/expirable_spec.rb +0 -3
  154. data/spec/lib/models/revocable_spec.rb +0 -2
  155. data/spec/lib/models/scopes_spec.rb +0 -4
  156. data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -4
  157. data/spec/lib/oauth/authorization_code_request_spec.rb +17 -7
  158. data/spec/lib/oauth/base_request_spec.rb +49 -11
  159. data/spec/lib/oauth/base_response_spec.rb +1 -1
  160. data/spec/lib/oauth/client/credentials_spec.rb +2 -4
  161. data/spec/lib/oauth/client_credentials/creator_spec.rb +5 -1
  162. data/spec/lib/oauth/client_credentials/issuer_spec.rb +24 -7
  163. data/spec/lib/oauth/client_credentials/validation_spec.rb +4 -4
  164. data/spec/lib/oauth/client_credentials_integration_spec.rb +2 -2
  165. data/spec/lib/oauth/client_credentials_request_spec.rb +3 -5
  166. data/spec/lib/oauth/client_spec.rb +0 -3
  167. data/spec/lib/oauth/code_request_spec.rb +5 -3
  168. data/spec/lib/oauth/code_response_spec.rb +1 -1
  169. data/spec/lib/oauth/error_response_spec.rb +0 -3
  170. data/spec/lib/oauth/error_spec.rb +0 -2
  171. data/spec/lib/oauth/forbidden_token_response_spec.rb +1 -4
  172. data/spec/lib/oauth/helpers/scope_checker_spec.rb +8 -11
  173. data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -1
  174. data/spec/lib/oauth/helpers/uri_checker_spec.rb +22 -13
  175. data/spec/lib/oauth/invalid_token_response_spec.rb +1 -4
  176. data/spec/lib/oauth/password_access_token_request_spec.rb +53 -6
  177. data/spec/lib/oauth/pre_authorization_spec.rb +33 -4
  178. data/spec/lib/oauth/refresh_token_request_spec.rb +22 -14
  179. data/spec/lib/oauth/scopes_spec.rb +0 -3
  180. data/spec/lib/oauth/token_request_spec.rb +8 -9
  181. data/spec/lib/oauth/token_response_spec.rb +0 -1
  182. data/spec/lib/oauth/token_spec.rb +40 -14
  183. data/spec/lib/request/strategy_spec.rb +0 -1
  184. data/spec/lib/server_spec.rb +7 -7
  185. data/spec/lib/stale_records_cleaner_spec.rb +89 -0
  186. data/spec/models/doorkeeper/access_grant_spec.rb +44 -1
  187. data/spec/models/doorkeeper/access_token_spec.rb +80 -32
  188. data/spec/models/doorkeeper/application_spec.rb +293 -221
  189. data/spec/requests/applications/applications_request_spec.rb +134 -1
  190. data/spec/requests/applications/authorized_applications_spec.rb +1 -1
  191. data/spec/requests/endpoints/authorization_spec.rb +3 -3
  192. data/spec/requests/endpoints/token_spec.rb +7 -5
  193. data/spec/requests/flows/authorization_code_errors_spec.rb +2 -2
  194. data/spec/requests/flows/authorization_code_spec.rb +258 -2
  195. data/spec/requests/flows/client_credentials_spec.rb +46 -6
  196. data/spec/requests/flows/implicit_grant_errors_spec.rb +3 -3
  197. data/spec/requests/flows/implicit_grant_spec.rb +38 -11
  198. data/spec/requests/flows/password_spec.rb +61 -3
  199. data/spec/requests/flows/refresh_token_spec.rb +59 -2
  200. data/spec/requests/flows/revoke_token_spec.rb +20 -20
  201. data/spec/requests/flows/skip_authorization_spec.rb +16 -11
  202. data/spec/requests/protected_resources/metal_spec.rb +1 -1
  203. data/spec/requests/protected_resources/private_api_spec.rb +3 -3
  204. data/spec/routing/custom_controller_routes_spec.rb +59 -7
  205. data/spec/routing/default_routes_spec.rb +2 -2
  206. data/spec/routing/scoped_routes_spec.rb +16 -2
  207. data/spec/spec_helper.rb +54 -3
  208. data/spec/spec_helper_integration.rb +2 -74
  209. data/spec/support/dependencies/{factory_girl.rb → factory_bot.rb} +0 -0
  210. data/spec/support/doorkeeper_rspec.rb +20 -0
  211. data/spec/support/helpers/authorization_request_helper.rb +4 -4
  212. data/spec/support/helpers/model_helper.rb +8 -4
  213. data/spec/support/helpers/request_spec_helper.rb +10 -2
  214. data/spec/support/helpers/url_helper.rb +18 -14
  215. data/spec/support/http_method_shim.rb +12 -16
  216. data/spec/support/shared/controllers_shared_context.rb +56 -0
  217. data/spec/validators/redirect_uri_validator_spec.rb +9 -3
  218. data/spec/version/version_spec.rb +3 -3
  219. data/vendor/assets/stylesheets/doorkeeper/bootstrap.min.css +4 -5
  220. metadata +54 -35
  221. data/lib/generators/doorkeeper/add_client_confidentiality_generator.rb +0 -31
  222. data/lib/generators/doorkeeper/templates/add_confidential_to_application_migration.rb.erb +0 -11
  223. data/spec/controllers/application_metal_controller.rb +0 -10
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'generators/doorkeeper/pkce_generator'
5
+
6
+ describe 'Doorkeeper::PkceGenerator' do
7
+ include GeneratorSpec::TestCase
8
+
9
+ tests Doorkeeper::PkceGenerator
10
+ destination ::File.expand_path('../tmp/dummy', __FILE__)
11
+
12
+ describe 'after running the generator' do
13
+ before :each do
14
+ prepare_destination
15
+ end
16
+
17
+ context 'pre Rails 5.0.0' do
18
+ it 'creates a migration with no version specifier' do
19
+ stub_const("ActiveRecord::VERSION::MAJOR", 4)
20
+ stub_const("ActiveRecord::VERSION::MINOR", 2)
21
+
22
+ run_generator
23
+
24
+ assert_migration 'db/migrate/enable_pkce.rb' do |migration|
25
+ assert migration.include?("ActiveRecord::Migration\n")
26
+ end
27
+ end
28
+ end
29
+
30
+ context 'post Rails 5.0.0' do
31
+ it 'creates a migration with a version specifier' do
32
+ stub_const("ActiveRecord::VERSION::MAJOR", 5)
33
+ stub_const("ActiveRecord::VERSION::MINOR", 0)
34
+
35
+ run_generator
36
+
37
+ assert_migration 'db/migrate/enable_pkce.rb' do |migration|
38
+ assert migration.include?("ActiveRecord::Migration[5.0]\n")
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
  require 'generators/doorkeeper/previous_refresh_token_generator'
3
3
 
4
4
  describe 'Doorkeeper::PreviousRefreshTokenGenerator' do
@@ -1,3 +1,2 @@
1
1
  Rails.application.routes.draw do
2
-
3
2
  end
@@ -1,11 +1,11 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
  require 'generators/doorkeeper/views_generator'
3
3
 
4
4
  describe Doorkeeper::Generators::ViewsGenerator do
5
5
  include GeneratorSpec::TestCase
6
6
 
7
7
  tests Doorkeeper::Generators::ViewsGenerator
8
- destination File.expand_path('../tmp/dummy', __FILE__)
8
+ destination File.expand_path('tmp/dummy', __dir__)
9
9
 
10
10
  before :each do
11
11
  prepare_destination
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
  require 'grape'
3
3
  require 'rack/test'
4
4
  require 'doorkeeper/grape/helpers'
@@ -68,7 +68,7 @@ describe 'Grape integration' do
68
68
  def json_body
69
69
  JSON.parse(last_response.body)
70
70
  end
71
-
71
+
72
72
  let(:client) { FactoryBot.create(:application) }
73
73
  let(:resource) { FactoryBot.create(:doorkeeper_testing_user, name: 'Joe', password: 'sekret') }
74
74
  let(:access_token) { client_is_authorized(client, resource) }
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Doorkeeper::DashboardHelper do
4
4
  describe '#doorkeeper_errors_for' do
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Doorkeeper, 'configuration' do
4
4
  subject { Doorkeeper.configuration }
@@ -66,6 +66,17 @@ describe Doorkeeper, 'configuration' do
66
66
  end
67
67
 
68
68
  describe 'admin_authenticator' do
69
+ it 'sets the block that is accessible via authenticate_admin' do
70
+ default_behaviour = 'default behaviour'
71
+ allow(Doorkeeper::Config).to receive(:head).and_return(default_behaviour)
72
+
73
+ Doorkeeper.configure do
74
+ orm DOORKEEPER_ORM
75
+ end
76
+
77
+ expect(subject.authenticate_admin.call({})).to eq(default_behaviour)
78
+ end
79
+
69
80
  it 'sets the block that is accessible via authenticate_admin' do
70
81
  block = proc {}
71
82
  Doorkeeper.configure do
@@ -122,7 +133,7 @@ describe Doorkeeper, 'configuration' do
122
133
  it 'has all scopes' do
123
134
  Doorkeeper.configure do
124
135
  orm DOORKEEPER_ORM
125
- default_scopes :normal
136
+ default_scopes :normal
126
137
  optional_scopes :admin
127
138
  end
128
139
 
@@ -132,7 +143,7 @@ describe Doorkeeper, 'configuration' do
132
143
 
133
144
  describe 'use_refresh_token' do
134
145
  it 'is false by default' do
135
- expect(subject.refresh_token_enabled?).to be_falsey
146
+ expect(subject.refresh_token_enabled?).to eq(false)
136
147
  end
137
148
 
138
149
  it 'can change the value' do
@@ -141,7 +152,25 @@ describe Doorkeeper, 'configuration' do
141
152
  use_refresh_token
142
153
  end
143
154
 
144
- expect(subject.refresh_token_enabled?).to be_truthy
155
+ expect(subject.refresh_token_enabled?).to eq(true)
156
+ end
157
+
158
+ it 'can accept a boolean parameter' do
159
+ Doorkeeper.configure do
160
+ orm DOORKEEPER_ORM
161
+ use_refresh_token false
162
+ end
163
+
164
+ expect(subject.refresh_token_enabled?).to eq(false)
165
+ end
166
+
167
+ it 'can accept a block parameter' do
168
+ Doorkeeper.configure do
169
+ orm DOORKEEPER_ORM
170
+ use_refresh_token { |_context| nil }
171
+ end
172
+
173
+ expect(subject.refresh_token_enabled?).to be_a(Proc)
145
174
  end
146
175
 
147
176
  it "does not includes 'refresh_token' in authorization_response_types" do
@@ -150,10 +179,10 @@ describe Doorkeeper, 'configuration' do
150
179
 
151
180
  context "is enabled" do
152
181
  before do
153
- Doorkeeper.configure {
182
+ Doorkeeper.configure do
154
183
  orm DOORKEEPER_ORM
155
184
  use_refresh_token
156
- }
185
+ end
157
186
  end
158
187
 
159
188
  it "includes 'refresh_token' in authorization_response_types" do
@@ -162,34 +191,25 @@ describe Doorkeeper, 'configuration' do
162
191
  end
163
192
  end
164
193
 
165
- describe 'opt_out_native_route_change' do
166
- around(:each) do |example|
167
- Doorkeeper.configure do
168
- orm DOORKEEPER_ORM
169
- opt_out_native_route_change
170
- end
171
-
172
- Rails.application.reload_routes!
173
-
174
- subject { Doorkeeper.configuration }
175
-
176
- example.run
194
+ describe 'enforce_configured_scopes' do
195
+ it 'is false by default' do
196
+ expect(subject.enforce_configured_scopes?).to eq(false)
197
+ end
177
198
 
199
+ it 'can change the value' do
178
200
  Doorkeeper.configure do
179
201
  orm DOORKEEPER_ORM
202
+ enforce_configured_scopes
180
203
  end
181
204
 
182
- Rails.application.reload_routes!
183
- end
184
-
185
- it 'sets the native authorization code route /:code' do
186
- expect(subject.native_authorization_code_route).to eq('/:code')
205
+ expect(subject.enforce_configured_scopes?).to eq(true)
187
206
  end
188
207
  end
189
208
 
190
209
  describe 'client_credentials' do
191
210
  it 'has defaults order' do
192
- expect(subject.client_credentials_methods).to eq([:from_basic, :from_params])
211
+ expect(subject.client_credentials_methods)
212
+ .to eq(%i[from_basic from_params])
193
213
  end
194
214
 
195
215
  it 'can change the value' do
@@ -198,13 +218,14 @@ describe Doorkeeper, 'configuration' do
198
218
  client_credentials :from_digest, :from_params
199
219
  end
200
220
 
201
- expect(subject.client_credentials_methods).to eq([:from_digest, :from_params])
221
+ expect(subject.client_credentials_methods)
222
+ .to eq(%i[from_digest from_params])
202
223
  end
203
224
  end
204
225
 
205
226
  describe 'force_ssl_in_redirect_uri' do
206
227
  it 'is true by default in non-development environments' do
207
- expect(subject.force_ssl_in_redirect_uri).to be_truthy
228
+ expect(subject.force_ssl_in_redirect_uri).to eq(true)
208
229
  end
209
230
 
210
231
  it 'can change the value' do
@@ -213,7 +234,7 @@ describe Doorkeeper, 'configuration' do
213
234
  force_ssl_in_redirect_uri(false)
214
235
  end
215
236
 
216
- expect(subject.force_ssl_in_redirect_uri).to be_falsey
237
+ expect(subject.force_ssl_in_redirect_uri).to eq(false)
217
238
  end
218
239
 
219
240
  it 'can be a callable object' do
@@ -224,13 +245,14 @@ describe Doorkeeper, 'configuration' do
224
245
  end
225
246
 
226
247
  expect(subject.force_ssl_in_redirect_uri).to eq(block)
227
- expect(subject.force_ssl_in_redirect_uri.call).to be_falsey
248
+ expect(subject.force_ssl_in_redirect_uri.call).to eq(false)
228
249
  end
229
250
  end
230
251
 
231
252
  describe 'access_token_methods' do
232
253
  it 'has defaults order' do
233
- expect(subject.access_token_methods).to eq([:from_bearer_authorization, :from_access_token_param, :from_bearer_param])
254
+ expect(subject.access_token_methods)
255
+ .to eq(%i[from_bearer_authorization from_access_token_param from_bearer_param])
234
256
  end
235
257
 
236
258
  it 'can change the value' do
@@ -239,13 +261,14 @@ describe Doorkeeper, 'configuration' do
239
261
  access_token_methods :from_access_token_param, :from_bearer_param
240
262
  end
241
263
 
242
- expect(subject.access_token_methods).to eq([:from_access_token_param, :from_bearer_param])
264
+ expect(subject.access_token_methods)
265
+ .to eq(%i[from_access_token_param from_bearer_param])
243
266
  end
244
267
  end
245
268
 
246
269
  describe 'forbid_redirect_uri' do
247
270
  it 'is false by default' do
248
- expect(subject.forbid_redirect_uri.call(URI.parse('https://localhost'))).to be_falsey
271
+ expect(subject.forbid_redirect_uri.call(URI.parse('https://localhost'))).to eq(false)
249
272
  end
250
273
 
251
274
  it 'can be a callable object' do
@@ -256,13 +279,13 @@ describe Doorkeeper, 'configuration' do
256
279
  end
257
280
 
258
281
  expect(subject.forbid_redirect_uri).to eq(block)
259
- expect(subject.forbid_redirect_uri.call).to be_truthy
282
+ expect(subject.forbid_redirect_uri.call).to eq(true)
260
283
  end
261
284
  end
262
285
 
263
286
  describe 'enable_application_owner' do
264
287
  it 'is disabled by default' do
265
- expect(Doorkeeper.configuration.enable_application_owner?).not_to be_truthy
288
+ expect(Doorkeeper.configuration.enable_application_owner?).not_to eq(true)
266
289
  end
267
290
 
268
291
  context 'when enabled without confirmation' do
@@ -278,7 +301,7 @@ describe Doorkeeper, 'configuration' do
278
301
  end
279
302
 
280
303
  it 'Doorkeeper.configuration.confirm_application_owner? returns false' do
281
- expect(Doorkeeper.configuration.confirm_application_owner?).not_to be_truthy
304
+ expect(Doorkeeper.configuration.confirm_application_owner?).not_to eq(true)
282
305
  end
283
306
  end
284
307
 
@@ -295,7 +318,7 @@ describe Doorkeeper, 'configuration' do
295
318
  end
296
319
 
297
320
  it 'Doorkeeper.configuration.confirm_application_owner? returns true' do
298
- expect(Doorkeeper.configuration.confirm_application_owner?).to be_truthy
321
+ expect(Doorkeeper.configuration.confirm_application_owner?).to eq(true)
299
322
  end
300
323
  end
301
324
  end
@@ -317,17 +340,17 @@ describe Doorkeeper, 'configuration' do
317
340
 
318
341
  describe "grant_flows" do
319
342
  it "is set to all grant flows by default" do
320
- expect(Doorkeeper.configuration.grant_flows).
321
- to eq(%w[authorization_code client_credentials])
343
+ expect(Doorkeeper.configuration.grant_flows)
344
+ .to eq(%w[authorization_code client_credentials])
322
345
  end
323
346
 
324
347
  it "can change the value" do
325
348
  Doorkeeper.configure do
326
349
  orm DOORKEEPER_ORM
327
- grant_flows ['authorization_code', 'implicit']
350
+ grant_flows %w[authorization_code implicit]
328
351
  end
329
352
 
330
- expect(subject.grant_flows).to eq ['authorization_code', 'implicit']
353
+ expect(subject.grant_flows).to eq %w[authorization_code implicit]
331
354
  end
332
355
 
333
356
  context "when including 'authorization_code'" do
@@ -459,4 +482,47 @@ describe Doorkeeper, 'configuration' do
459
482
  end
460
483
  end
461
484
  end
485
+
486
+ describe "api_only" do
487
+ it "is false by default" do
488
+ expect(subject.api_only).to eq(false)
489
+ end
490
+
491
+ it "can change the value" do
492
+ Doorkeeper.configure do
493
+ orm DOORKEEPER_ORM
494
+ api_only
495
+ end
496
+
497
+ expect(subject.api_only).to eq(true)
498
+ end
499
+ end
500
+
501
+ describe 'strict_content_type' do
502
+ it 'is false by default' do
503
+ expect(subject.enforce_content_type).to eq(false)
504
+ end
505
+
506
+ it "can change the value" do
507
+ Doorkeeper.configure do
508
+ orm DOORKEEPER_ORM
509
+ enforce_content_type
510
+ end
511
+
512
+ expect(subject.enforce_content_type).to eq(true)
513
+ end
514
+ end
515
+
516
+ describe 'handle_auth_errors' do
517
+ it 'is set to render by default' do
518
+ expect(Doorkeeper.configuration.handle_auth_errors).to eq(:render)
519
+ end
520
+ it 'can change the value' do
521
+ Doorkeeper.configure do
522
+ orm DOORKEEPER_ORM
523
+ handle_auth_errors :raise
524
+ end
525
+ expect(subject.handle_auth_errors).to eq(:raise)
526
+ end
527
+ end
462
528
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Doorkeeper do
4
4
  describe "#authenticate" do
@@ -7,144 +7,19 @@ describe Doorkeeper do
7
7
  it "calls OAuth::Token#authenticate" do
8
8
  token_strategies = Doorkeeper.configuration.access_token_methods
9
9
 
10
- expect(Doorkeeper::OAuth::Token).to receive(:authenticate).
11
- with(request, *token_strategies)
10
+ expect(Doorkeeper::OAuth::Token).to receive(:authenticate)
11
+ .with(request, *token_strategies)
12
12
 
13
13
  Doorkeeper.authenticate(request)
14
14
  end
15
15
 
16
16
  it "accepts custom token strategies" do
17
- token_strategies = [:first_way, :second_way]
17
+ token_strategies = %i[first_way second_way]
18
18
 
19
- expect(Doorkeeper::OAuth::Token).to receive(:authenticate).
20
- with(request, *token_strategies)
19
+ expect(Doorkeeper::OAuth::Token).to receive(:authenticate)
20
+ .with(request, *token_strategies)
21
21
 
22
22
  Doorkeeper.authenticate(request, token_strategies)
23
23
  end
24
24
  end
25
-
26
- describe "#configured?" do
27
- after do
28
- Doorkeeper.remove_instance_variable(:@config)
29
- end
30
-
31
- context "@config is set" do
32
- it "returns true" do
33
- Doorkeeper.instance_variable_set(:@config, "hi")
34
-
35
- expect(Doorkeeper.configured?).to eq(true)
36
- end
37
- end
38
-
39
- context "@config is not set" do
40
- it "returns false" do
41
- Doorkeeper.instance_variable_set(:@config, nil)
42
-
43
- expect(Doorkeeper.configured?).to eq(false)
44
- end
45
- end
46
-
47
- it "is deprecated" do
48
- expect(ActiveSupport::Deprecation).to receive(:warn).
49
- with("Method `Doorkeeper#configured?` has been deprecated without replacement.")
50
-
51
- Doorkeeper.configured?
52
- end
53
- end
54
-
55
- describe "#database_installed?" do
56
- before do
57
- ["AccessToken", "AccessGrant", "Application"].each do |klass|
58
- @original_classes ||= {}
59
- @original_classes[klass] = Doorkeeper.const_get(klass)
60
- Doorkeeper.send(:remove_const, klass)
61
- end
62
- end
63
-
64
- after do
65
- ["AccessToken", "AccessGrant", "Application"].each do |klass|
66
- Doorkeeper.send(:remove_const, klass)
67
- Doorkeeper.const_set(klass, @original_classes[klass])
68
- end
69
- end
70
-
71
- context "all tables exist" do
72
- before do
73
- klass = double table_exists?: true
74
-
75
- Doorkeeper.const_set(:AccessToken, klass)
76
- Doorkeeper.const_set(:AccessGrant, klass)
77
- Doorkeeper.const_set(:Application, klass)
78
- end
79
-
80
- it "returns true" do
81
- expect(Doorkeeper.database_installed?).to eq(true)
82
- end
83
-
84
- it "is deprecated" do
85
- expect(ActiveSupport::Deprecation).to receive(:warn).
86
- with("Method `Doorkeeper#database_installed?` has been deprecated without replacement.")
87
-
88
- Doorkeeper.database_installed?
89
- end
90
- end
91
-
92
- context "all tables do not exist" do
93
- before do
94
- klass = double table_exists?: false
95
-
96
- Doorkeeper.const_set(:AccessToken, klass)
97
- Doorkeeper.const_set(:AccessGrant, klass)
98
- Doorkeeper.const_set(:Application, klass)
99
- end
100
-
101
- it "returns false" do
102
- expect(Doorkeeper.database_installed?).to eq(false)
103
- end
104
-
105
- it "is deprecated" do
106
- expect(ActiveSupport::Deprecation).to receive(:warn).
107
- with("Method `Doorkeeper#database_installed?` has been deprecated without replacement.")
108
-
109
- Doorkeeper.database_installed?
110
- end
111
- end
112
- end
113
-
114
- describe "#installed?" do
115
- context "methods return true" do
116
- before do
117
- allow(Doorkeeper).to receive(:configured?).and_return(true).once
118
- allow(Doorkeeper).to receive(:database_installed?).and_return(true).once
119
- end
120
-
121
- it "returns true" do
122
- expect(Doorkeeper.installed?).to eq(true)
123
- end
124
- end
125
-
126
- context "methods return false" do
127
- before do
128
- allow(Doorkeeper).to receive(:configured?).and_return(false).once
129
- allow(Doorkeeper).to receive(:database_installed?).and_return(false).once
130
- end
131
-
132
- it "returns false" do
133
- expect(Doorkeeper.installed?).to eq(false)
134
- end
135
- end
136
-
137
- it "is deprecated" do
138
- expect(ActiveSupport::Deprecation).to receive(:warn).
139
- with("Method `Doorkeeper#configured?` has been deprecated without replacement.")
140
-
141
- expect(ActiveSupport::Deprecation).to receive(:warn).
142
- with("Method `Doorkeeper#database_installed?` has been deprecated without replacement.")
143
-
144
- expect(ActiveSupport::Deprecation).to receive(:warn).
145
- with("Method `Doorkeeper#installed?` has been deprecated without replacement.")
146
-
147
- Doorkeeper.installed?
148
- end
149
- end
150
25
  end
@@ -1,6 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'active_support/time'
3
- require 'doorkeeper/models/concerns/expirable'
4
2
 
5
3
  describe 'Expirable' do
6
4
  subject do
@@ -45,6 +43,5 @@ describe 'Expirable' do
45
43
  allow(subject).to receive(:expires_in).and_return(nil)
46
44
  expect(subject.expires_in_seconds).to be_nil
47
45
  end
48
-
49
46
  end
50
47
  end
@@ -1,6 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'active_support/core_ext/object/blank'
3
- require 'doorkeeper/models/concerns/revocable'
4
2
 
5
3
  describe 'Revocable' do
6
4
  subject do
@@ -1,8 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'active_support/core_ext/module/delegation'
3
- require 'active_support/core_ext/object/blank'
4
- require 'doorkeeper/oauth/scopes'
5
- require 'doorkeeper/models/concerns/scopes'
6
2
 
7
3
  describe 'Doorkeeper::Models::Scopes' do
8
4
  subject do
@@ -1,8 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'active_support/core_ext/string'
3
- require 'uri'
4
- require 'rack/utils'
5
- require 'doorkeeper/oauth/authorization/uri_builder'
6
2
 
7
3
  module Doorkeeper::OAuth::Authorization
8
4
  describe URIBuilder do
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
 
3
3
  module Doorkeeper::OAuth
4
4
  describe AuthorizationCodeRequest do
@@ -6,7 +6,9 @@ module Doorkeeper::OAuth
6
6
  double :server,
7
7
  access_token_expires_in: 2.days,
8
8
  refresh_token_enabled?: false,
9
- custom_access_token_expires_in: ->(_app) { nil }
9
+ custom_access_token_expires_in: lambda { |context|
10
+ context.grant_type == Doorkeeper::OAuth::AUTHORIZATION_CODE ? 1234 : nil
11
+ }
10
12
  end
11
13
 
12
14
  let(:grant) { FactoryBot.create :access_grant }
@@ -22,6 +24,8 @@ module Doorkeeper::OAuth
22
24
  expect do
23
25
  subject.authorize
24
26
  end.to change { client.reload.access_tokens.count }.by(1)
27
+
28
+ expect(client.reload.access_tokens.max_by(&:created_at).expires_in).to eq(1234)
25
29
  end
26
30
 
27
31
  it "issues the token with same grant's scopes" do
@@ -30,7 +34,7 @@ module Doorkeeper::OAuth
30
34
  end
31
35
 
32
36
  it 'revokes the grant' do
33
- expect { subject.authorize }.to change { grant.reload.accessible? }
37
+ expect { subject.authorize }.to(change { grant.reload.accessible? })
34
38
  end
35
39
 
36
40
  it 'requires the grant to be accessible' do
@@ -70,20 +74,26 @@ module Doorkeeper::OAuth
70
74
  end
71
75
 
72
76
  it 'skips token creation if there is a matching one' do
77
+ scopes = grant.scopes
78
+
73
79
  Doorkeeper.configure do
74
80
  orm DOORKEEPER_ORM
75
81
  reuse_access_token
82
+ default_scopes(*scopes)
76
83
  end
77
84
 
78
85
  FactoryBot.create(:access_token, application_id: client.id,
79
- resource_owner_id: grant.resource_owner_id, scopes: grant.scopes.to_s)
86
+ resource_owner_id: grant.resource_owner_id, scopes: grant.scopes.to_s)
80
87
 
81
- expect { subject.authorize }.to_not change { Doorkeeper::AccessToken.count }
88
+ expect { subject.authorize }.to_not(change { Doorkeeper::AccessToken.count })
82
89
  end
83
90
 
84
91
  it "calls configured request callback methods" do
85
- expect(Doorkeeper.configuration.before_successful_strategy_response).to receive(:call).with(subject).once
86
- expect(Doorkeeper.configuration.after_successful_strategy_response).to receive(:call).with(subject, instance_of(Doorkeeper::OAuth::TokenResponse)).once
92
+ expect(Doorkeeper.configuration.before_successful_strategy_response)
93
+ .to receive(:call).with(subject).once
94
+ expect(Doorkeeper.configuration.after_successful_strategy_response)
95
+ .to receive(:call).with(subject, instance_of(Doorkeeper::OAuth::TokenResponse)).once
96
+
87
97
  subject.authorize
88
98
  end
89
99