doorkeeper 4.4.3 → 5.0.0

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 (181) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.gitlab-ci.yml +16 -0
  4. data/.travis.yml +2 -0
  5. data/Appraisals +2 -2
  6. data/Gemfile +1 -1
  7. data/NEWS.md +61 -8
  8. data/README.md +92 -9
  9. data/Rakefile +6 -0
  10. data/UPGRADE.md +2 -0
  11. data/app/assets/stylesheets/doorkeeper/admin/application.css +2 -2
  12. data/app/controllers/doorkeeper/application_controller.rb +4 -3
  13. data/app/controllers/doorkeeper/application_metal_controller.rb +4 -0
  14. data/app/controllers/doorkeeper/applications_controller.rb +42 -22
  15. data/app/controllers/doorkeeper/authorizations_controller.rb +55 -12
  16. data/app/controllers/doorkeeper/authorized_applications_controller.rb +19 -2
  17. data/app/controllers/doorkeeper/tokens_controller.rb +2 -6
  18. data/app/helpers/doorkeeper/dashboard_helper.rb +7 -7
  19. data/app/validators/redirect_uri_validator.rb +3 -2
  20. data/app/views/doorkeeper/applications/_delete_form.html.erb +3 -1
  21. data/app/views/doorkeeper/applications/_form.html.erb +25 -24
  22. data/app/views/doorkeeper/applications/edit.html.erb +1 -1
  23. data/app/views/doorkeeper/applications/index.html.erb +17 -7
  24. data/app/views/doorkeeper/applications/new.html.erb +1 -1
  25. data/app/views/doorkeeper/applications/show.html.erb +6 -6
  26. data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
  27. data/app/views/doorkeeper/authorizations/new.html.erb +4 -0
  28. data/app/views/layouts/doorkeeper/admin.html.erb +15 -15
  29. data/config/locales/en.yml +10 -1
  30. data/doorkeeper.gemspec +18 -20
  31. data/gemfiles/rails_5_2.gemfile +1 -1
  32. data/gemfiles/rails_master.gemfile +4 -1
  33. data/lib/doorkeeper/config.rb +75 -39
  34. data/lib/doorkeeper/engine.rb +4 -0
  35. data/lib/doorkeeper/errors.rb +2 -5
  36. data/lib/doorkeeper/grape/helpers.rb +1 -1
  37. data/lib/doorkeeper/helpers/controller.rb +7 -2
  38. data/lib/doorkeeper/models/access_grant_mixin.rb +71 -0
  39. data/lib/doorkeeper/models/access_token_mixin.rb +39 -22
  40. data/lib/doorkeeper/models/concerns/scopes.rb +1 -1
  41. data/lib/doorkeeper/oauth/authorization/code.rb +31 -8
  42. data/lib/doorkeeper/oauth/authorization/context.rb +15 -0
  43. data/lib/doorkeeper/oauth/authorization/token.rb +36 -14
  44. data/lib/doorkeeper/oauth/authorization_code_request.rb +27 -2
  45. data/lib/doorkeeper/oauth/base_request.rb +20 -9
  46. data/lib/doorkeeper/oauth/client/credentials.rb +1 -1
  47. data/lib/doorkeeper/oauth/client.rb +0 -2
  48. data/lib/doorkeeper/oauth/client_credentials/creator.rb +2 -1
  49. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +6 -3
  50. data/lib/doorkeeper/oauth/client_credentials/validation.rb +4 -6
  51. data/lib/doorkeeper/oauth/client_credentials_request.rb +0 -4
  52. data/lib/doorkeeper/oauth/error_response.rb +11 -3
  53. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +0 -8
  54. data/lib/doorkeeper/oauth/password_access_token_request.rb +7 -4
  55. data/lib/doorkeeper/oauth/pre_authorization.rb +41 -11
  56. data/lib/doorkeeper/oauth/refresh_token_request.rb +6 -1
  57. data/lib/doorkeeper/oauth/scopes.rb +1 -1
  58. data/lib/doorkeeper/oauth/token.rb +5 -2
  59. data/lib/doorkeeper/oauth/token_introspection.rb +2 -2
  60. data/lib/doorkeeper/oauth/token_response.rb +4 -2
  61. data/lib/doorkeeper/oauth.rb +13 -0
  62. data/lib/doorkeeper/orm/active_record/application.rb +22 -14
  63. data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +26 -0
  64. data/lib/doorkeeper/orm/active_record.rb +2 -0
  65. data/lib/doorkeeper/rails/helpers.rb +2 -4
  66. data/lib/doorkeeper/rails/routes.rb +14 -6
  67. data/lib/doorkeeper/rake/db.rake +40 -0
  68. data/lib/doorkeeper/rake/setup.rake +6 -0
  69. data/lib/doorkeeper/rake.rb +14 -0
  70. data/lib/doorkeeper/request/authorization_code.rb +0 -2
  71. data/lib/doorkeeper/request/client_credentials.rb +0 -2
  72. data/lib/doorkeeper/request/code.rb +0 -2
  73. data/lib/doorkeeper/request/password.rb +0 -2
  74. data/lib/doorkeeper/request/refresh_token.rb +0 -2
  75. data/lib/doorkeeper/request/token.rb +0 -2
  76. data/lib/doorkeeper/request.rb +28 -35
  77. data/lib/doorkeeper/version.rb +5 -25
  78. data/lib/doorkeeper.rb +19 -17
  79. data/lib/generators/doorkeeper/application_owner_generator.rb +23 -18
  80. data/lib/generators/doorkeeper/confidential_applications_generator.rb +32 -0
  81. data/lib/generators/doorkeeper/install_generator.rb +17 -9
  82. data/lib/generators/doorkeeper/migration_generator.rb +23 -18
  83. data/lib/generators/doorkeeper/pkce_generator.rb +32 -0
  84. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -24
  85. data/lib/generators/doorkeeper/templates/add_confidential_to_applications.rb.erb +13 -0
  86. data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +6 -0
  87. data/lib/generators/doorkeeper/templates/initializer.rb +76 -11
  88. data/lib/generators/doorkeeper/views_generator.rb +3 -1
  89. data/spec/controllers/application_metal_controller_spec.rb +50 -0
  90. data/spec/controllers/applications_controller_spec.rb +126 -13
  91. data/spec/controllers/authorizations_controller_spec.rb +277 -47
  92. data/spec/controllers/protected_resources_controller_spec.rb +16 -16
  93. data/spec/controllers/token_info_controller_spec.rb +4 -12
  94. data/spec/controllers/tokens_controller_spec.rb +13 -15
  95. data/spec/dummy/app/assets/config/manifest.js +2 -0
  96. data/spec/dummy/config/environments/test.rb +4 -5
  97. data/spec/dummy/config/initializers/doorkeeper.rb +10 -5
  98. data/spec/dummy/config/initializers/new_framework_defaults.rb +4 -0
  99. data/spec/dummy/config/routes.rb +3 -42
  100. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +6 -0
  101. data/spec/dummy/db/migrate/{20180210183654_add_confidential_to_application.rb → 20180210183654_add_confidential_to_applications.rb} +1 -1
  102. data/spec/dummy/db/schema.rb +36 -36
  103. data/spec/generators/application_owner_generator_spec.rb +1 -1
  104. data/spec/generators/confidential_applications_generator_spec.rb +45 -0
  105. data/spec/generators/install_generator_spec.rb +1 -1
  106. data/spec/generators/migration_generator_spec.rb +1 -1
  107. data/spec/generators/pkce_generator_spec.rb +43 -0
  108. data/spec/generators/previous_refresh_token_generator_spec.rb +1 -1
  109. data/spec/generators/views_generator_spec.rb +1 -1
  110. data/spec/grape/grape_integration_spec.rb +1 -1
  111. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
  112. data/spec/lib/config_spec.rb +80 -31
  113. data/spec/lib/doorkeeper_spec.rb +1 -126
  114. data/spec/lib/models/expirable_spec.rb +0 -3
  115. data/spec/lib/models/revocable_spec.rb +0 -2
  116. data/spec/lib/models/scopes_spec.rb +0 -4
  117. data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -4
  118. data/spec/lib/oauth/authorization_code_request_spec.rb +9 -2
  119. data/spec/lib/oauth/base_request_spec.rb +40 -2
  120. data/spec/lib/oauth/base_response_spec.rb +1 -1
  121. data/spec/lib/oauth/client/credentials_spec.rb +1 -3
  122. data/spec/lib/oauth/client_credentials/creator_spec.rb +5 -1
  123. data/spec/lib/oauth/client_credentials/issuer_spec.rb +26 -7
  124. data/spec/lib/oauth/client_credentials/validation_spec.rb +2 -3
  125. data/spec/lib/oauth/client_credentials_integration_spec.rb +1 -1
  126. data/spec/lib/oauth/client_credentials_request_spec.rb +3 -5
  127. data/spec/lib/oauth/client_spec.rb +0 -3
  128. data/spec/lib/oauth/code_request_spec.rb +4 -2
  129. data/spec/lib/oauth/error_response_spec.rb +0 -3
  130. data/spec/lib/oauth/error_spec.rb +0 -2
  131. data/spec/lib/oauth/forbidden_token_response_spec.rb +1 -4
  132. data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -3
  133. data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -1
  134. data/spec/lib/oauth/helpers/uri_checker_spec.rb +5 -7
  135. data/spec/lib/oauth/invalid_token_response_spec.rb +1 -4
  136. data/spec/lib/oauth/password_access_token_request_spec.rb +37 -2
  137. data/spec/lib/oauth/pre_authorization_spec.rb +33 -4
  138. data/spec/lib/oauth/refresh_token_request_spec.rb +11 -7
  139. data/spec/lib/oauth/scopes_spec.rb +0 -3
  140. data/spec/lib/oauth/token_request_spec.rb +4 -5
  141. data/spec/lib/oauth/token_response_spec.rb +0 -1
  142. data/spec/lib/oauth/token_spec.rb +37 -14
  143. data/spec/lib/orm/active_record/stale_records_cleaner_spec.rb +79 -0
  144. data/spec/lib/request/strategy_spec.rb +0 -1
  145. data/spec/lib/server_spec.rb +1 -1
  146. data/spec/models/doorkeeper/access_grant_spec.rb +44 -1
  147. data/spec/models/doorkeeper/access_token_spec.rb +66 -22
  148. data/spec/models/doorkeeper/application_spec.rb +14 -47
  149. data/spec/requests/applications/applications_request_spec.rb +134 -1
  150. data/spec/requests/applications/authorized_applications_spec.rb +1 -1
  151. data/spec/requests/endpoints/authorization_spec.rb +1 -1
  152. data/spec/requests/endpoints/token_spec.rb +7 -5
  153. data/spec/requests/flows/authorization_code_errors_spec.rb +1 -1
  154. data/spec/requests/flows/authorization_code_spec.rb +197 -1
  155. data/spec/requests/flows/client_credentials_spec.rb +46 -6
  156. data/spec/requests/flows/implicit_grant_errors_spec.rb +1 -1
  157. data/spec/requests/flows/implicit_grant_spec.rb +38 -11
  158. data/spec/requests/flows/password_spec.rb +56 -2
  159. data/spec/requests/flows/refresh_token_spec.rb +2 -2
  160. data/spec/requests/flows/revoke_token_spec.rb +11 -11
  161. data/spec/requests/flows/skip_authorization_spec.rb +16 -11
  162. data/spec/requests/protected_resources/metal_spec.rb +1 -1
  163. data/spec/requests/protected_resources/private_api_spec.rb +1 -1
  164. data/spec/routing/custom_controller_routes_spec.rb +59 -7
  165. data/spec/routing/default_routes_spec.rb +2 -2
  166. data/spec/routing/scoped_routes_spec.rb +16 -2
  167. data/spec/spec_helper.rb +54 -3
  168. data/spec/spec_helper_integration.rb +2 -74
  169. data/spec/support/dependencies/{factory_girl.rb → factory_bot.rb} +0 -0
  170. data/spec/support/doorkeeper_rspec.rb +19 -0
  171. data/spec/support/helpers/authorization_request_helper.rb +4 -4
  172. data/spec/support/helpers/request_spec_helper.rb +10 -2
  173. data/spec/support/helpers/url_helper.rb +7 -3
  174. data/spec/support/http_method_shim.rb +12 -16
  175. data/spec/validators/redirect_uri_validator_spec.rb +7 -1
  176. data/spec/version/version_spec.rb +3 -3
  177. data/vendor/assets/stylesheets/doorkeeper/bootstrap.min.css +4 -5
  178. metadata +37 -33
  179. data/lib/generators/doorkeeper/add_client_confidentiality_generator.rb +0 -31
  180. data/lib/generators/doorkeeper/templates/add_confidential_to_application_migration.rb.erb +0 -11
  181. data/spec/controllers/application_metal_controller.rb +0 -10
