doorkeeper 4.2.5 → 5.0.0

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 (215) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +25 -0
  3. data/.github/PULL_REQUEST_TEMPLATE.md +17 -0
  4. data/.gitignore +2 -1
  5. data/.gitlab-ci.yml +16 -0
  6. data/.hound.yml +2 -13
  7. data/.rubocop.yml +17 -0
  8. data/.travis.yml +19 -4
  9. data/Appraisals +8 -4
  10. data/CODE_OF_CONDUCT.md +46 -0
  11. data/Gemfile +1 -1
  12. data/NEWS.md +115 -0
  13. data/README.md +175 -39
  14. data/RELEASING.md +5 -12
  15. data/Rakefile +6 -0
  16. data/SECURITY.md +15 -0
  17. data/UPGRADE.md +2 -0
  18. data/app/assets/stylesheets/doorkeeper/admin/application.css +2 -2
  19. data/app/controllers/doorkeeper/application_controller.rb +2 -5
  20. data/app/controllers/doorkeeper/application_metal_controller.rb +4 -0
  21. data/app/controllers/doorkeeper/applications_controller.rb +47 -13
  22. data/app/controllers/doorkeeper/authorizations_controller.rb +55 -12
  23. data/app/controllers/doorkeeper/authorized_applications_controller.rb +19 -2
  24. data/app/controllers/doorkeeper/tokens_controller.rb +24 -17
  25. data/app/helpers/doorkeeper/dashboard_helper.rb +8 -6
  26. data/app/validators/redirect_uri_validator.rb +13 -2
  27. data/app/views/doorkeeper/applications/_delete_form.html.erb +3 -1
  28. data/app/views/doorkeeper/applications/_form.html.erb +31 -19
  29. data/app/views/doorkeeper/applications/edit.html.erb +1 -1
  30. data/app/views/doorkeeper/applications/index.html.erb +18 -6
  31. data/app/views/doorkeeper/applications/new.html.erb +1 -1
  32. data/app/views/doorkeeper/applications/show.html.erb +8 -5
  33. data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
  34. data/app/views/doorkeeper/authorizations/new.html.erb +5 -1
  35. data/app/views/doorkeeper/authorized_applications/index.html.erb +0 -1
  36. data/app/views/layouts/doorkeeper/admin.html.erb +15 -15
  37. data/config/locales/en.yml +19 -6
  38. data/doorkeeper.gemspec +20 -20
  39. data/gemfiles/rails_4_2.gemfile +6 -4
  40. data/gemfiles/rails_5_0.gemfile +4 -4
  41. data/gemfiles/rails_5_1.gemfile +6 -7
  42. data/gemfiles/rails_5_2.gemfile +12 -0
  43. data/gemfiles/rails_master.gemfile +17 -0
  44. data/lib/doorkeeper/config.rb +123 -71
  45. data/lib/doorkeeper/engine.rb +7 -3
  46. data/lib/doorkeeper/errors.rb +20 -5
  47. data/lib/doorkeeper/grape/helpers.rb +14 -9
  48. data/lib/doorkeeper/helpers/controller.rb +16 -22
  49. data/lib/doorkeeper/models/access_grant_mixin.rb +67 -23
  50. data/lib/doorkeeper/models/access_token_mixin.rb +54 -55
  51. data/lib/doorkeeper/models/application_mixin.rb +16 -30
  52. data/lib/doorkeeper/models/concerns/expirable.rb +7 -5
  53. data/lib/doorkeeper/models/concerns/orderable.rb +13 -0
  54. data/lib/doorkeeper/models/concerns/scopes.rb +1 -1
  55. data/lib/doorkeeper/oauth/authorization/code.rb +31 -8
  56. data/lib/doorkeeper/oauth/authorization/context.rb +15 -0
  57. data/lib/doorkeeper/oauth/authorization/token.rb +46 -20
  58. data/lib/doorkeeper/oauth/authorization_code_request.rb +33 -3
  59. data/lib/doorkeeper/oauth/base_request.rb +23 -7
  60. data/lib/doorkeeper/oauth/client/credentials.rb +6 -4
  61. data/lib/doorkeeper/oauth/client.rb +2 -4
  62. data/lib/doorkeeper/oauth/client_credentials/creator.rb +2 -1
  63. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +6 -3
  64. data/lib/doorkeeper/oauth/client_credentials/validation.rb +4 -6
  65. data/lib/doorkeeper/oauth/client_credentials_request.rb +0 -4
  66. data/lib/doorkeeper/oauth/error.rb +2 -2
  67. data/lib/doorkeeper/oauth/error_response.rb +11 -4
  68. data/lib/doorkeeper/oauth/forbidden_token_response.rb +1 -1
  69. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +0 -8
  70. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +15 -0
  71. data/lib/doorkeeper/oauth/invalid_token_response.rb +3 -4
  72. data/lib/doorkeeper/oauth/password_access_token_request.rb +8 -4
  73. data/lib/doorkeeper/oauth/pre_authorization.rb +45 -13
  74. data/lib/doorkeeper/oauth/refresh_token_request.rb +7 -1
  75. data/lib/doorkeeper/oauth/scopes.rb +19 -9
  76. data/lib/doorkeeper/oauth/token.rb +6 -3
  77. data/lib/doorkeeper/oauth/token_introspection.rb +128 -0
  78. data/lib/doorkeeper/oauth/token_response.rb +4 -2
  79. data/lib/doorkeeper/oauth.rb +13 -0
  80. data/lib/doorkeeper/orm/active_record/access_grant.rb +27 -0
  81. data/lib/doorkeeper/orm/active_record/access_token.rb +21 -20
  82. data/lib/doorkeeper/orm/active_record/application.rb +45 -0
  83. data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +26 -0
  84. data/lib/doorkeeper/orm/active_record.rb +21 -8
  85. data/lib/doorkeeper/rails/helpers.rb +7 -10
  86. data/lib/doorkeeper/rails/routes.rb +21 -7
  87. data/lib/doorkeeper/rake/db.rake +40 -0
  88. data/lib/doorkeeper/rake/setup.rake +6 -0
  89. data/lib/doorkeeper/rake.rb +14 -0
  90. data/lib/doorkeeper/request/authorization_code.rb +0 -2
  91. data/lib/doorkeeper/request/client_credentials.rb +0 -2
  92. data/lib/doorkeeper/request/code.rb +0 -2
  93. data/lib/doorkeeper/request/password.rb +1 -13
  94. data/lib/doorkeeper/request/refresh_token.rb +0 -2
  95. data/lib/doorkeeper/request/token.rb +0 -2
  96. data/lib/doorkeeper/request.rb +29 -30
  97. data/lib/doorkeeper/validations.rb +3 -2
  98. data/lib/doorkeeper/version.rb +14 -1
  99. data/lib/doorkeeper.rb +21 -17
  100. data/lib/generators/doorkeeper/application_owner_generator.rb +26 -12
  101. data/lib/generators/doorkeeper/confidential_applications_generator.rb +32 -0
  102. data/lib/generators/doorkeeper/install_generator.rb +17 -9
  103. data/lib/generators/doorkeeper/migration_generator.rb +26 -9
  104. data/lib/generators/doorkeeper/pkce_generator.rb +32 -0
  105. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +31 -20
  106. data/lib/generators/doorkeeper/templates/add_confidential_to_applications.rb.erb +13 -0
  107. data/lib/generators/doorkeeper/templates/{add_owner_to_application_migration.rb → add_owner_to_application_migration.rb.erb} +1 -1
  108. data/lib/generators/doorkeeper/templates/{add_previous_refresh_token_to_access_tokens.rb → add_previous_refresh_token_to_access_tokens.rb.erb} +1 -1
  109. data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +6 -0
  110. data/lib/generators/doorkeeper/templates/initializer.rb +104 -12
  111. data/lib/generators/doorkeeper/templates/{migration.rb → migration.rb.erb} +2 -1
  112. data/lib/generators/doorkeeper/views_generator.rb +3 -1
  113. data/spec/controllers/application_metal_controller_spec.rb +50 -0
  114. data/spec/controllers/applications_controller_spec.rb +141 -17
  115. data/spec/controllers/authorizations_controller_spec.rb +304 -27
  116. data/spec/controllers/protected_resources_controller_spec.rb +44 -35
  117. data/spec/controllers/token_info_controller_spec.rb +17 -21
  118. data/spec/controllers/tokens_controller_spec.rb +201 -17
  119. data/spec/dummy/app/assets/config/manifest.js +2 -0
  120. data/spec/dummy/config/environments/test.rb +4 -5
  121. data/spec/dummy/config/initializers/doorkeeper.rb +23 -2
  122. data/spec/dummy/config/initializers/{active_record_belongs_to_required_by_default.rb → new_framework_defaults.rb} +5 -1
  123. data/spec/dummy/config/initializers/secret_token.rb +0 -1
  124. data/spec/dummy/config/routes.rb +3 -42
  125. data/spec/dummy/db/migrate/20111122132257_create_users.rb +3 -1
  126. data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +3 -1
  127. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +3 -1
  128. data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +3 -1
  129. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +3 -1
  130. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +6 -0
  131. data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +13 -0
  132. data/spec/dummy/db/schema.rb +38 -37
  133. data/spec/factories.rb +1 -1
  134. data/spec/generators/application_owner_generator_spec.rb +25 -6
  135. data/spec/generators/confidential_applications_generator_spec.rb +45 -0
  136. data/spec/generators/install_generator_spec.rb +1 -1
  137. data/spec/generators/migration_generator_spec.rb +25 -4
  138. data/spec/generators/pkce_generator_spec.rb +43 -0
  139. data/spec/generators/previous_refresh_token_generator_spec.rb +57 -0
  140. data/spec/generators/views_generator_spec.rb +1 -1
  141. data/spec/grape/grape_integration_spec.rb +135 -0
  142. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +2 -2
  143. data/spec/lib/config_spec.rb +199 -22
  144. data/spec/lib/doorkeeper_spec.rb +1 -126
  145. data/spec/lib/models/expirable_spec.rb +0 -4
  146. data/spec/lib/models/revocable_spec.rb +2 -4
  147. data/spec/lib/models/scopes_spec.rb +0 -4
  148. data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -4
  149. data/spec/lib/oauth/authorization_code_request_spec.rb +63 -13
  150. data/spec/lib/oauth/base_request_spec.rb +43 -10
  151. data/spec/lib/oauth/base_response_spec.rb +1 -1
  152. data/spec/lib/oauth/client/credentials_spec.rb +5 -5
  153. data/spec/lib/oauth/client_credentials/creator_spec.rb +6 -2
  154. data/spec/lib/oauth/client_credentials/issuer_spec.rb +26 -7
  155. data/spec/lib/oauth/client_credentials/validation_spec.rb +2 -3
  156. data/spec/lib/oauth/client_credentials_integration_spec.rb +2 -2
  157. data/spec/lib/oauth/client_credentials_request_spec.rb +4 -5
  158. data/spec/lib/oauth/client_spec.rb +0 -3
  159. data/spec/lib/oauth/code_request_spec.rb +5 -5
  160. data/spec/lib/oauth/error_response_spec.rb +0 -3
  161. data/spec/lib/oauth/error_spec.rb +1 -3
  162. data/spec/lib/oauth/forbidden_token_response_spec.rb +1 -4
  163. data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -3
  164. data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -1
  165. data/spec/lib/oauth/helpers/uri_checker_spec.rb +115 -3
  166. data/spec/lib/oauth/invalid_token_response_spec.rb +2 -5
  167. data/spec/lib/oauth/password_access_token_request_spec.rb +46 -5
  168. data/spec/lib/oauth/pre_authorization_spec.rb +40 -6
  169. data/spec/lib/oauth/refresh_token_request_spec.rb +30 -14
  170. data/spec/lib/oauth/scopes_spec.rb +28 -4
  171. data/spec/lib/oauth/token_request_spec.rb +10 -13
  172. data/spec/lib/oauth/token_response_spec.rb +0 -1
  173. data/spec/lib/oauth/token_spec.rb +37 -14
  174. data/spec/lib/orm/active_record/stale_records_cleaner_spec.rb +79 -0
  175. data/spec/lib/request/strategy_spec.rb +0 -1
  176. data/spec/lib/server_spec.rb +10 -0
  177. data/spec/models/doorkeeper/access_grant_spec.rb +45 -2
  178. data/spec/models/doorkeeper/access_token_spec.rb +132 -64
  179. data/spec/models/doorkeeper/application_spec.rb +114 -23
  180. data/spec/requests/applications/applications_request_spec.rb +139 -6
  181. data/spec/requests/applications/authorized_applications_spec.rb +1 -1
  182. data/spec/requests/endpoints/authorization_spec.rb +1 -1
  183. data/spec/requests/endpoints/token_spec.rb +15 -6
  184. data/spec/requests/flows/authorization_code_errors_spec.rb +12 -2
  185. data/spec/requests/flows/authorization_code_spec.rb +199 -2
  186. data/spec/requests/flows/client_credentials_spec.rb +73 -5
  187. data/spec/requests/flows/implicit_grant_errors_spec.rb +3 -3
  188. data/spec/requests/flows/implicit_grant_spec.rb +38 -11
  189. data/spec/requests/flows/password_spec.rb +160 -24
  190. data/spec/requests/flows/refresh_token_spec.rb +6 -6
  191. data/spec/requests/flows/revoke_token_spec.rb +26 -26
  192. data/spec/requests/flows/skip_authorization_spec.rb +16 -11
  193. data/spec/requests/protected_resources/metal_spec.rb +2 -2
  194. data/spec/requests/protected_resources/private_api_spec.rb +2 -2
  195. data/spec/routing/custom_controller_routes_spec.rb +63 -7
  196. data/spec/routing/default_routes_spec.rb +6 -2
  197. data/spec/routing/scoped_routes_spec.rb +16 -2
  198. data/spec/spec_helper.rb +54 -3
  199. data/spec/spec_helper_integration.rb +2 -64
  200. data/spec/support/dependencies/factory_bot.rb +2 -0
  201. data/spec/support/doorkeeper_rspec.rb +19 -0
  202. data/spec/support/helpers/access_token_request_helper.rb +1 -1
  203. data/spec/support/helpers/authorization_request_helper.rb +4 -4
  204. data/spec/support/helpers/model_helper.rb +9 -4
  205. data/spec/support/helpers/request_spec_helper.rb +18 -6
  206. data/spec/support/helpers/url_helper.rb +15 -10
  207. data/spec/support/http_method_shim.rb +12 -16
  208. data/spec/support/shared/controllers_shared_context.rb +2 -6
  209. data/spec/support/shared/models_shared_examples.rb +4 -4
  210. data/spec/validators/redirect_uri_validator_spec.rb +58 -7
  211. data/spec/version/version_spec.rb +15 -0
  212. data/vendor/assets/stylesheets/doorkeeper/bootstrap.min.css +4 -5
  213. metadata +75 -33
  214. data/spec/controllers/application_metal_controller.rb +0 -10
  215. data/spec/support/dependencies/factory_girl.rb +0 -2
