doorkeeper 5.0.0 → 5.1.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 (241) hide show
  1. checksums.yaml +5 -5
  2. data/.hound.yml +2 -1
  3. data/.rubocop.yml +37 -4
  4. data/.travis.yml +16 -21
  5. data/Appraisals +29 -7
  6. data/Dangerfile +67 -0
  7. data/Gemfile +19 -5
  8. data/NEWS.md +107 -10
  9. data/README.md +75 -470
  10. data/Rakefile +10 -8
  11. data/app/controllers/doorkeeper/application_controller.rb +3 -2
  12. data/app/controllers/doorkeeper/application_metal_controller.rb +4 -13
  13. data/app/controllers/doorkeeper/applications_controller.rb +21 -7
  14. data/app/controllers/doorkeeper/authorizations_controller.rb +3 -3
  15. data/app/controllers/doorkeeper/authorized_applications_controller.rb +2 -0
  16. data/app/controllers/doorkeeper/token_info_controller.rb +4 -2
  17. data/app/controllers/doorkeeper/tokens_controller.rb +13 -11
  18. data/app/helpers/doorkeeper/dashboard_helper.rb +3 -1
  19. data/app/validators/redirect_uri_validator.rb +7 -2
  20. data/app/views/doorkeeper/applications/_form.html.erb +6 -0
  21. data/app/views/doorkeeper/applications/show.html.erb +1 -1
  22. data/app/views/layouts/doorkeeper/admin.html.erb +5 -3
  23. data/bin/console +16 -0
  24. data/config/locales/en.yml +1 -0
  25. data/doorkeeper.gemspec +28 -24
  26. data/gemfiles/rails_5_0.gemfile +9 -4
  27. data/gemfiles/rails_5_1.gemfile +9 -4
  28. data/gemfiles/rails_5_2.gemfile +10 -5
  29. data/gemfiles/rails_6_0.gemfile +17 -0
  30. data/gemfiles/rails_master.gemfile +9 -9
  31. data/lib/doorkeeper/config/option.rb +64 -0
  32. data/lib/doorkeeper/config.rb +197 -76
  33. data/lib/doorkeeper/engine.rb +3 -1
  34. data/lib/doorkeeper/errors.rb +17 -0
  35. data/lib/doorkeeper/grape/authorization_decorator.rb +6 -4
  36. data/lib/doorkeeper/grape/helpers.rb +5 -3
  37. data/lib/doorkeeper/helpers/controller.rb +5 -2
  38. data/lib/doorkeeper/models/access_grant_mixin.rb +25 -6
  39. data/lib/doorkeeper/models/access_token_mixin.rb +68 -22
  40. data/lib/doorkeeper/models/application_mixin.rb +45 -1
  41. data/lib/doorkeeper/models/concerns/accessible.rb +2 -0
  42. data/lib/doorkeeper/models/concerns/expirable.rb +6 -2
  43. data/lib/doorkeeper/models/concerns/orderable.rb +2 -0
  44. data/lib/doorkeeper/models/concerns/ownership.rb +3 -6
  45. data/lib/doorkeeper/models/concerns/reusable.rb +19 -0
  46. data/lib/doorkeeper/models/concerns/revocable.rb +4 -1
  47. data/lib/doorkeeper/models/concerns/scopes.rb +7 -1
  48. data/lib/doorkeeper/models/concerns/secret_storable.rb +108 -0
  49. data/lib/doorkeeper/oauth/authorization/code.rb +4 -2
  50. data/lib/doorkeeper/oauth/authorization/context.rb +2 -0
  51. data/lib/doorkeeper/oauth/authorization/token.rb +14 -7
  52. data/lib/doorkeeper/oauth/authorization/uri_builder.rb +3 -1
  53. data/lib/doorkeeper/oauth/authorization_code_request.rb +8 -4
  54. data/lib/doorkeeper/oauth/base_request.rb +2 -0
  55. data/lib/doorkeeper/oauth/base_response.rb +2 -0
  56. data/lib/doorkeeper/oauth/client/credentials.rb +2 -0
  57. data/lib/doorkeeper/oauth/client.rb +3 -1
  58. data/lib/doorkeeper/oauth/client_credentials/creator.rb +2 -0
  59. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +2 -0
  60. data/lib/doorkeeper/oauth/client_credentials/validation.rb +7 -4
  61. data/lib/doorkeeper/oauth/client_credentials_request.rb +3 -1
  62. data/lib/doorkeeper/oauth/code_request.rb +2 -0
  63. data/lib/doorkeeper/oauth/code_response.rb +4 -2
  64. data/lib/doorkeeper/oauth/error.rb +2 -0
  65. data/lib/doorkeeper/oauth/error_response.rb +20 -6
  66. data/lib/doorkeeper/oauth/forbidden_token_response.rb +10 -3
  67. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +25 -8
  68. data/lib/doorkeeper/oauth/helpers/unique_token.rb +15 -1
  69. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +42 -3
  70. data/lib/doorkeeper/oauth/invalid_token_response.rb +22 -0
  71. data/lib/doorkeeper/oauth/password_access_token_request.rb +9 -2
  72. data/lib/doorkeeper/oauth/pre_authorization.rb +13 -5
  73. data/lib/doorkeeper/oauth/refresh_token_request.rb +15 -4
  74. data/lib/doorkeeper/oauth/scopes.rb +7 -3
  75. data/lib/doorkeeper/oauth/token.rb +4 -2
  76. data/lib/doorkeeper/oauth/token_introspection.rb +76 -8
  77. data/lib/doorkeeper/oauth/token_request.rb +2 -0
  78. data/lib/doorkeeper/oauth/token_response.rb +11 -9
  79. data/lib/doorkeeper/oauth.rb +5 -5
  80. data/lib/doorkeeper/orm/active_record/access_grant.rb +27 -13
  81. data/lib/doorkeeper/orm/active_record/access_token.rb +6 -13
  82. data/lib/doorkeeper/orm/active_record/application.rb +26 -7
  83. data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +10 -3
  84. data/lib/doorkeeper/orm/active_record.rb +8 -6
  85. data/lib/doorkeeper/rails/helpers.rb +5 -1
  86. data/lib/doorkeeper/rails/routes/mapper.rb +2 -0
  87. data/lib/doorkeeper/rails/routes/mapping.rb +9 -7
  88. data/lib/doorkeeper/rails/routes.rb +19 -12
  89. data/lib/doorkeeper/rake/db.rake +17 -17
  90. data/lib/doorkeeper/rake.rb +1 -1
  91. data/lib/doorkeeper/request/authorization_code.rb +2 -0
  92. data/lib/doorkeeper/request/client_credentials.rb +2 -0
  93. data/lib/doorkeeper/request/code.rb +2 -0
  94. data/lib/doorkeeper/request/password.rb +2 -0
  95. data/lib/doorkeeper/request/refresh_token.rb +2 -0
  96. data/lib/doorkeeper/request/strategy.rb +2 -0
  97. data/lib/doorkeeper/request/token.rb +2 -0
  98. data/lib/doorkeeper/request.rb +3 -1
  99. data/lib/doorkeeper/secret_storing/base.rb +64 -0
  100. data/lib/doorkeeper/secret_storing/bcrypt.rb +60 -0
  101. data/lib/doorkeeper/secret_storing/plain.rb +33 -0
  102. data/lib/doorkeeper/secret_storing/sha256_hash.rb +26 -0
  103. data/lib/doorkeeper/server.rb +2 -0
  104. data/lib/doorkeeper/stale_records_cleaner.rb +20 -0
  105. data/lib/doorkeeper/validations.rb +2 -0
  106. data/lib/doorkeeper/version.rb +4 -2
  107. data/lib/doorkeeper.rb +69 -59
  108. data/lib/generators/doorkeeper/application_owner_generator.rb +10 -9
  109. data/lib/generators/doorkeeper/confidential_applications_generator.rb +10 -9
  110. data/lib/generators/doorkeeper/install_generator.rb +11 -9
  111. data/lib/generators/doorkeeper/migration_generator.rb +9 -9
  112. data/lib/generators/doorkeeper/pkce_generator.rb +10 -9
  113. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +10 -9
  114. data/lib/generators/doorkeeper/templates/initializer.rb +138 -13
  115. data/lib/generators/doorkeeper/templates/migration.rb.erb +17 -10
  116. data/lib/generators/doorkeeper/views_generator.rb +6 -4
  117. data/spec/controllers/application_metal_controller_spec.rb +24 -10
  118. data/spec/controllers/applications_controller_spec.rb +76 -78
  119. data/spec/controllers/authorizations_controller_spec.rb +189 -142
  120. data/spec/controllers/protected_resources_controller_spec.rb +111 -67
  121. data/spec/controllers/token_info_controller_spec.rb +14 -12
  122. data/spec/controllers/tokens_controller_spec.rb +170 -112
  123. data/spec/dummy/Rakefile +3 -1
  124. data/spec/dummy/app/controllers/application_controller.rb +3 -1
  125. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +3 -1
  126. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +4 -2
  127. data/spec/dummy/app/controllers/home_controller.rb +6 -5
  128. data/spec/dummy/app/controllers/metal_controller.rb +2 -0
  129. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +4 -2
  130. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  131. data/spec/dummy/app/models/user.rb +2 -0
  132. data/spec/dummy/config/application.rb +26 -2
  133. data/spec/dummy/config/boot.rb +2 -4
  134. data/spec/dummy/config/environment.rb +1 -1
  135. data/spec/dummy/config/environments/development.rb +2 -0
  136. data/spec/dummy/config/environments/production.rb +2 -0
  137. data/spec/dummy/config/environments/test.rb +4 -2
  138. data/spec/dummy/config/initializers/backtrace_silencers.rb +2 -0
  139. data/spec/dummy/config/initializers/doorkeeper.rb +7 -3
  140. data/spec/dummy/config/initializers/secret_token.rb +3 -1
  141. data/spec/dummy/config/initializers/session_store.rb +3 -1
  142. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
  143. data/spec/dummy/config.ru +3 -1
  144. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +20 -13
  145. data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +1 -1
  146. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +2 -0
  147. data/spec/dummy/db/schema.rb +1 -1
  148. data/spec/dummy/script/rails +7 -4
  149. data/spec/factories.rb +11 -9
  150. data/spec/generators/application_owner_generator_spec.rb +13 -26
  151. data/spec/generators/confidential_applications_generator_spec.rb +12 -28
  152. data/spec/generators/install_generator_spec.rb +19 -14
  153. data/spec/generators/migration_generator_spec.rb +13 -26
  154. data/spec/generators/pkce_generator_spec.rb +11 -26
  155. data/spec/generators/previous_refresh_token_generator_spec.rb +16 -29
  156. data/spec/generators/templates/routes.rb +2 -1
  157. data/spec/generators/views_generator_spec.rb +14 -12
  158. data/spec/grape/grape_integration_spec.rb +35 -33
  159. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +9 -7
  160. data/spec/lib/config_spec.rb +290 -104
  161. data/spec/lib/doorkeeper_spec.rb +8 -6
  162. data/spec/lib/models/expirable_spec.rb +22 -8
  163. data/spec/lib/models/reusable_spec.rb +40 -0
  164. data/spec/lib/models/revocable_spec.rb +8 -6
  165. data/spec/lib/models/scopes_spec.rb +27 -13
  166. data/spec/lib/models/secret_storable_spec.rb +135 -0
  167. data/spec/lib/oauth/authorization/uri_builder_spec.rb +17 -15
  168. data/spec/lib/oauth/authorization_code_request_spec.rb +43 -17
  169. data/spec/lib/oauth/base_request_spec.rb +24 -12
  170. data/spec/lib/oauth/base_response_spec.rb +3 -1
  171. data/spec/lib/oauth/client/credentials_spec.rb +26 -24
  172. data/spec/lib/oauth/client_credentials/creator_spec.rb +56 -10
  173. data/spec/lib/oauth/client_credentials/issuer_spec.rb +27 -20
  174. data/spec/lib/oauth/client_credentials/validation_spec.rb +21 -15
  175. data/spec/lib/oauth/client_credentials_integration_spec.rb +8 -6
  176. data/spec/lib/oauth/client_credentials_request_spec.rb +27 -21
  177. data/spec/lib/oauth/client_spec.rb +15 -13
  178. data/spec/lib/oauth/code_request_spec.rb +10 -8
  179. data/spec/lib/oauth/code_response_spec.rb +9 -7
  180. data/spec/lib/oauth/error_response_spec.rb +19 -11
  181. data/spec/lib/oauth/error_spec.rb +4 -2
  182. data/spec/lib/oauth/forbidden_token_response_spec.rb +7 -5
  183. data/spec/lib/oauth/helpers/scope_checker_spec.rb +68 -31
  184. data/spec/lib/oauth/helpers/unique_token_spec.rb +8 -6
  185. data/spec/lib/oauth/helpers/uri_checker_spec.rb +124 -93
  186. data/spec/lib/oauth/invalid_token_response_spec.rb +3 -1
  187. data/spec/lib/oauth/password_access_token_request_spec.rb +95 -34
  188. data/spec/lib/oauth/pre_authorization_spec.rb +80 -54
  189. data/spec/lib/oauth/refresh_token_request_spec.rb +46 -39
  190. data/spec/lib/oauth/scopes_spec.rb +63 -61
  191. data/spec/lib/oauth/token_request_spec.rb +80 -25
  192. data/spec/lib/oauth/token_response_spec.rb +40 -38
  193. data/spec/lib/oauth/token_spec.rb +64 -45
  194. data/spec/lib/request/strategy_spec.rb +3 -1
  195. data/spec/lib/secret_storing/base_spec.rb +60 -0
  196. data/spec/lib/secret_storing/bcrypt_spec.rb +49 -0
  197. data/spec/lib/secret_storing/plain_spec.rb +44 -0
  198. data/spec/lib/secret_storing/sha256_hash_spec.rb +48 -0
  199. data/spec/lib/server_spec.rb +20 -18
  200. data/spec/lib/{orm/active_record/stale_records_cleaner_spec.rb → stale_records_cleaner_spec.rb} +28 -18
  201. data/spec/models/doorkeeper/access_grant_spec.rb +80 -15
  202. data/spec/models/doorkeeper/access_token_spec.rb +212 -83
  203. data/spec/models/doorkeeper/application_spec.rb +146 -49
  204. data/spec/requests/applications/applications_request_spec.rb +100 -68
  205. data/spec/requests/applications/authorized_applications_spec.rb +20 -18
  206. data/spec/requests/endpoints/authorization_spec.rb +27 -25
  207. data/spec/requests/endpoints/token_spec.rb +38 -36
  208. data/spec/requests/flows/authorization_code_errors_spec.rb +27 -25
  209. data/spec/requests/flows/authorization_code_spec.rb +260 -158
  210. data/spec/requests/flows/client_credentials_spec.rb +54 -52
  211. data/spec/requests/flows/implicit_grant_errors_spec.rb +11 -9
  212. data/spec/requests/flows/implicit_grant_spec.rb +27 -25
  213. data/spec/requests/flows/password_spec.rb +64 -56
  214. data/spec/requests/flows/refresh_token_spec.rb +91 -32
  215. data/spec/requests/flows/revoke_token_spec.rb +49 -63
  216. data/spec/requests/flows/skip_authorization_spec.rb +23 -21
  217. data/spec/requests/protected_resources/metal_spec.rb +7 -5
  218. data/spec/requests/protected_resources/private_api_spec.rb +37 -35
  219. data/spec/routing/custom_controller_routes_spec.rb +71 -65
  220. data/spec/routing/default_routes_spec.rb +22 -20
  221. data/spec/routing/scoped_routes_spec.rb +20 -18
  222. data/spec/spec_helper.rb +15 -13
  223. data/spec/spec_helper_integration.rb +3 -1
  224. data/spec/support/dependencies/factory_bot.rb +3 -1
  225. data/spec/support/doorkeeper_rspec.rb +5 -2
  226. data/spec/support/helpers/access_token_request_helper.rb +3 -1
  227. data/spec/support/helpers/authorization_request_helper.rb +4 -2
  228. data/spec/support/helpers/config_helper.rb +2 -0
  229. data/spec/support/helpers/model_helper.rb +11 -5
  230. data/spec/support/helpers/request_spec_helper.rb +5 -3
  231. data/spec/support/helpers/url_helper.rb +20 -18
  232. data/spec/support/http_method_shim.rb +4 -9
  233. data/spec/support/orm/active_record.rb +3 -1
  234. data/spec/support/shared/controllers_shared_context.rb +68 -10
  235. data/spec/support/shared/hashing_shared_context.rb +36 -0
  236. data/spec/support/shared/models_shared_examples.rb +12 -10
  237. data/spec/validators/redirect_uri_validator_spec.rb +76 -47
  238. data/spec/version/version_spec.rb +7 -5
  239. metadata +70 -21
  240. data/gemfiles/rails_4_2.gemfile +0 -13
  241. data/spec/dummy/config/initializers/new_framework_defaults.rb +0 -10