@@ -1,27 +1,79 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
 
3
3
  describe 'Custom controller for routes' do
4
- it 'GET /space/scope/authorize routes to custom authorizations controller' do
4
+ before :all do
5
+ Rails.application.routes.disable_clear_and_finalize = true
6
+
7
+ Rails.application.routes.draw do
8
+ scope 'inner_space' do
9
+ use_doorkeeper scope: 'scope' do
10
+ controllers authorizations: 'custom_authorizations',
11
+ tokens: 'custom_authorizations',
12
+ applications: 'custom_authorizations',
13
+ token_info: 'custom_authorizations'
14
+
15
+ as authorizations: 'custom_auth',
16
+ tokens: 'custom_token',
17
+ token_info: 'custom_token_info'
18
+ end
19
+ end
20
+
21
+ scope 'space' do
22
+ use_doorkeeper do
23
+ controllers authorizations: 'custom_authorizations',
24
+ tokens: 'custom_authorizations',
25
+ applications: 'custom_authorizations',
26
+ token_info: 'custom_authorizations'
27
+
28
+ as authorizations: 'custom_auth',
29
+ tokens: 'custom_token',
30
+ token_info: 'custom_token_info'
31
+ end
32
+ end
33
+
34
+ scope 'outer_space' do
35
+ use_doorkeeper do
36
+ controllers authorizations: 'custom_authorizations',
37
+ tokens: 'custom_authorizations',
38
+ token_info: 'custom_authorizations'
39
+
40
+ as authorizations: 'custom_auth',
41
+ tokens: 'custom_token',
42
+ token_info: 'custom_token_info'
43
+
44
+ skip_controllers :tokens, :applications, :token_info
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ after :all do
51
+ Rails.application.routes.clear!
52
+
53
+ load File.expand_path('../dummy/config/routes.rb', __dir__)
54
+ end
55
+
56
+ it 'GET /inner_space/scope/authorize routes to custom authorizations controller' do
5
57
  expect(get('/inner_space/scope/authorize')).to route_to('custom_authorizations#new')
