doorkeeper 4.3.2 → 5.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +4 -0
  4. data/.travis.yml +2 -0
  5. data/Appraisals +2 -2
  6. data/Gemfile +1 -1
  7. data/NEWS.md +36 -0
  8. data/README.md +85 -3
  9. data/Rakefile +6 -0
  10. data/app/assets/stylesheets/doorkeeper/admin/application.css +2 -2
  11. data/app/controllers/doorkeeper/application_controller.rb +4 -3
  12. data/app/controllers/doorkeeper/application_metal_controller.rb +4 -0
  13. data/app/controllers/doorkeeper/applications_controller.rb +43 -22
  14. data/app/controllers/doorkeeper/authorizations_controller.rb +55 -12
  15. data/app/controllers/doorkeeper/authorized_applications_controller.rb +15 -1
  16. data/app/controllers/doorkeeper/tokens_controller.rb +2 -6
  17. data/app/helpers/doorkeeper/dashboard_helper.rb +7 -7
  18. data/app/validators/redirect_uri_validator.rb +3 -2
  19. data/app/views/doorkeeper/applications/_delete_form.html.erb +3 -1
  20. data/app/views/doorkeeper/applications/_form.html.erb +31 -19
  21. data/app/views/doorkeeper/applications/edit.html.erb +1 -1
  22. data/app/views/doorkeeper/applications/index.html.erb +18 -6
  23. data/app/views/doorkeeper/applications/new.html.erb +1 -1
  24. data/app/views/doorkeeper/applications/show.html.erb +8 -5
  25. data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
  26. data/app/views/doorkeeper/authorizations/new.html.erb +4 -0
  27. data/app/views/layouts/doorkeeper/admin.html.erb +15 -15
  28. data/config/locales/en.yml +15 -1
  29. data/gemfiles/rails_5_2.gemfile +1 -1
  30. data/lib/doorkeeper/config.rb +60 -23
  31. data/lib/doorkeeper/engine.rb +4 -0
  32. data/lib/doorkeeper/errors.rb +2 -5
  33. data/lib/doorkeeper/grape/helpers.rb +1 -1
  34. data/lib/doorkeeper/helpers/controller.rb +7 -2
  35. data/lib/doorkeeper/models/access_grant_mixin.rb +56 -0
  36. data/lib/doorkeeper/models/access_token_mixin.rb +37 -20
  37. data/lib/doorkeeper/models/application_mixin.rb +8 -1
  38. data/lib/doorkeeper/models/concerns/scopes.rb +1 -1
  39. data/lib/doorkeeper/oauth/authorization/code.rb +31 -8
  40. data/lib/doorkeeper/oauth/authorization/context.rb +15 -0
  41. data/lib/doorkeeper/oauth/authorization/token.rb +23 -6
  42. data/lib/doorkeeper/oauth/authorization_code_request.rb +27 -2
  43. data/lib/doorkeeper/oauth/base_request.rb +18 -8
  44. data/lib/doorkeeper/oauth/client/credentials.rb +4 -2
  45. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +6 -1
  46. data/lib/doorkeeper/oauth/client_credentials/validation.rb +4 -2
  47. data/lib/doorkeeper/oauth/error_response.rb +11 -3
  48. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +0 -8
  49. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +1 -0
  50. data/lib/doorkeeper/oauth/password_access_token_request.rb +7 -4
  51. data/lib/doorkeeper/oauth/pre_authorization.rb +45 -13
  52. data/lib/doorkeeper/oauth/refresh_token_request.rb +6 -1
  53. data/lib/doorkeeper/oauth/scopes.rb +1 -1
  54. data/lib/doorkeeper/oauth/token.rb +5 -2
  55. data/lib/doorkeeper/oauth/token_introspection.rb +2 -2
  56. data/lib/doorkeeper/oauth/token_response.rb +4 -2
  57. data/lib/doorkeeper/oauth.rb +13 -0
  58. data/lib/doorkeeper/orm/active_record/application.rb +14 -0
  59. data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +26 -0
  60. data/lib/doorkeeper/orm/active_record.rb +2 -0
  61. data/lib/doorkeeper/rails/helpers.rb +2 -4
  62. data/lib/doorkeeper/rails/routes.rb +13 -1
  63. data/lib/doorkeeper/rake/db.rake +40 -0
  64. data/lib/doorkeeper/rake/setup.rake +6 -0
  65. data/lib/doorkeeper/rake.rb +14 -0
  66. data/lib/doorkeeper/request/password.rb +1 -11
  67. data/lib/doorkeeper/request.rb +28 -28
  68. data/lib/doorkeeper/version.rb +5 -4
  69. data/lib/doorkeeper.rb +4 -17
  70. data/lib/generators/doorkeeper/application_owner_generator.rb +23 -18
  71. data/lib/generators/doorkeeper/confidential_applications_generator.rb +32 -0
  72. data/lib/generators/doorkeeper/install_generator.rb +17 -9
  73. data/lib/generators/doorkeeper/migration_generator.rb +23 -18
  74. data/lib/generators/doorkeeper/pkce_generator.rb +32 -0
  75. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -24
  76. data/lib/generators/doorkeeper/templates/add_confidential_to_applications.rb.erb +13 -0
  77. data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +6 -0
  78. data/lib/generators/doorkeeper/templates/initializer.rb +60 -9
  79. data/lib/generators/doorkeeper/templates/migration.rb.erb +1 -0
  80. data/lib/generators/doorkeeper/views_generator.rb +3 -1
  81. data/spec/controllers/application_metal_controller_spec.rb +50 -0
  82. data/spec/controllers/applications_controller_spec.rb +126 -13
  83. data/spec/controllers/authorizations_controller_spec.rb +250 -15
  84. data/spec/controllers/protected_resources_controller_spec.rb +16 -16
  85. data/spec/controllers/token_info_controller_spec.rb +4 -12
  86. data/spec/controllers/tokens_controller_spec.rb +12 -14
  87. data/spec/dummy/app/assets/config/manifest.js +2 -0
  88. data/spec/dummy/config/environments/test.rb +4 -5
  89. data/spec/dummy/config/initializers/doorkeeper.rb +6 -0
  90. data/spec/dummy/config/initializers/new_framework_defaults.rb +4 -0
  91. data/spec/dummy/config/routes.rb +3 -42
  92. data/spec/dummy/db/migrate/20111122132257_create_users.rb +3 -1
  93. data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +3 -1
  94. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +3 -1
  95. data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +3 -1
  96. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +3 -1
  97. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +6 -0
  98. data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +13 -0
  99. data/spec/dummy/db/schema.rb +38 -37
  100. data/spec/generators/application_owner_generator_spec.rb +1 -1
  101. data/spec/generators/confidential_applications_generator_spec.rb +45 -0
  102. data/spec/generators/install_generator_spec.rb +1 -1
  103. data/spec/generators/migration_generator_spec.rb +1 -1
  104. data/spec/generators/pkce_generator_spec.rb +43 -0
  105. data/spec/generators/previous_refresh_token_generator_spec.rb +1 -1
  106. data/spec/generators/views_generator_spec.rb +1 -1
  107. data/spec/grape/grape_integration_spec.rb +1 -1
  108. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
  109. data/spec/lib/config_spec.rb +59 -14
  110. data/spec/lib/doorkeeper_spec.rb +1 -126
  111. data/spec/lib/models/expirable_spec.rb +0 -3
  112. data/spec/lib/models/revocable_spec.rb +0 -2
  113. data/spec/lib/models/scopes_spec.rb +0 -4
  114. data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -4
  115. data/spec/lib/oauth/authorization_code_request_spec.rb +24 -2
  116. data/spec/lib/oauth/base_request_spec.rb +16 -2
  117. data/spec/lib/oauth/base_response_spec.rb +1 -1
  118. data/spec/lib/oauth/client/credentials_spec.rb +5 -5
  119. data/spec/lib/oauth/client_credentials/creator_spec.rb +5 -1
  120. data/spec/lib/oauth/client_credentials/issuer_spec.rb +26 -7
  121. data/spec/lib/oauth/client_credentials/validation_spec.rb +2 -3
  122. data/spec/lib/oauth/client_credentials_integration_spec.rb +1 -1
  123. data/spec/lib/oauth/client_credentials_request_spec.rb +3 -5
  124. data/spec/lib/oauth/client_spec.rb +0 -3
  125. data/spec/lib/oauth/code_request_spec.rb +4 -2
  126. data/spec/lib/oauth/error_response_spec.rb +0 -3
  127. data/spec/lib/oauth/error_spec.rb +0 -2
  128. data/spec/lib/oauth/forbidden_token_response_spec.rb +1 -4
  129. data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -3
  130. data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -1
  131. data/spec/lib/oauth/helpers/uri_checker_spec.rb +5 -2
  132. data/spec/lib/oauth/invalid_token_response_spec.rb +1 -4
  133. data/spec/lib/oauth/password_access_token_request_spec.rb +37 -2
  134. data/spec/lib/oauth/pre_authorization_spec.rb +40 -6
  135. data/spec/lib/oauth/refresh_token_request_spec.rb +11 -7
  136. data/spec/lib/oauth/scopes_spec.rb +0 -3
  137. data/spec/lib/oauth/token_request_spec.rb +4 -5
  138. data/spec/lib/oauth/token_response_spec.rb +0 -1
  139. data/spec/lib/oauth/token_spec.rb +37 -14
  140. data/spec/lib/orm/active_record/stale_records_cleaner_spec.rb +79 -0
  141. data/spec/lib/request/strategy_spec.rb +0 -1
  142. data/spec/lib/server_spec.rb +1 -1
  143. data/spec/models/doorkeeper/access_grant_spec.rb +1 -1
  144. data/spec/models/doorkeeper/access_token_spec.rb +50 -16
  145. data/spec/models/doorkeeper/application_spec.rb +51 -6
  146. data/spec/requests/applications/applications_request_spec.rb +89 -1
  147. data/spec/requests/applications/authorized_applications_spec.rb +1 -1
  148. data/spec/requests/endpoints/authorization_spec.rb +1 -1
  149. data/spec/requests/endpoints/token_spec.rb +7 -5
  150. data/spec/requests/flows/authorization_code_errors_spec.rb +1 -1
  151. data/spec/requests/flows/authorization_code_spec.rb +197 -1
  152. data/spec/requests/flows/client_credentials_spec.rb +46 -6
  153. data/spec/requests/flows/implicit_grant_errors_spec.rb +1 -1
  154. data/spec/requests/flows/implicit_grant_spec.rb +38 -11
  155. data/spec/requests/flows/password_spec.rb +120 -23
  156. data/spec/requests/flows/refresh_token_spec.rb +2 -2
  157. data/spec/requests/flows/revoke_token_spec.rb +11 -11
  158. data/spec/requests/flows/skip_authorization_spec.rb +16 -11
  159. data/spec/requests/protected_resources/metal_spec.rb +1 -1
  160. data/spec/requests/protected_resources/private_api_spec.rb +1 -1
  161. data/spec/routing/custom_controller_routes_spec.rb +59 -7
  162. data/spec/routing/default_routes_spec.rb +2 -2
  163. data/spec/routing/scoped_routes_spec.rb +16 -2
  164. data/spec/spec_helper.rb +54 -3
  165. data/spec/spec_helper_integration.rb +2 -74
  166. data/spec/support/doorkeeper_rspec.rb +19 -0
  167. data/spec/support/helpers/authorization_request_helper.rb +4 -4
  168. data/spec/support/helpers/request_spec_helper.rb +2 -2
  169. data/spec/support/helpers/url_helper.rb +7 -3
  170. data/spec/support/http_method_shim.rb +12 -16
  171. data/spec/validators/redirect_uri_validator_spec.rb +7 -1
  172. data/spec/version/version_spec.rb +3 -3
  173. data/vendor/assets/stylesheets/doorkeeper/bootstrap.min.css +4 -5
  174. metadata +32 -8
  175. data/spec/controllers/application_metal_controller.rb +0 -10
  176. /data/spec/support/dependencies/{factory_girl.rb → factory_bot.rb} +0 -0