@@ -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
data/spec/factories.rb CHANGED
@@ -1,4 +1,4 @@
1
- FactoryGirl.define do
1
+ FactoryBot.define do
2
2
  factory :access_grant, class: Doorkeeper::AccessGrant do
3
3
  sequence(:resource_owner_id) { |n| n }
4
4
  application
@@ -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
@@ -10,13 +10,32 @@ describe 'Doorkeeper::ApplicationOwnerGenerator' do
10
10
  describe 'after running the generator' do
11
11
  before :each do
12
12
  prepare_destination
13
- FileUtils.mkdir(::File.expand_path('config', Pathname(destination_root)))
14
- FileUtils.copy_file(::File.expand_path('../templates/routes.rb', __FILE__), ::File.expand_path('config/routes.rb', Pathname.new(destination_root)))
15
- run_generator
16
13
  end
17
14
 
18
- it 'creates a migration' do
19
- assert_migration 'db/migrate/add_owner_to_application.rb'
15
+ context 'pre Rails 5.0.0' do
16
+ it 'creates a migration with no version specifier' do
17
+ stub_const("ActiveRecord::VERSION::MAJOR", 4)
18
+ stub_const("ActiveRecord::VERSION::MINOR", 2)
19
+
20
+ run_generator
21
+
22
+ assert_migration 'db/migrate/add_owner_to_application.rb' do |migration|
23
+ assert migration.include?("ActiveRecord::Migration\n")
24
+ end
25
+ end
26
+ end
27
+
28
+ context 'post Rails 5.0.0' do
29
+ it 'creates a migration with a version specifier' do
30
+ stub_const("ActiveRecord::VERSION::MAJOR", 5)
31
+ stub_const("ActiveRecord::VERSION::MINOR", 0)
32
+
33
+ run_generator
34
+
35
+ assert_migration 'db/migrate/add_owner_to_application.rb' do |migration|
36
+ assert migration.include?("ActiveRecord::Migration[5.0]\n")
37
+ end
38
+ end
20
39
  end