6
58
  end
7
59
 
8
- it 'POST /space/scope/authorize routes to custom authorizations controller' do
60
+ it 'POST /inner_space/scope/authorize routes to custom authorizations controller' do
9
61
  expect(post('/inner_space/scope/authorize')).to route_to('custom_authorizations#create')
10
62
  end
11
63
 
12
- it 'DELETE /space/scope/authorize routes to custom authorizations controller' do
64
+ it 'DELETE /inner_space/scope/authorize routes to custom authorizations controller' do
13
65
  expect(delete('/inner_space/scope/authorize')).to route_to('custom_authorizations#destroy')
14
66
  end
15
67
 
16
- it 'POST /space/scope/token routes to tokens controller' do
68
+ it 'POST /inner_space/scope/token routes to tokens controller' do
17
69
  expect(post('/inner_space/scope/token')).to route_to('custom_authorizations#create')
18
70
  end
19
71
 
20
- it 'GET /space/scope/applications routes to applications controller' do
72
+ it 'GET /inner_space/scope/applications routes to applications controller' do
21
73
  expect(get('/inner_space/scope/applications')).to route_to('custom_authorizations#index')
22
74
  end
23
75
 
24
- it 'GET /space/scope/token/info routes to the token_info controller' do
76
+ it 'GET /inner_space/scope/token/info routes to the token_info controller' do
25
77
  expect(get('/inner_space/scope/token/info')).to route_to('custom_authorizations#show')