@@ -3,4 +3,8 @@
3
3
  # made on earlier versions of Rails are not affected when upgrading.
4
4
  if Rails::VERSION::MAJOR >= 5
5
5
  Rails.application.config.active_record.belongs_to_required_by_default = true
6
+
7
+ if Rails::VERSION::MINOR >= 2
8
+ Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
9
+ end
6
10
  end
@@ -1,52 +1,13 @@
1
1
  Rails.application.routes.draw do
2
2
  use_doorkeeper
3
- use_doorkeeper scope: 'scope'
4
3
 
5
- scope 'inner_space' do
6
- use_doorkeeper scope: 'scope' do
7
- controllers authorizations: 'custom_authorizations',
8
- tokens: 'custom_authorizations',
9
- applications: 'custom_authorizations',
10
- token_info: 'custom_authorizations'
11
-
12
- as authorizations: 'custom_auth',
13
- tokens: 'custom_token',
14
- token_info: 'custom_token_info'
15
- end
16
- end
17
-
18
- scope 'space' do
19
- use_doorkeeper do
20
- controllers authorizations: 'custom_authorizations',
21
- tokens: 'custom_authorizations',
22
- applications: 'custom_authorizations',
23
- token_info: 'custom_authorizations'
24
-
25
- as authorizations: 'custom_auth',
26
- tokens: 'custom_token',
27
- token_info: 'custom_token_info'
28
- end
29
- end
30
-
31
- scope 'outer_space' do
32
- use_doorkeeper do
33
- controllers authorizations: 'custom_authorizations',
34
- tokens: 'custom_authorizations',
35
- token_info: 'custom_authorizations'
36
-
37
- as authorizations: 'custom_auth',
38
- tokens: 'custom_token',
39
- token_info: 'custom_token_info'
40
-
41
- skip_controllers :tokens, :applications, :token_info
42
- end
43
- end
4
+ resources :semi_protected_resources
5
+ resources :full_protected_resources
44
6
 