21
40
  end
22
41
  end
@@ -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
@@ -10,11 +10,32 @@ describe 'Doorkeeper::MigrationGenerator' do
10
10
  describe 'after running the generator' do
11
11
  before :each do
12
12
  prepare_destination
13
- run_generator
14
13
  end
15
14
 
16
- it 'creates a migration' do
17
- assert_migration 'db/migrate/create_doorkeeper_tables.rb'
15
+ context 'pre Rails 5.0.0' do
16
+ it 'creates a migration with no version specifier' do
17
+ stub_const('ActiveRecord::VERSION::MAJOR', 4)
18
+ stub_const('ActiveRecord::VERSION::MINOR', 2)
19
+
20
+ run_generator
21
+
22
+ assert_migration 'db/migrate/create_doorkeeper_tables.rb' do |migration|
23
+ assert migration.include?("ActiveRecord::Migration\n")
24
+ end
25
+ end
26
+ end
27
+
28
+ context 'post Rails 5.0.0' do
29
+ it 'creates a migration with a version specifier' do
30
+ stub_const('ActiveRecord::VERSION::MAJOR', 5)
31
+ stub_const('ActiveRecord::VERSION::MINOR', 0)
32
+
33
+ run_generator
34
+
35
+ assert_migration 'db/migrate/create_doorkeeper_tables.rb' do |migration|
36
+ assert migration.include?("ActiveRecord::Migration[5.0]\n")
37
+ end
38
+ end
18
39
  end