26
78
  end
27
79
 
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
 
3
3
  describe 'Default routes' do
4
4
  it 'GET /oauth/authorize routes to authorizations controller' do
@@ -33,7 +33,7 @@ describe 'Default routes' do
33
33
  expect(get('/oauth/authorized_applications')).to route_to('doorkeeper/authorized_applications#index')
34
34
  end
35
35
 
36
- it 'GET /oauth/token/info route to authorized tokeninfo controller' do
36
+ it 'GET /oauth/token/info route to authorized TokenInfo controller' do
37
37
  expect(get('/oauth/token/info')).to route_to('doorkeeper/token_info#show')
38
38
  end
39
39
  end
@@ -1,6 +1,20 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
 
3
3
  describe 'Scoped routes' do
4
+ before :all do
5
+ Rails.application.routes.disable_clear_and_finalize = true
6
+
7
+ Rails.application.routes.draw do
8
+ use_doorkeeper scope: 'scope'
9
+ end
10
+ end
11
+
12
+ after :all do
13
+ Rails.application.routes.clear!
14
+
15
+ load File.expand_path('../dummy/config/routes.rb', __dir__)
16
+ end
17
+
4
18
  it 'GET /scope/authorize routes to authorizations controller' do
5
19
  expect(get('/scope/authorize')).to route_to('doorkeeper/authorizations#new')