45
7
  get 'metal.json' => 'metal#index'
46
8
 
47
9
  get '/callback', to: 'home#callback'
48
10
  get '/sign_in', to: 'home#sign_in'
49
- resources :semi_protected_resources
50
- resources :full_protected_resources
11
+
51
12
  root to: 'home#index'
52
13
  end
@@ -1,4 +1,6 @@
1
- class CreateUsers < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class CreateUsers < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  create_table :users do |t|
4
6
  t.string :name
@@ -1,4 +1,6 @@
1
- class AddPasswordToUsers < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class AddPasswordToUsers < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  add_column :users, :password, :string
4
6
  end
@@ -1,4 +1,6 @@
1
- class CreateDoorkeeperTables < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class CreateDoorkeeperTables < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  create_table :oauth_applications do |t|
4
6
  t.string :name, null: false
@@ -1,4 +1,6 @@
1
- class AddOwnerToApplication < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class AddOwnerToApplication < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  add_column :oauth_applications, :owner_id, :integer, null: true
4
6
  add_column :oauth_applications, :owner_type, :string, null: true
@@ -1,4 +1,6 @@
1
- class AddPreviousRefreshTokenToAccessTokens < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class AddPreviousRefreshTokenToAccessTokens < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  add_column(
4
6
  :oauth_access_tokens,
@@ -0,0 +1,6 @@
1
+ class EnablePkce < ActiveRecord::Migration[4.2]
2
+ def change
3
+ add_column :oauth_access_grants, :code_challenge, :string, null: true
4
+ add_column :oauth_access_grants, :code_challenge_method, :string, null: true
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddConfidentialToApplications < ActiveRecord::Migration[5.1]
4
+ def change
5
+ add_column(
6
+ :oauth_applications,
7
+ :confidential,
8
+ :boolean,
9
+ null: false,
10
+ default: true # maintaining backwards compatibility: require secrets
11
+ )
12
+ end
13
+ end
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  # This file is auto-generated from the current state of the database. Instead
3
2
  # of editing this file, please use the migrations feature of Active Record to
4
3
  # incrementally modify your database, and then regenerate this schema definition.
@@ -11,57 +10,59 @@
11
10
  #
12
11
  # It's strongly recommended that you check this file into your version control system.
13
12
 
14
- ActiveRecord::Schema.define(version: 20160320211015) do
13
+ ActiveRecord::Schema.define(version: 20180210183654) do
15
14
 
16
15
  create_table "oauth_access_grants", force: :cascade do |t|
17
- t.integer "resource_owner_id", null: false
18
- t.integer "application_id", null: false
19
- t.string "token", null: false
20
- t.integer "expires_in", null: false
21
- t.text "redirect_uri", null: false
22
- t.datetime "created_at", null: false
16
+ t.integer "resource_owner_id", null: false
17
+ t.integer "application_id", null: false
18
+ t.string "token", null: false
19
+ t.integer "expires_in", null: false
20
+ t.text "redirect_uri", null: false
21
+ t.datetime "created_at", null: false
23
22
  t.datetime "revoked_at"
24
- t.string "scopes"
23
+ t.string "scopes"
24
+ unless ENV['WITHOUT_PKCE']
25
+ t.string "code_challenge"
26
+ t.string "code_challenge_method"
27
+ end
28
+ t.index ["token"], name: "index_oauth_access_grants_on_token", unique: true
25
29
  end
26
30
 
27
- add_index "oauth_access_grants", ["token"], name: "index_oauth_access_grants_on_token", unique: true
28
-
29
31
  create_table "oauth_access_tokens", force: :cascade do |t|
30
- t.integer "resource_owner_id"
31
- t.integer "application_id"
32
- t.string "token", null: false
33
- t.string "refresh_token"
34
- t.integer "expires_in"
32
+ t.integer "resource_owner_id"
33
+ t.integer "application_id"
34
+ t.string "token", null: false
35
+ t.string "refresh_token"
36
+ t.integer "expires_in"
35
37
  t.datetime "revoked_at"
36
- t.datetime "created_at", null: false
37
- t.string "scopes"
38
- t.string "previous_refresh_token", default: "", null: false
38
+ t.datetime "created_at", null: false
39
+ t.string "scopes"
40
+ t.string "previous_refresh_token", default: "", null: false
41
+ t.index ["refresh_token"], name: "index_oauth_access_tokens_on_refresh_token", unique: true
42
+ t.index ["resource_owner_id"], name: "index_oauth_access_tokens_on_resource_owner_id"
43
+ t.index ["token"], name: "index_oauth_access_tokens_on_token", unique: true
39
44
  end
40
45
 
41
- add_index "oauth_access_tokens", ["refresh_token"], name: "index_oauth_access_tokens_on_refresh_token", unique: true
42
- add_index "oauth_access_tokens", ["resource_owner_id"], name: "index_oauth_access_tokens_on_resource_owner_id"
43
- add_index "oauth_access_tokens", ["token"], name: "index_oauth_access_tokens_on_token", unique: true
44
-
45
46
  create_table "oauth_applications", force: :cascade do |t|
46
- t.string "name", null: false
47
- t.string "uid", null: false
48
- t.string "secret", null: false
49
- t.text "redirect_uri", null: false
50
- t.string "scopes", default: "", null: false
51
- t.datetime "created_at"
52
- t.datetime "updated_at"
53
- t.integer "owner_id"
54
- t.string "owner_type"
47
+ t.string "name", null: false
48
+ t.string "uid", null: false
49
+ t.string "secret", null: false
50
+ t.text "redirect_uri", null: false
51
+ t.string "scopes", default: "", null: false
52
+ t.datetime "created_at", null: false
53
+ t.datetime "updated_at", null: false
54
+ t.integer "owner_id"
55
+ t.string "owner_type"
56
+ t.boolean "confidential", default: true, null: false
57
+ t.index ["owner_id", "owner_type"], name: "index_oauth_applications_on_owner_id_and_owner_type"
58
+ t.index ["uid"], name: "index_oauth_applications_on_uid", unique: true
55
59
  end
56
60
 
57
- add_index "oauth_applications", ["owner_id", "owner_type"], name: "index_oauth_applications_on_owner_id_and_owner_type"
58
- add_index "oauth_applications", ["uid"], name: "index_oauth_applications_on_uid", unique: true
59
-
60
61
  create_table "users", force: :cascade do |t|
61
- t.string "name"
62
+ t.string "name"
62
63
  t.datetime "created_at"
63
64
  t.datetime "updated_at"
64
- t.string "password"
65
+ t.string "password"
65
66
  end
66
67
 
67
68
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
  require 'generators/doorkeeper/application_owner_generator'
3
3
 
4
4
  describe 'Doorkeeper::ApplicationOwnerGenerator' do
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'generators/doorkeeper/confidential_applications_generator'
5
+
6
+ describe 'Doorkeeper::ConfidentialApplicationsGenerator' do
7
+ include GeneratorSpec::TestCase
8
+
9
+ tests Doorkeeper::ConfidentialApplicationsGenerator
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/add_confidential_to_applications.rb' do |migration|
25
+ assert migration.include?("ActiveRecord::Migration\n")
26
+ assert migration.include?(':confidential')
27
+ end
28
+ end
29
+ end
30
+
31
+ context 'post Rails 5.0.0' do
32
+ it 'creates a migration with a version specifier' do
33
+ stub_const("ActiveRecord::VERSION::MAJOR", 5)
34
+ stub_const("ActiveRecord::VERSION::MINOR", 0)
35
+
36
+ run_generator
37
+
38
+ assert_migration 'db/migrate/add_confidential_to_applications.rb' do |migration|
39
+ assert migration.include?("ActiveRecord::Migration[5.0]\n")
40
+ assert migration.include?(':confidential')
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
  require 'generators/doorkeeper/install_generator'
3
3
 
4
4
  describe 'Doorkeeper::InstallGenerator' do
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
  require 'generators/doorkeeper/migration_generator'
3
3
 
4
4
  describe 'Doorkeeper::MigrationGenerator' do
@@ -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,4 +1,4 @@
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
@@ -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'
@@ -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 }
@@ -122,7 +122,7 @@ describe Doorkeeper, 'configuration' do
122
122
  it 'has all scopes' do