@@ -1,24 +1,15 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
3
+ require "spec_helper"
4
+
5
+ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
4
6
  include AuthorizationRequestHelper
5
7
 
6
- if Rails::VERSION::MAJOR >= 5
7
- class ActionDispatch::TestResponse
8
- def query_params
9
- @query_params ||= begin
10
- fragment = URI.parse(location).fragment
11
- Rack::Utils.parse_query(fragment)
12
- end
13
- end
14
- end
15
- else
16
- class ActionController::TestResponse
17
- def query_params
18
- @query_params ||= begin
19
- fragment = URI.parse(location).fragment
20
- Rack::Utils.parse_query(fragment)
21
- end
8
+ class ActionDispatch::TestResponse
9
+ def query_params
10
+ @query_params ||= begin
11
+ fragment = URI.parse(location).fragment
12
+ Rack::Utils.parse_query(fragment)
22
13
  end
23
14
  end
24
15
  end
@@ -28,47 +19,50 @@ describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
28
19
  end
29
20
 
30
21
  let(:client) { FactoryBot.create :application }
31
- let(:user) { User.create!(name: 'Joe', password: 'sekret') }
22
+ let(:user) { User.create!(name: "Joe", password: "sekret") }
32
23
  let(:access_token) { FactoryBot.build :access_token, resource_owner_id: user.id, application_id: client.id }