6
20
  end
@@ -25,7 +39,7 @@ describe 'Scoped routes' do
25
39
  expect(get('/scope/authorized_applications')).to route_to('doorkeeper/authorized_applications#index')
26
40
  end
27
41
 
28
- it 'GET /scope/token/info route to authorzed tokeninfo controller' do
42
+ it 'GET /scope/token/info route to authorized TokenInfo controller' do
29
43
  expect(get('/scope/token/info')).to route_to('doorkeeper/token_info#show')
30
44
  end
31
45
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,55 @@
1
- $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '../lib'))
2
- $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '../app'))
1
+ require 'coveralls'
3
2
 
4
- require 'doorkeeper'
3
+ Coveralls.wear!('rails') do
4
+ add_filter('/spec/')
5
+ add_filter('/lib/generators/doorkeeper/templates/')
6
+ end
7
+
8
+ ENV['RAILS_ENV'] ||= 'test'
9
+
10
+ $LOAD_PATH.unshift File.dirname(__FILE__)
11
+
12
+ require "#{File.dirname(__FILE__)}/support/doorkeeper_rspec.rb"
13
+
14
+ DOORKEEPER_ORM = Doorkeeper::RSpec.detect_orm
15
+
16
+ require 'dummy/config/environment'
17
+ require 'rspec/rails'
18
+ require 'capybara/rspec'
19
+ require 'database_cleaner'
20
+ require 'generator_spec/test_case'
21
+
22
+ # Load JRuby SQLite3 if in that platform
23
+ if defined? JRUBY_VERSION
24
+ require 'jdbc/sqlite3'
25
+ Jdbc::SQLite3.load_driver
26
+ end
27
+
28
+ Doorkeeper::RSpec.print_configuration_info
29
+
30
+ # Remove after dropping support of Rails 4.2
31
+ require "#{File.dirname(__FILE__)}/support/http_method_shim.rb"
32
+
33
+ require "support/orm/#{DOORKEEPER_ORM}"
34
+
35
+ Dir["#{File.dirname(__FILE__)}/support/{dependencies,helpers,shared}/*.rb"].each { |file| require file }
36
+
37
+ RSpec.configure do |config|
38
+ config.infer_spec_type_from_file_location!
39
+ config.mock_with :rspec
40
+
41
+ config.infer_base_class_for_anonymous_controllers = false
42
+
43
+ config.include RSpec::Rails::RequestExampleGroup, type: :request
44
+
45
+ config.before do
46
+ DatabaseCleaner.start
47
+ Doorkeeper.configure { orm DOORKEEPER_ORM }
48
+ end
49
+
50
+ config.after do
51
+ DatabaseCleaner.clean
52
+ end
53
+
54
+ config.order = 'random'
55
+ end
@@ -1,74 +1,2 @@
1
- if ENV['TRAVIS']
2
- require 'coveralls'
3
-
4
- Coveralls.wear!('rails') do
5
- add_filter('/spec/')
6
- add_filter('/lib/generators/doorkeeper/templates/')
7
- end
8
- else
9
- require 'simplecov'
10
-
11
- SimpleCov.start do
12
- add_filter('/spec/')
13
- add_filter('/lib/generators/doorkeeper/templates/')
14
- end
15
- end
16
-
17
- ENV['RAILS_ENV'] ||= 'test'
18
- TABLE_NAME_PREFIX = ENV['table_name_prefix'] || nil
19
- TABLE_NAME_SUFFIX = ENV['table_name_suffix'] || nil
20
-
21
- orm = (ENV['BUNDLE_GEMFILE'] || '').match(/Gemfile\.(.+)\.rb/)
22
- DOORKEEPER_ORM = (orm && orm[1] || :active_record).to_sym
23
-
24
- $LOAD_PATH.unshift File.dirname(__FILE__)
25
-
26
- require 'capybara/rspec'
27
- require 'dummy/config/environment'
28
- require 'rspec/rails'
29
- require 'generator_spec/test_case'
30
- require 'database_cleaner'
31
-
32
- # Load JRuby SQLite3 if in that platform
33
- begin
34
- require 'jdbc/sqlite3'
35
- Jdbc::SQLite3.load_driver
36
- rescue LoadError
37
- end
38
-
39
- Rails.logger.info "====> Doorkeeper.orm = #{Doorkeeper.configuration.orm}"
40
- if Doorkeeper.configuration.orm == :active_record
41
- Rails.logger.info "======> active_record.table_name_prefix = #{Rails.configuration.active_record.table_name_prefix}"
42
- Rails.logger.info "======> active_record.table_name_suffix = #{Rails.configuration.active_record.table_name_suffix}"
43
- end
44
- Rails.logger.info "====> Rails version: #{Rails.version}"
45
- Rails.logger.info "====> Ruby version: #{RUBY_VERSION}"
46
-
47
- require "support/orm/#{DOORKEEPER_ORM}"
48
-
49
- ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../')
50
-
51
- Dir["#{File.dirname(__FILE__)}/support/{dependencies,helpers,shared}/*.rb"].each { |f| require f }
52
-
53
- # Remove after dropping support of Rails 4.2
54
- require "#{File.dirname(__FILE__)}/support/http_method_shim.rb"
55
-
56
- RSpec.configure do |config|
57
- config.infer_spec_type_from_file_location!
58
- config.mock_with :rspec
59
-
60
- config.infer_base_class_for_anonymous_controllers = false
61
-
62
- config.include RSpec::Rails::RequestExampleGroup, type: :request
63
-
64
- config.before do
65
- DatabaseCleaner.start
66
- Doorkeeper.configure { orm DOORKEEPER_ORM }
67
- end
68
-
69
- config.after do
70
- DatabaseCleaner.clean
71
- end
72
-
73
- config.order = 'random'
74
- end
1
+ # For compatibility only
2
+ require 'spec_helper'
@@ -0,0 +1,19 @@
1
+ module Doorkeeper
2
+ class RSpec
3
+ # Print's useful information about env: Ruby / Rails versions,
4
+ # Doorkeeper configuration, etc.
5
+ def self.print_configuration_info
6
+ puts <<-INFO.strip_heredoc
7
+ ====> Doorkeeper ORM = #{Doorkeeper.configuration.orm}
8
+ ====> Rails version: #{::Rails.version}
9
+ ====> Ruby version: #{RUBY_VERSION} on #{RUBY_PLATFORM}
10
+ INFO
11
+ end
12
+
13
+ # Tries to find ORM from the Gemfile used to run test suite
14
+ def self.detect_orm
15
+ orm = (ENV['BUNDLE_GEMFILE'] || '').match(/Gemfile\.(.+)\.rb/)
16
+ (orm && orm[1] || :active_record).to_sym
17
+ end
18
+ end
19
+ end
@@ -28,13 +28,13 @@ module AuthorizationRequestHelper
28
28
  expect(client.redirect_uri).to eq("#{current_uri.scheme}://#{current_uri.host}#{current_uri.path}")