123
123
  Doorkeeper.configure do
124
124
  orm DOORKEEPER_ORM
125
- default_scopes :normal
125
+ default_scopes :normal
126
126
  optional_scopes :admin
127
127
  end
128
128
 
@@ -132,7 +132,7 @@ describe Doorkeeper, 'configuration' do
132
132
 
133
133
  describe 'use_refresh_token' do
134
134
  it 'is false by default' do
135
- expect(subject.refresh_token_enabled?).to be_falsey
135
+ expect(subject.refresh_token_enabled?).to eq(false)
136
136
  end
137
137
 
138
138
  it 'can change the value' do
@@ -141,7 +141,7 @@ describe Doorkeeper, 'configuration' do
141
141
  use_refresh_token
142
142
  end
143
143
 
144
- expect(subject.refresh_token_enabled?).to be_truthy
144
+ expect(subject.refresh_token_enabled?).to eq(true)
145
145
  end
146
146
 
147
147
  it "does not includes 'refresh_token' in authorization_response_types" do
@@ -162,6 +162,21 @@ describe Doorkeeper, 'configuration' do
162
162
  end
163
163
  end
164
164
 
165
+ describe 'enforce_configured_scopes' do
166
+ it 'is false by default' do
167
+ expect(subject.enforce_configured_scopes?).to eq(false)
168
+ end
169
+
170
+ it 'can change the value' do
171
+ Doorkeeper.configure do
172
+ orm DOORKEEPER_ORM
173
+ enforce_configured_scopes
174
+ end
175
+
176
+ expect(subject.enforce_configured_scopes?).to eq(true)
177
+ end
178
+ end
179
+
165
180
  describe 'client_credentials' do