33
24
 
34
25
  before do
26
+ Doorkeeper.configure do
27
+ custom_access_token_expires_in(lambda do |context|
28
+ context.grant_type == Doorkeeper::OAuth::IMPLICIT ? 1234 : nil
29
+ end)
30
+ end
31
+
35
32
  allow(Doorkeeper.configuration).to receive(:grant_flows).and_return(["implicit"])
36
33
  allow(controller).to receive(:current_resource_owner).and_return(user)
37
- allow(Doorkeeper.configuration).to receive(:custom_access_token_expires_in).and_return(proc { |context|
38
- context.grant_type == Doorkeeper::OAuth::IMPLICIT ? 1234 : nil
39
- })
40
34
  end
41
35
 
42
- describe 'POST #create' do
36
+ describe "POST #create" do
43
37
  before do
44
- post :create, params: { client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri }
38
+ post :create, params: { client_id: client.uid, response_type: "token", redirect_uri: client.redirect_uri }
45
39
  end
46
40
 
47
- it 'redirects after authorization' do
41
+ it "redirects after authorization" do
48
42
  expect(response).to be_redirect
49
43
  end
50
44
 
51
- it 'redirects to client redirect uri' do
52
- expect(response.location).to match(%r{^#{client.redirect_uri}})
45
+ it "redirects to client redirect uri" do
46
+ expect(response.location).to match(/^#{client.redirect_uri}/)
53
47
  end
54
48
 
55
- it 'includes access token in fragment' do
56
- expect(response.query_params['access_token']).to eq(Doorkeeper::AccessToken.first.token)
49
+ it "includes access token in fragment" do
50
+ expect(response.query_params["access_token"]).to eq(Doorkeeper::AccessToken.first.token)
57
51
  end
58
52
 
59
- it 'includes token type in fragment' do
60
- expect(response.query_params['token_type']).to eq('Bearer')
53
+ it "includes token type in fragment" do
54
+ expect(response.query_params["token_type"]).to eq("Bearer")
61
55
  end
62
56
 
63
- it 'includes token expiration in fragment' do
64
- expect(response.query_params['expires_in'].to_i).to eq(1234)
57
+ it "includes token expiration in fragment" do
58
+ expect(response.query_params["expires_in"].to_i).to eq(1234)
65
59
  end
66
60
 
67
- it 'issues the token for the current client' do
61
+ it "issues the token for the current client" do
68
62
  expect(Doorkeeper::AccessToken.first.application_id).to eq(client.id)
69
63
  end
70
64
 
71
- it 'issues the token for the current resource owner' do
65
+ it "issues the token for the current resource owner" do
72
66
  expect(Doorkeeper::AccessToken.first.resource_owner_id).to eq(user.id)
73
67
  end
74
68
  end
@@ -91,7 +85,7 @@ describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
91
85
  end
92
86
 
93
87
  it "includes access token in fragment" do
94
- expect(redirect_uri.match(/access_token=([a-f0-9]+)&?/)[1]).to eq(Doorkeeper::AccessToken.first.token)
88
+ expect(redirect_uri.match(/access_token=([a-zA-Z0-9\-_]+)&?/)[1]).to eq(Doorkeeper::AccessToken.first.token)
95
89
  end
96
90
 
97
91
  it "includes token type in fragment" do
@@ -111,240 +105,290 @@ describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
111
105
  end
112
106
  end
113
107
 
114
- describe 'POST #create with errors' do
108
+ describe "POST #create with errors" do
115
109
  before do
116
110
  default_scopes_exist :public
117
- post :create, params: { client_id: client.uid, response_type: 'token', scope: 'invalid', redirect_uri: client.redirect_uri }
111
+
112
+ post :create, params: {
113
+ client_id: client.uid,
114
+ response_type: "token",
115
+ scope: "invalid",
116
+ redirect_uri: client.redirect_uri,
117
+ }
118
118
  end
119
119
 
120
- it 'redirects after authorization' do
120
+ it "redirects after authorization" do
121
121
  expect(response).to be_redirect
122
122
  end
123
123
 
124
- it 'redirects to client redirect uri' do
124
+ it "redirects to client redirect uri" do
125
125
  expect(response.location).to match(/^#{client.redirect_uri}/)
126
126
  end
127
127
 
128
- it 'does not include access token in fragment' do
129
- expect(response.query_params['access_token']).to be_nil
128
+ it "does not include access token in fragment" do
129
+ expect(response.query_params["access_token"]).to be_nil
130
130
  end
131
131
 
132
- it 'includes error in fragment' do
133
- expect(response.query_params['error']).to eq('invalid_scope')
132
+ it "includes error in fragment" do
133
+ expect(response.query_params["error"]).to eq("invalid_scope")
134
134
  end
135
135
 
136
- it 'includes error description in fragment' do
137
- expect(response.query_params['error_description']).to eq(translated_error_message(:invalid_scope))
136
+ it "includes error description in fragment" do
137
+ expect(response.query_params["error_description"]).to eq(translated_error_message(:invalid_scope))
138
138
  end
139
139
 
140
- it 'does not issue any access token' do
140
+ it "does not issue any access token" do
141
141
  expect(Doorkeeper::AccessToken.all).to be_empty
142
142
  end
143
143
  end
144
144
 
145
- describe 'POST #create in API mode with errors' do
145
+ describe "POST #create in API mode with errors" do
146
146
  before do
147
147
  allow(Doorkeeper.configuration).to receive(:api_only).and_return(true)
148
148
  default_scopes_exist :public
149
- post :create, params: { client_id: client.uid, response_type: 'token', scope: 'invalid', redirect_uri: client.redirect_uri }
149
+
150
+ post :create, params: {
151
+ client_id: client.uid,
152
+ response_type: "token",
153
+ scope: "invalid",
154
+ redirect_uri: client.redirect_uri,
155
+ }
150
156
  end
151
157
 
152
158
  let(:response_json_body) { JSON.parse(response.body) }
153
- let(:redirect_uri) { response_json_body['redirect_uri'] }
159
+ let(:redirect_uri) { response_json_body["redirect_uri"] }
154
160
 
155
- it 'renders 400 error' do
156
- expect(response.status).to eq 401
161
+ it "renders 400 error" do
162
+ expect(response.status).to eq 400
157
163
  end
158
164
 
159
- it 'includes correct redirect URI' do
165
+ it "includes correct redirect URI" do
160
166
  expect(redirect_uri).to match(/^#{client.redirect_uri}/)
161
167
  end
162
168
 
163
- it 'does not include access token in fragment' do
169
+ it "does not include access token in fragment" do
164
170
  expect(redirect_uri.match(/access_token=([a-f0-9]+)&?/)).to be_nil
165
171
  end
166
172
 
167
- it 'includes error in redirect uri' do
168
- expect(redirect_uri.match(/error=([a-z_]+)&?/)[1]).to eq 'invalid_scope'
173
+ it "includes error in redirect uri" do
174
+ expect(redirect_uri.match(/error=([a-z_]+)&?/)[1]).to eq "invalid_scope"
169
175
  end
170
176
 
171
- it 'includes error description in redirect uri' do
177
+ it "includes error description in redirect uri" do
172
178
  expect(redirect_uri.match(/error_description=(.+)&?/)[1]).to_not be_nil
173
179
  end
174
180
 
175
- it 'does not issue any access token' do
181
+ it "does not issue any access token" do
176
182
  expect(Doorkeeper::AccessToken.all).to be_empty
177
183
  end
178
184
  end
179
185
 
180
- describe 'POST #create with application already authorized' do
186
+ describe "POST #create with application already authorized" do
181
187
  before do
182
188
  allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
183
189
 
184
190
  access_token.save!
185
- post :create, params: { client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri }
191
+
192
+ post :create, params: {
193
+ client_id: client.uid,
194
+ response_type: "token",
195
+ redirect_uri: client.redirect_uri,
196
+ }
186
197
  end
187
198
 
188
- it 'returns the existing access token in a fragment' do
189
- expect(response.query_params['access_token']).to eq(access_token.token)
199
+ it "returns the existing access token in a fragment" do
200
+ expect(response.query_params["access_token"]).to eq(access_token.token)
190
201
  end
191
202
 
192
- it 'does not creates a new access token' do
203
+ it "does not creates a new access token" do
193
204
  expect(Doorkeeper::AccessToken.count).to eq(1)
194
205
  end
195
206
  end
196
207
 
197
- describe 'POST #create with callbacks' do
208
+ describe "POST #create with callbacks" do
198
209
  after do
199
- client.update_attribute :redirect_uri, 'urn:ietf:wg:oauth:2.0:oob'
210
+ client.update_attribute :redirect_uri, "urn:ietf:wg:oauth:2.0:oob"
200
211
  end
201
212
 
202
- describe 'when successful' do
213
+ describe "when successful" do
203
214
  after do
204
- post :create, params: { client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri }
215
+ post :create, params: {
216
+ client_id: client.uid,
217
+ response_type: "token",
218
+ redirect_uri: client.redirect_uri,
219
+ }
205
220
  end
206
221
 
207
- it 'should call :before_successful_authorization callback' do
208
- expect(Doorkeeper.configuration).to receive_message_chain(:before_successful_authorization, :call).with(instance_of(described_class))
222
+ it "should call :before_successful_authorization callback" do
223
+ expect(Doorkeeper.configuration)
224
+ .to receive_message_chain(:before_successful_authorization, :call).with(instance_of(described_class))
209
225
  end
210
226
 
211
- it 'should call :after_successful_authorization callback' do
212
- expect(Doorkeeper.configuration).to receive_message_chain(:after_successful_authorization, :call).with(instance_of(described_class))
227
+ it "should call :after_successful_authorization callback" do
228
+ expect(Doorkeeper.configuration)
229
+ .to receive_message_chain(:after_successful_authorization, :call).with(instance_of(described_class))
213
230
  end
214
231
  end
215
232
 
216
- describe 'with errors' do
233
+ describe "with errors" do
217
234
  after do
218
- post :create, params: { client_id: client.uid, response_type: 'token', redirect_uri: 'bad_uri' }
235
+ post :create, params: { client_id: client.uid, response_type: "token", redirect_uri: "bad_uri" }
219
236
  end
220
237
 
221
- it 'should not call :before_successful_authorization callback' do
238
+ it "should not call :before_successful_authorization callback" do
222
239
  expect(Doorkeeper.configuration).not_to receive(:before_successful_authorization)
223
240
  end
224
241
 
225
- it 'should not call :after_successful_authorization callback' do
242
+ it "should not call :after_successful_authorization callback" do
226
243
  expect(Doorkeeper.configuration).not_to receive(:after_successful_authorization)
227
244
  end
228
245
  end
229
246
  end
230
247
 
231
- describe 'GET #new token request with native url and skip_authorization true' do
248
+ describe "GET #new token request with native url and skip_authorization true" do
232
249
  before do
233
250
  allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc do
234
251
  true
235
252
  end)
236
- client.update_attribute :redirect_uri, 'urn:ietf:wg:oauth:2.0:oob'
237
- get :new, params: { client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri }
253
+
254
+ client.update_attribute :redirect_uri, "urn:ietf:wg:oauth:2.0:oob"
255
+
256
+ get :new, params: {
257
+ client_id: client.uid,
258
+ response_type: "token",
259
+ redirect_uri: client.redirect_uri,
260
+ }
238
261
  end
239
262
 
240
- it 'should redirect immediately' do
263
+ it "should redirect immediately" do
241
264
  expect(response).to be_redirect
242
- expect(response.location).to match(/oauth\/token\/info\?access_token=/)
265
+ expect(response.location).to match(%r{/oauth/token/info\?access_token=})
243
266
  end
244
267
 
245
- it 'should not issue a grant' do
268
+ it "should not issue a grant" do
246
269
  expect(Doorkeeper::AccessGrant.count).to be 0
247
270
  end
248
271
 
249
- it 'should issue a token' do
272
+ it "should issue a token" do
250
273
  expect(Doorkeeper::AccessToken.count).to be 1
251
274
  end
252
275
  end
253
276
 
254
- describe 'GET #new code request with native url and skip_authorization true' do
277
+ describe "GET #new code request with native url and skip_authorization true" do
255
278
  before do
256
279
  allow(Doorkeeper.configuration).to receive(:grant_flows).and_return(%w[authorization_code])
257
280
  allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc do
258
281
  true
259
282
  end)
260
- client.update_attribute :redirect_uri, 'urn:ietf:wg:oauth:2.0:oob'
261
- get :new, params: { client_id: client.uid, response_type: 'code', redirect_uri: client.redirect_uri }
283
+
284
+ client.update_attribute :redirect_uri, "urn:ietf:wg:oauth:2.0:oob"
285
+
286
+ get :new, params: {
287
+ client_id: client.uid,
288
+ response_type: "code",
289
+ redirect_uri: client.redirect_uri,
290
+ }
262
291
  end
263
292
 
264
- it 'should redirect immediately' do
293
+ it "should redirect immediately" do
265
294
  expect(response).to be_redirect
266
- expect(response.location).to match(/oauth\/authorize\/native\?code=#{Doorkeeper::AccessGrant.first.token}/)
295
+ expect(response.location)
296
+ .to match(%r{/oauth/authorize/native\?code=#{Doorkeeper::AccessGrant.first.token}})
267
297
  end
268
298
 
269
- it 'should issue a grant' do
299
+ it "should issue a grant" do
270
300
  expect(Doorkeeper::AccessGrant.count).to be 1
271
301
  end
272
302
 
273
- it 'should not issue a token' do
303
+ it "should not issue a token" do
274
304
  expect(Doorkeeper::AccessToken.count).to be 0
275
305
  end
276
306
  end
277
307
 
278
- describe 'GET #new with skip_authorization true' do
308
+ describe "GET #new with skip_authorization true" do
279
309
  before do
280
310
  allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc do
281
311
  true
282
312
  end)
283
- get :new, params: { client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri }
313
+
314
+ get :new, params: {
315
+ client_id: client.uid,
316
+ response_type: "token",
317
+ redirect_uri: client.redirect_uri,
318
+ }
284
319
  end
285
320
 
286
- it 'should redirect immediately' do
321
+ it "should redirect immediately" do
287
322
  expect(response).to be_redirect
288
- expect(response.location).to match(%r{^#{client.redirect_uri}})
323
+ expect(response.location).to match(/^#{client.redirect_uri}/)
289
324
  end
290
325
 
291
- it 'should issue a token' do
326
+ it "should issue a token" do
292
327
  expect(Doorkeeper::AccessToken.count).to be 1
293
328
  end
294
329
 
295
- it 'includes token type in fragment' do
296
- expect(response.query_params['token_type']).to eq('Bearer')
330
+ it "includes token type in fragment" do
331
+ expect(response.query_params["token_type"]).to eq("Bearer")
297
332
  end
298
333
 
299
- it 'includes token expiration in fragment' do
300
- expect(response.query_params['expires_in'].to_i).to eq(1234)
334
+ it "includes token expiration in fragment" do
335
+ expect(response.query_params["expires_in"].to_i).to eq(1234)
301
336
  end
302
337
 
303
- it 'issues the token for the current client' do
338
+ it "issues the token for the current client" do
304
339
  expect(Doorkeeper::AccessToken.first.application_id).to eq(client.id)
305
340
  end
306
341
 
307
- it 'issues the token for the current resource owner' do
342
+ it "issues the token for the current resource owner" do
308
343
  expect(Doorkeeper::AccessToken.first.resource_owner_id).to eq(user.id)
309
344
  end
310
345
  end
311
346
 
312
- describe 'GET #new in API mode' do
347
+ describe "GET #new in API mode" do
313
348
  before do
314
349
  allow(Doorkeeper.configuration).to receive(:api_only).and_return(true)
315
- get :new, params: { client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri }
350
+
351
+ get :new, params: {
352
+ client_id: client.uid,
353
+ response_type: "token",
354
+ redirect_uri: client.redirect_uri,
355
+ }
316
356
  end
317
357
 
318
- it 'should render success' do
358
+ it "should render success" do
319
359
  expect(response).to be_successful
320
360
  end
321
361
 
322
362
  it "sets status to pre-authorization" do
323
- expect(json_response["status"]).to eq(I18n.t('doorkeeper.pre_authorization.status'))
363
+ expect(json_response["status"]).to eq(I18n.t("doorkeeper.pre_authorization.status"))
324
364
  end
325
365
 
326
366
  it "sets correct values" do
327
- expect(json_response['client_id']).to eq(client.uid)
328
- expect(json_response['redirect_uri']).to eq(client.redirect_uri)
329
- expect(json_response['state']).to be_nil
330
- expect(json_response['response_type']).to eq('token')
331
- expect(json_response['scope']).to eq('')
367
+ expect(json_response["client_id"]).to eq(client.uid)
368
+ expect(json_response["redirect_uri"]).to eq(client.redirect_uri)
369
+ expect(json_response["state"]).to be_nil
370
+ expect(json_response["response_type"]).to eq("token")
371
+ expect(json_response["scope"]).to eq("")
332
372
  end
333
373
  end
334
374
 
335
- describe 'GET #new in API mode with skip_authorization true' do
375
+ describe "GET #new in API mode with skip_authorization true" do
336
376
  before do
337
377
  allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc { true })
338
378
  allow(Doorkeeper.configuration).to receive(:api_only).and_return(true)
339
379
 
340
- get :new, params: { client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri }
380
+ get :new, params: {
381
+ client_id: client.uid,
382
+ response_type: "token",
383
+ redirect_uri: client.redirect_uri,
384
+ }
341
385
  end
342
386
 
343
- it 'should render success' do
387
+ it "should render success" do
344
388
  expect(response).to be_successful
345
389
  end
346
390
 
347
- it 'should issue a token' do
391
+ it "should issue a token" do
348
392
  expect(Doorkeeper::AccessToken.count).to be 1
349
393
  end
350
394
 
@@ -358,7 +402,7 @@ describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
358
402
  expect(redirect_uri.match(/token_type=(\w+)&?/)[1]).to eq "Bearer"
359
403
  expect(redirect_uri.match(/expires_in=(\d+)&?/)[1].to_i).to eq 1234
360
404
  expect(
361
- redirect_uri.match(/access_token=([a-f0-9]+)&?/)[1]
405
+ redirect_uri.match(/access_token=([a-zA-Z0-9\-_]+)&?/)[1]
362
406
  ).to eq Doorkeeper::AccessToken.first.token
363
407
  end
364
408
 
@@ -371,101 +415,104 @@ describe Doorkeeper::AuthorizationsController, 'implicit grant flow' do
371
415
  end
372
416
  end
373
417
 
374
- describe 'GET #new with errors' do
418
+ describe "GET #new with errors" do
375
419
  before do
376
420
  default_scopes_exist :public
377
- get :new, params: { an_invalid: 'request' }
421
+ get :new, params: { an_invalid: "request" }
378
422
  end
379
423
 
380
- it 'does not redirect' do
424
+ it "does not redirect" do
381
425
  expect(response).to_not be_redirect
382
426
  end
383
427
 
384
- it 'does not issue any token' do
428
+ it "does not issue any token" do
385
429
  expect(Doorkeeper::AccessGrant.count).to eq 0
386
430
  expect(Doorkeeper::AccessToken.count).to eq 0
387
431
  end
388
432
  end
389
433
 
390
- describe 'GET #new in API mode with errors' do
434
+ describe "GET #new in API mode with errors" do
391
435
  let(:response_json_body) { JSON.parse(response.body) }
392
436
 
393
437
  before do
394
438
  default_scopes_exist :public
395
439
  allow(Doorkeeper.configuration).to receive(:api_only).and_return(true)
396
- get :new, params: { an_invalid: 'request' }
440
+ get :new, params: { an_invalid: "request" }
397
441
  end
398
442
 
399
- it 'should render bad request' do
443
+ it "should render bad request" do
400
444
  expect(response).to have_http_status(:bad_request)
401
445
  end
402
446
 
403
- it 'includes error in body' do
404
- expect(response_json_body['error']).to eq('unsupported_response_type')
447
+ it "includes error in body" do
448
+ expect(response_json_body["error"]).to eq("unsupported_response_type")
405
449
  end
406
450
 
407
- it 'includes error description in body' do
408
- expect(response_json_body['error_description']).to eq(translated_error_message(:unsupported_response_type))
451
+ it "includes error description in body" do
452
+ expect(response_json_body["error_description"])
453
+ .to eq(translated_error_message(:unsupported_response_type))
409
454
  end
410
455
 
411
- it 'does not issue any token' do
456
+ it "does not issue any token" do
412
457
  expect(Doorkeeper::AccessGrant.count).to eq 0
413
458
  expect(Doorkeeper::AccessToken.count).to eq 0
414
459
  end
415
460
  end
416
461
 
417
- describe 'GET #new with callbacks' do
462
+ describe "GET #new with callbacks" do
418
463
  after do
419
- client.update_attribute :redirect_uri, 'urn:ietf:wg:oauth:2.0:oob'
420
- get :new, params: { client_id: client.uid, response_type: 'token', redirect_uri: client.redirect_uri }
464
+ client.update_attribute :redirect_uri, "urn:ietf:wg:oauth:2.0:oob"
465
+ get :new, params: { client_id: client.uid, response_type: "token", redirect_uri: client.redirect_uri }
421
466
  end
422
467
 
423
- describe 'when authorizing' do
468
+ describe "when authorizing" do
424
469
  before do
425
470
  allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc { true })
426
471
  end
427
472
 
428
- it 'should call :before_successful_authorization callback' do
429
- expect(Doorkeeper.configuration).to receive_message_chain(:before_successful_authorization, :call).with(instance_of(described_class))
473
+ it "should call :before_successful_authorization callback" do
474
+ expect(Doorkeeper.configuration)
475
+ .to receive_message_chain(:before_successful_authorization, :call).with(instance_of(described_class))
430
476
  end
431
477
 
432
- it 'should call :after_successful_authorization callback' do
433
- expect(Doorkeeper.configuration).to receive_message_chain(:after_successful_authorization, :call).with(instance_of(described_class))
478
+ it "should call :after_successful_authorization callback" do
479
+ expect(Doorkeeper.configuration)
480
+ .to receive_message_chain(:after_successful_authorization, :call).with(instance_of(described_class))
434
481
  end
435
482
  end
436
483
 
437
- describe 'when not authorizing' do
484
+ describe "when not authorizing" do
438
485
  before do
439
486
  allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc { false })
440
487
  end
441
488
 
442
- it 'should not call :before_successful_authorization callback' do
489
+ it "should not call :before_successful_authorization callback" do
443
490
  expect(Doorkeeper.configuration).not_to receive(:before_successful_authorization)
444
491
  end
445
492
 
446
- it 'should not call :after_successful_authorization callback' do
493
+ it "should not call :after_successful_authorization callback" do
447
494
  expect(Doorkeeper.configuration).not_to receive(:after_successful_authorization)
448
495
  end
449
496
  end
450
497
 
451
- describe 'when not authorizing in api mode' do
498
+ describe "when not authorizing in api mode" do
452
499
  before do
453
500
  allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc { false })
454
501
  allow(Doorkeeper.configuration).to receive(:api_only).and_return(true)
455
502
  end
456
503
 
457
- it 'should not call :before_successful_authorization callback' do
504
+ it "should not call :before_successful_authorization callback" do
458
505
  expect(Doorkeeper.configuration).not_to receive(:before_successful_authorization)
459
506
  end
460
507
 
461
- it 'should not call :after_successful_authorization callback' do
508
+ it "should not call :after_successful_authorization callback" do
462
509
  expect(Doorkeeper.configuration).not_to receive(:after_successful_authorization)
463
510
  end
464
511
  end
465
512
  end
466
513
 
467
- describe 'authorize response memoization' do
468
- it 'memoizes the result of the authorization' do
514
+ describe "authorize response memoization" do
515
+ it "memoizes the result of the authorization" do
469
516
  strategy = double(:strategy, authorize: true)
470
517
  expect(strategy).to receive(:authorize).once
471
518
  allow(controller).to receive(:strategy) { strategy }