29
29
  end
30
30
 
31
- def allowing_forgery_protection(&block)
32
- _original_value = ActionController::Base.allow_forgery_protection
31
+ def allowing_forgery_protection(&_block)
32
+ original_value = ActionController::Base.allow_forgery_protection
33
33
  ActionController::Base.allow_forgery_protection = true
34
34
 
35
- block.call
35
+ yield
36
36
  ensure
37
- ActionController::Base.allow_forgery_protection = _original_value
37
+ ActionController::Base.allow_forgery_protection = original_value
38
38
  end
39
39
  end
40
40
 
@@ -1,4 +1,8 @@
1
1
  module RequestSpecHelper
2
+ def i_am_logged_in
3
+ allow(Doorkeeper.configuration).to receive(:authenticate_admin).and_return(->(*) {})
4
+ end
5
+
2
6
  def i_should_see(content)
3
7
  expect(page).to have_content(content)
4
8
  end
@@ -39,6 +43,10 @@ module RequestSpecHelper
39
43
  expect(headers[header]).to eq(value)
40
44
  end
41
45
 
46
+ def should_have_status(status)
47
+ expect(page.driver.response.status).to eq(status)
48
+ end
49
+
42
50
  def with_access_token_header(token)
43
51
  with_header 'Authorization', "Bearer #{token}"