166
181
  it 'has defaults order' do
167
182
  expect(subject.client_credentials_methods).to eq([:from_basic, :from_params])
@@ -179,7 +194,7 @@ describe Doorkeeper, 'configuration' do
179
194
 
180
195
  describe 'force_ssl_in_redirect_uri' do
181
196
  it 'is true by default in non-development environments' do
182
- expect(subject.force_ssl_in_redirect_uri).to be_truthy
197
+ expect(subject.force_ssl_in_redirect_uri).to eq(true)
183
198
  end
184
199
 
185
200
  it 'can change the value' do
@@ -188,7 +203,7 @@ describe Doorkeeper, 'configuration' do
188
203
  force_ssl_in_redirect_uri(false)
189
204
  end
190
205
 
191
- expect(subject.force_ssl_in_redirect_uri).to be_falsey
206
+ expect(subject.force_ssl_in_redirect_uri).to eq(false)
192
207
  end
193
208
 
194
209
  it 'can be a callable object' do
@@ -199,7 +214,7 @@ describe Doorkeeper, 'configuration' do
199
214
  end
200
215
 
201
216
  expect(subject.force_ssl_in_redirect_uri).to eq(block)
202
- expect(subject.force_ssl_in_redirect_uri.call).to be_falsey
217
+ expect(subject.force_ssl_in_redirect_uri.call).to eq(false)
203
218
  end