19
40
  end
20
41
  end
@@ -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
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+ require 'generators/doorkeeper/previous_refresh_token_generator'
3
+
4
+ describe 'Doorkeeper::PreviousRefreshTokenGenerator' do
5
+ include GeneratorSpec::TestCase
6
+
7
+ tests Doorkeeper::PreviousRefreshTokenGenerator
8
+ destination ::File.expand_path('../tmp/dummy', __FILE__)
9
+
10
+ describe 'after running the generator' do
11
+ before :each do
12
+ prepare_destination
13
+
14
+ allow_any_instance_of(Doorkeeper::PreviousRefreshTokenGenerator).to(
15
+ receive(:no_previous_refresh_token_column?).and_return(true)
16
+ )
17
+ end
18
+
19
+ context 'pre Rails 5.0.0' do
20
+ it 'creates a migration with no version specifier' do
21
+ stub_const('ActiveRecord::VERSION::MAJOR', 4)
22
+ stub_const('ActiveRecord::VERSION::MINOR', 2)
23
+
24
+ run_generator
25
+
26
+ assert_migration 'db/migrate/add_previous_refresh_token_to_access_tokens.rb' do |migration|
27
+ assert migration.include?("ActiveRecord::Migration\n")
28
+ end
29
+ end
30
+ end
31
+
32
+ context 'post Rails 5.0.0' do
33
+ it 'creates a migration with a version specifier' do
34
+ stub_const('ActiveRecord::VERSION::MAJOR', 5)
35
+ stub_const('ActiveRecord::VERSION::MINOR', 0)
36
+
37
+ run_generator
38
+
39
+ assert_migration 'db/migrate/add_previous_refresh_token_to_access_tokens.rb' do |migration|
40
+ assert migration.include?("ActiveRecord::Migration[5.0]\n")
41
+ end
42
+ end
43
+ end
44
+
45
+ context 'already exist' do
46
+ it 'does not create a migration' do
47
+ allow_any_instance_of(Doorkeeper::PreviousRefreshTokenGenerator).to(
48
+ receive(:no_previous_refresh_token_column?).and_call_original
49
+ )
50
+
51
+ run_generator
52
+
53
+ assert_no_migration 'db/migrate/add_previous_refresh_token_to_access_tokens.rb'
54
+ end
55
+ end
56
+ end
57
+ end
@@ -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
@@ -0,0 +1,135 @@
1
+ require 'spec_helper'
2
+ require 'grape'
3
+ require 'rack/test'
4
+ require 'doorkeeper/grape/helpers'
5
+
6
+ # Test Grape API application
7
+ module GrapeApp
8
+ class API < Grape::API
9
+ version 'v1', using: :path
10
+ format :json
11
+ prefix :api
12
+
13
+ helpers Doorkeeper::Grape::Helpers
14
+
15
+ resource :protected do
16
+ before do
17
+ doorkeeper_authorize!
18
+ end
19
+
20
+ desc 'Protected resource, requires token.'
21
+
22
+ get :status do
23
+ { token: doorkeeper_token.token }
24
+ end
25
+ end
26
+
27
+ resource :protected_with_endpoint_scopes do
28
+ before do
29
+ doorkeeper_authorize!
30
+ end
31
+
32
+ desc 'Protected resource, requires token with scopes (defined in endpoint).'
33
+
34
+ get :status, scopes: [:admin] do
35
+ { response: 'OK' }
36
+ end
37
+ end
38
+
39
+ resource :protected_with_helper_scopes do
40
+ before do
41
+ doorkeeper_authorize! :admin
42
+ end
43
+
44
+ desc 'Protected resource, requires token with scopes (defined in helper).'
45
+
46
+ get :status do
47
+ { response: 'OK' }
48
+ end
49
+ end
50
+
51
+ resource :public do
52
+ desc "Public resource, no token required."
53
+
54
+ get :status do
55
+ { response: 'OK' }
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ describe 'Grape integration' do
62
+ include Rack::Test::Methods
63
+
64
+ def app
65
+ GrapeApp::API
66
+ end
67
+
68
+ def json_body
69
+ JSON.parse(last_response.body)
70
+ end
71
+
72
+ let(:client) { FactoryBot.create(:application) }
73
+ let(:resource) { FactoryBot.create(:doorkeeper_testing_user, name: 'Joe', password: 'sekret') }
74
+ let(:access_token) { client_is_authorized(client, resource) }
75
+
76
+ context 'with valid Access Token' do
77
+ it 'successfully requests protected resource' do
78
+ get "api/v1/protected/status.json?access_token=#{access_token.token}"
79
+
80
+ expect(last_response).to be_successful
81
+
82
+ expect(json_body['token']).to eq(access_token.token)
83
+ end
84
+
85
+ it 'successfully requests protected resource with token that has required scopes (Grape endpoint)' do
86
+ access_token = client_is_authorized(client, resource, scopes: 'admin')
87
+
88
+ get "api/v1/protected_with_endpoint_scopes/status.json?access_token=#{access_token.token}"
89
+
90
+ expect(last_response).to be_successful
91
+ expect(json_body).to have_key('response')
92
+ end
93
+
94
+ it 'successfully requests protected resource with token that has required scopes (Doorkeeper helper)' do
95
+ access_token = client_is_authorized(client, resource, scopes: 'admin')
96
+
97
+ get "api/v1/protected_with_helper_scopes/status.json?access_token=#{access_token.token}"
98
+
99
+ expect(last_response).to be_successful
100
+ expect(json_body).to have_key('response')
101
+ end
102
+
103
+ it 'successfully requests public resource' do
104
+ get "api/v1/public/status.json"
105
+
106
+ expect(last_response).to be_successful
107
+ expect(json_body).to have_key('response')
108
+ end
109
+ end
110
+
111
+ context 'with invalid Access Token' do
112
+ it 'fails without access token' do
113
+ get "api/v1/protected/status.json"
114
+
115
+ expect(last_response).not_to be_successful
116
+ expect(json_body).to have_key('error')
117
+ end
118
+
119
+ it 'fails for access token without scopes' do
120
+ get "api/v1/protected_with_endpoint_scopes/status.json?access_token=#{access_token.token}"
121
+
122
+ expect(last_response).not_to be_successful
123
+ expect(json_body).to have_key('error')
124
+ end
125
+
126
+ it 'fails for access token with invalid scopes' do
127
+ access_token = client_is_authorized(client, resource, scopes: 'read write')
128
+
129
+ get "api/v1/protected_with_endpoint_scopes/status.json?access_token=#{access_token.token}"
130
+
131
+ expect(last_response).not_to be_successful
132
+ expect(json_body).to have_key('error')
133
+ end
134
+ end
135
+ end
@@ -1,7 +1,7 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Doorkeeper::DashboardHelper do
4
- describe '.doorkeeper_errors_for' do
4
+ describe '#doorkeeper_errors_for' do
5
5
  let(:object) { double errors: { method: messages } }
6
6
  let(:messages) { ['first message', 'second message'] }
7
7