44
52
  end
@@ -68,8 +76,8 @@ module RequestSpecHelper
68
76
  click_on 'Sign in'
69
77
  end
70
78
 
71
- def create_access_token(authorization_code, client)
72
- page.driver.post token_endpoint_url(code: authorization_code, client: client)
79
+ def create_access_token(authorization_code, client, code_verifier = nil)
80
+ page.driver.post token_endpoint_url(code: authorization_code, client: client, code_verifier: code_verifier)
73
81
  end
74
82
 
75
83
  def i_should_see_translated_error_message(key)
@@ -5,8 +5,10 @@ module UrlHelper
5
5
  client_id: options[:client_id] || (options[:client] ? options[:client].uid : nil),
6
6
  client_secret: options[:client_secret] || (options[:client] ? options[:client].secret : nil),
7
7
  redirect_uri: options[:redirect_uri] || (options[:client] ? options[:client].redirect_uri : nil),
8
- grant_type: options[:grant_type] || 'authorization_code'
9
- }
8
+ grant_type: options[:grant_type] || 'authorization_code',
9
+ code_verifier: options[:code_verifier],
10
+ code_challenge_method: options[:code_challenge_method]
11
+ }.reject { |_, v| v.blank? }
10
12
  "/oauth/token?#{build_query(parameters)}"
11
13
  end
12
14
 