204
219
  end
205
220
 
@@ -220,7 +235,7 @@ describe Doorkeeper, 'configuration' do
220
235
 
221
236
  describe 'forbid_redirect_uri' do
222
237
  it 'is false by default' do
223
- expect(subject.forbid_redirect_uri.call(URI.parse('https://localhost'))).to be_falsey
238
+ expect(subject.forbid_redirect_uri.call(URI.parse('https://localhost'))).to eq(false)
224
239
  end
225
240
 
226
241
  it 'can be a callable object' do
@@ -231,13 +246,13 @@ describe Doorkeeper, 'configuration' do
231
246
  end
232
247
 
233
248
  expect(subject.forbid_redirect_uri).to eq(block)
234
- expect(subject.forbid_redirect_uri.call).to be_truthy
249
+ expect(subject.forbid_redirect_uri.call).to eq(true)
235
250
  end
236
251
  end
237
252
 
238
253
  describe 'enable_application_owner' do
239
254
  it 'is disabled by default' do
240
- expect(Doorkeeper.configuration.enable_application_owner?).not_to be_truthy
255
+ expect(Doorkeeper.configuration.enable_application_owner?).not_to eq(true)
241
256
  end
242
257
 
243
258
  context 'when enabled without confirmation' do
@@ -253,7 +268,7 @@ describe Doorkeeper, 'configuration' do
253
268
  end
254
269
 
255
270
  it 'Doorkeeper.configuration.confirm_application_owner? returns false' do
256
- expect(Doorkeeper.configuration.confirm_application_owner?).not_to be_truthy
271
+ expect(Doorkeeper.configuration.confirm_application_owner?).not_to eq(true)
257
272
  end
258
273
  end
259
274
 
@@ -270,7 +285,7 @@ describe Doorkeeper, 'configuration' do
270
285
  end
271
286
 
272
287
  it 'Doorkeeper.configuration.confirm_application_owner? returns true' do
273
- expect(Doorkeeper.configuration.confirm_application_owner?).to be_truthy
288
+ expect(Doorkeeper.configuration.confirm_application_owner?).to eq(true)
274
289
  end
275
290
  end
276
291
  end
@@ -299,10 +314,10 @@ describe Doorkeeper, 'configuration' do
299
314
  it "can change the value" do
300
315
  Doorkeeper.configure do
301
316
  orm DOORKEEPER_ORM
302
- grant_flows ['authorization_code', 'implicit']
317
+ grant_flows %w[authorization_code implicit]
303
318
  end
304
319
 
305
- expect(subject.grant_flows).to eq ['authorization_code', 'implicit']
320
+ expect(subject.grant_flows).to eq %w[authorization_code implicit]
306
321
  end
307
322
 
308
323
  context "when including 'authorization_code'" do
@@ -434,4 +449,34 @@ describe Doorkeeper, 'configuration' do
434
449
  end
435
450
  end
436
451
  end
452
+
453
+ describe "api_only" do
454
+ it "is false by default" do
455
+ expect(subject.api_only).to eq(false)
456
+ end
457
+
458
+ it "can change the value" do
459
+ Doorkeeper.configure do
460
+ orm DOORKEEPER_ORM
461
+ api_only
462
+ end
463
+
464
+ expect(subject.api_only).to eq(true)
465
+ end
466
+ end
467
+
468
+ describe 'strict_content_type' do
469
+ it 'is false by default' do
470
+ expect(subject.enforce_content_type).to eq(false)
471
+ end
472
+
473
+ it "can change the value" do
474
+ Doorkeeper.configure do
475
+ orm DOORKEEPER_ORM
476
+ enforce_content_type
477
+ end
478
+
479
+ expect(subject.enforce_content_type).to eq(true)
480
+ end
481
+ end
437
482
  end