@@ -29,7 +31,9 @@ module UrlHelper
29
31
  redirect_uri: options[:redirect_uri] || options[:client].redirect_uri,
30
32
  response_type: options[:response_type] || 'code',
31
33
  scope: options[:scope],
32
- state: options[:state]
34
+ state: options[:state],
35
+ code_challenge: options[:code_challenge],
36
+ code_challenge_method: options[:code_challenge_method]
33
37
  }.reject { |_, v| v.blank? }
34
38
  "/oauth/authorize?#{build_query(parameters)}"
35
39
  end
@@ -3,34 +3,30 @@
3
3
  # supported in Rails 5+. Since we support back to 4, we need some sort of shim
4
4
  # to avoid super noisy deprecations when running tests.
5
5
  module RoutingHTTPMethodShim
6
- def get(path, params = {}, headers = nil)
7
- super(path, params: params, headers: headers)
6
+ def get(path, **args)
7
+ super(path, args[:params], args[:headers])
8
8
  end
9
9
 
10
- def post(path, params = {}, headers = nil)
11
- super(path, params: params, headers: headers)
10
+ def post(path, **args)
11
+ super(path, args[:params], args[:headers])
12
12
  end
13
13
 
14
- def put(path, params = {}, headers = nil)
15
- super(path, params: params, headers: headers)
14
+ def put(path, **args)
15
+ super(path, args[:params], args[:headers])
16
16
  end
17
17
  end
18
18
 
19
19
  module ControllerHTTPMethodShim
20
- def get(path, params = {})
21
- super(path, params: params)
22
- end
23
-
24
- def post(path, params = {})
25
- super(path, params: params)
26
- end
20
+ def process(action, http_method = 'GET', **args)
21
+ if (as = args.delete(:as))
22
+ @request.headers['Content-Type'] = Mime[as].to_s
23
+ end
27
24
 
28
- def put(path, params = {})
29
- super(path, params: params)
25
+ super(action, http_method, args[:params], args[:session], args[:flash])
30
26
  end
31
27
  end
32
28
 
33
- if ::Rails::VERSION::MAJOR >= 5
29
+ if ::Rails::VERSION::MAJOR < 5
34
30
  RSpec.configure do |config|
35
31
  config.include ControllerHTTPMethodShim, type: :controller
36
32
  config.include RoutingHTTPMethodShim, type: :request
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
 
3
3
  describe RedirectUriValidator do
4
4
  subject do
@@ -87,8 +87,14 @@ describe RedirectUriValidator do
87
87
  application = FactoryBot.build(:application, redirect_uri: 'http://localhost/callback')
88
88
  expect(application).to be_valid
89
89
 
90
+ application = FactoryBot.build(:application, redirect_uri: 'https://test.com/callback')
91
+ expect(application).to be_valid
92
+
90
93
  application = FactoryBot.build(:application, redirect_uri: 'http://localhost2/callback')
91
94
  expect(application).not_to be_valid
95
+
96
+ application = FactoryBot.build(:application, redirect_uri: 'https://test.com/callback')
97
+ expect(application).to be_valid
92
98
  end
93
99
 
94
100
  it 'forbids redirect uri if required' do
@@ -1,6 +1,6 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
 
3
- describe 'Doorkeeper version' do
3
+ describe Doorkeeper::VERSION do
4
4
  context '#gem_version' do
5
5
  it 'returns Gem::Version instance' do
6
6
  expect(Doorkeeper.gem_version).to be_an_instance_of(Gem::Version)
@@ -9,7 +9,7 @@ describe 'Doorkeeper version' do
9
9
 
10
10
  context 'VERSION' do
11
11
  it 'returns gem version string' do
12
- expect(Doorkeeper::VERSION::STRING).to match(/^\d+\.\d+\.\d+[.\w]?$/)
12
+ expect(Doorkeeper::VERSION::STRING).to match(/^\d+\.\d+\.\d+(\.\w+)?$/)
13
13
  end
14
14
  end
15
15
  end