doorkeeper 5.2.2 → 5.5.4

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

Potentially problematic release.


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

Files changed (260) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +198 -3
  3. data/README.md +28 -20
  4. data/app/controllers/doorkeeper/application_controller.rb +3 -2
  5. data/app/controllers/doorkeeper/application_metal_controller.rb +2 -2
  6. data/app/controllers/doorkeeper/applications_controller.rb +7 -8
  7. data/app/controllers/doorkeeper/authorizations_controller.rb +48 -18
  8. data/app/controllers/doorkeeper/authorized_applications_controller.rb +6 -6
  9. data/app/controllers/doorkeeper/token_info_controller.rb +12 -2
  10. data/app/controllers/doorkeeper/tokens_controller.rb +70 -25
  11. data/app/helpers/doorkeeper/dashboard_helper.rb +1 -1
  12. data/app/views/doorkeeper/applications/_form.html.erb +1 -1
  13. data/app/views/doorkeeper/applications/show.html.erb +35 -14
  14. data/app/views/doorkeeper/authorizations/form_post.html.erb +15 -0
  15. data/app/views/doorkeeper/authorizations/new.html.erb +2 -0
  16. data/config/locales/en.yml +9 -2
  17. data/lib/doorkeeper/config/abstract_builder.rb +28 -0
  18. data/lib/doorkeeper/config/option.rb +26 -14
  19. data/lib/doorkeeper/config/validations.rb +53 -0
  20. data/lib/doorkeeper/config.rb +214 -122
  21. data/lib/doorkeeper/engine.rb +1 -1
  22. data/lib/doorkeeper/grant_flow/fallback_flow.rb +15 -0
  23. data/lib/doorkeeper/grant_flow/flow.rb +44 -0
  24. data/lib/doorkeeper/grant_flow/registry.rb +50 -0
  25. data/lib/doorkeeper/grant_flow.rb +45 -0
  26. data/lib/doorkeeper/grape/helpers.rb +2 -2
  27. data/lib/doorkeeper/helpers/controller.rb +18 -12
  28. data/lib/doorkeeper/models/access_grant_mixin.rb +23 -19
  29. data/lib/doorkeeper/models/access_token_mixin.rb +157 -55
  30. data/lib/doorkeeper/models/application_mixin.rb +8 -7
  31. data/lib/doorkeeper/models/concerns/expirable.rb +1 -1
  32. data/lib/doorkeeper/models/concerns/ownership.rb +1 -1
  33. data/lib/doorkeeper/models/concerns/resource_ownerable.rb +47 -0
  34. data/lib/doorkeeper/models/concerns/reusable.rb +1 -1
  35. data/lib/doorkeeper/models/concerns/revocable.rb +1 -28
  36. data/lib/doorkeeper/models/concerns/scopes.rb +5 -1
  37. data/lib/doorkeeper/models/concerns/secret_storable.rb +1 -3
  38. data/lib/doorkeeper/oauth/authorization/code.rb +22 -9
  39. data/lib/doorkeeper/oauth/authorization/context.rb +5 -5
  40. data/lib/doorkeeper/oauth/authorization/token.rb +23 -18
  41. data/lib/doorkeeper/oauth/authorization/uri_builder.rb +4 -4
  42. data/lib/doorkeeper/oauth/authorization_code_request.rb +30 -20
  43. data/lib/doorkeeper/oauth/base_request.rb +19 -23
  44. data/lib/doorkeeper/oauth/client/credentials.rb +2 -4
  45. data/lib/doorkeeper/oauth/client.rb +8 -9
  46. data/lib/doorkeeper/oauth/client_credentials/creator.rb +38 -12
  47. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +10 -8
  48. data/lib/doorkeeper/oauth/client_credentials/{validation.rb → validator.rb} +7 -5
  49. data/lib/doorkeeper/oauth/client_credentials_request.rb +8 -7
  50. data/lib/doorkeeper/oauth/code_request.rb +4 -4
  51. data/lib/doorkeeper/oauth/code_response.rb +24 -14
  52. data/lib/doorkeeper/oauth/error.rb +1 -1
  53. data/lib/doorkeeper/oauth/error_response.rb +10 -11
  54. data/lib/doorkeeper/oauth/forbidden_token_response.rb +2 -1
  55. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +8 -12
  56. data/lib/doorkeeper/oauth/helpers/unique_token.rb +10 -7
  57. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +1 -19
  58. data/lib/doorkeeper/oauth/hooks/context.rb +21 -0
  59. data/lib/doorkeeper/oauth/invalid_request_response.rb +3 -3
  60. data/lib/doorkeeper/oauth/invalid_token_response.rb +7 -4
  61. data/lib/doorkeeper/oauth/password_access_token_request.rb +28 -10
  62. data/lib/doorkeeper/oauth/pre_authorization.rb +73 -37
  63. data/lib/doorkeeper/oauth/refresh_token_request.rb +35 -26
  64. data/lib/doorkeeper/oauth/token.rb +6 -7
  65. data/lib/doorkeeper/oauth/token_introspection.rb +12 -16
  66. data/lib/doorkeeper/oauth/token_request.rb +3 -3
  67. data/lib/doorkeeper/oauth/token_response.rb +1 -1
  68. data/lib/doorkeeper/orm/active_record/access_grant.rb +4 -43
  69. data/lib/doorkeeper/orm/active_record/access_token.rb +4 -35
  70. data/lib/doorkeeper/orm/active_record/application.rb +5 -95
  71. data/lib/doorkeeper/orm/active_record/mixins/access_grant.rb +69 -0
  72. data/lib/doorkeeper/orm/active_record/mixins/access_token.rb +60 -0
  73. data/lib/doorkeeper/orm/active_record/mixins/application.rb +199 -0
  74. data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +8 -3
  75. data/lib/doorkeeper/orm/active_record.rb +5 -7
  76. data/lib/doorkeeper/rails/helpers.rb +4 -4
  77. data/lib/doorkeeper/rails/routes/abstract_router.rb +35 -0
  78. data/lib/doorkeeper/rails/routes/mapper.rb +2 -2
  79. data/lib/doorkeeper/rails/routes/registry.rb +45 -0
  80. data/lib/doorkeeper/rails/routes.rb +17 -25
  81. data/lib/doorkeeper/rake/db.rake +6 -6
  82. data/lib/doorkeeper/rake/setup.rake +5 -0
  83. data/lib/doorkeeper/request/authorization_code.rb +3 -3
  84. data/lib/doorkeeper/request/client_credentials.rb +2 -2
  85. data/lib/doorkeeper/request/password.rb +3 -2
  86. data/lib/doorkeeper/request/refresh_token.rb +5 -4
  87. data/lib/doorkeeper/request/strategy.rb +2 -2
  88. data/lib/doorkeeper/request.rb +49 -12
  89. data/lib/doorkeeper/server.rb +5 -5
  90. data/lib/doorkeeper/stale_records_cleaner.rb +4 -4
  91. data/lib/doorkeeper/version.rb +2 -6
  92. data/lib/doorkeeper.rb +112 -81
  93. data/lib/generators/doorkeeper/application_owner_generator.rb +1 -1
  94. data/lib/generators/doorkeeper/confidential_applications_generator.rb +2 -2
  95. data/lib/generators/doorkeeper/enable_polymorphic_resource_owner_generator.rb +39 -0
  96. data/lib/generators/doorkeeper/migration_generator.rb +1 -1
  97. data/lib/generators/doorkeeper/pkce_generator.rb +1 -1
  98. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +2 -2
  99. data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb.erb +3 -1
  100. data/lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb.erb +2 -0
  101. data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +2 -0
  102. data/lib/generators/doorkeeper/templates/enable_polymorphic_resource_owner_migration.rb.erb +17 -0
  103. data/lib/generators/doorkeeper/templates/initializer.rb +99 -14
  104. data/lib/generators/doorkeeper/templates/migration.rb.erb +14 -5
  105. metadata +37 -306
  106. data/Appraisals +0 -40
  107. data/CODE_OF_CONDUCT.md +0 -46
  108. data/CONTRIBUTING.md +0 -49
  109. data/Dangerfile +0 -67
  110. data/Dockerfile +0 -29
  111. data/Gemfile +0 -25
  112. data/NEWS.md +0 -1
  113. data/RELEASING.md +0 -11
  114. data/Rakefile +0 -28
  115. data/SECURITY.md +0 -15
  116. data/UPGRADE.md +0 -2
  117. data/bin/console +0 -16
  118. data/doorkeeper.gemspec +0 -42
  119. data/gemfiles/rails_5_0.gemfile +0 -18
  120. data/gemfiles/rails_5_1.gemfile +0 -18
  121. data/gemfiles/rails_5_2.gemfile +0 -18
  122. data/gemfiles/rails_6_0.gemfile +0 -18
  123. data/gemfiles/rails_master.gemfile +0 -18
  124. data/spec/controllers/application_metal_controller_spec.rb +0 -64
  125. data/spec/controllers/applications_controller_spec.rb +0 -273
  126. data/spec/controllers/authorizations_controller_spec.rb +0 -608
  127. data/spec/controllers/protected_resources_controller_spec.rb +0 -353
  128. data/spec/controllers/token_info_controller_spec.rb +0 -50
  129. data/spec/controllers/tokens_controller_spec.rb +0 -498
  130. data/spec/dummy/Rakefile +0 -9
  131. data/spec/dummy/app/assets/config/manifest.js +0 -2
  132. data/spec/dummy/app/controllers/application_controller.rb +0 -5
  133. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +0 -9
  134. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +0 -14
  135. data/spec/dummy/app/controllers/home_controller.rb +0 -18
  136. data/spec/dummy/app/controllers/metal_controller.rb +0 -13
  137. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +0 -13
  138. data/spec/dummy/app/helpers/application_helper.rb +0 -7
  139. data/spec/dummy/app/models/user.rb +0 -7
  140. data/spec/dummy/app/views/home/index.html.erb +0 -0
  141. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  142. data/spec/dummy/config/application.rb +0 -49
  143. data/spec/dummy/config/boot.rb +0 -7
  144. data/spec/dummy/config/database.yml +0 -15
  145. data/spec/dummy/config/environment.rb +0 -5
  146. data/spec/dummy/config/environments/development.rb +0 -31
  147. data/spec/dummy/config/environments/production.rb +0 -64
  148. data/spec/dummy/config/environments/test.rb +0 -45
  149. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -9
  150. data/spec/dummy/config/initializers/doorkeeper.rb +0 -166
  151. data/spec/dummy/config/initializers/secret_token.rb +0 -10
  152. data/spec/dummy/config/initializers/session_store.rb +0 -10
  153. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -16
  154. data/spec/dummy/config/locales/doorkeeper.en.yml +0 -5
  155. data/spec/dummy/config/routes.rb +0 -13
  156. data/spec/dummy/config.ru +0 -6
  157. data/spec/dummy/db/migrate/20111122132257_create_users.rb +0 -11
  158. data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +0 -7
  159. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +0 -69
  160. data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +0 -9
  161. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +0 -13
  162. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +0 -8
  163. data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +0 -13
  164. data/spec/dummy/db/schema.rb +0 -68
  165. data/spec/dummy/public/404.html +0 -26
  166. data/spec/dummy/public/422.html +0 -26
  167. data/spec/dummy/public/500.html +0 -26
  168. data/spec/dummy/public/favicon.ico +0 -0
  169. data/spec/dummy/script/rails +0 -9
  170. data/spec/factories.rb +0 -30
  171. data/spec/generators/application_owner_generator_spec.rb +0 -28
  172. data/spec/generators/confidential_applications_generator_spec.rb +0 -29
  173. data/spec/generators/install_generator_spec.rb +0 -36
  174. data/spec/generators/migration_generator_spec.rb +0 -28
  175. data/spec/generators/pkce_generator_spec.rb +0 -28
  176. data/spec/generators/previous_refresh_token_generator_spec.rb +0 -44
  177. data/spec/generators/templates/routes.rb +0 -4
  178. data/spec/generators/views_generator_spec.rb +0 -29
  179. data/spec/grape/grape_integration_spec.rb +0 -137
  180. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +0 -26
  181. data/spec/lib/config_spec.rb +0 -739
  182. data/spec/lib/doorkeeper_spec.rb +0 -27
  183. data/spec/lib/models/expirable_spec.rb +0 -61
  184. data/spec/lib/models/reusable_spec.rb +0 -40
  185. data/spec/lib/models/revocable_spec.rb +0 -59
  186. data/spec/lib/models/scopes_spec.rb +0 -53
  187. data/spec/lib/models/secret_storable_spec.rb +0 -135
  188. data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -39
  189. data/spec/lib/oauth/authorization_code_request_spec.rb +0 -168
  190. data/spec/lib/oauth/base_request_spec.rb +0 -222
  191. data/spec/lib/oauth/base_response_spec.rb +0 -47
  192. data/spec/lib/oauth/client/credentials_spec.rb +0 -90
  193. data/spec/lib/oauth/client_credentials/creator_spec.rb +0 -97
  194. data/spec/lib/oauth/client_credentials/issuer_spec.rb +0 -112
  195. data/spec/lib/oauth/client_credentials/validation_spec.rb +0 -59
  196. data/spec/lib/oauth/client_credentials_integration_spec.rb +0 -29
  197. data/spec/lib/oauth/client_credentials_request_spec.rb +0 -109
  198. data/spec/lib/oauth/client_spec.rb +0 -38
  199. data/spec/lib/oauth/code_request_spec.rb +0 -46
  200. data/spec/lib/oauth/code_response_spec.rb +0 -36
  201. data/spec/lib/oauth/error_response_spec.rb +0 -66
  202. data/spec/lib/oauth/error_spec.rb +0 -23
  203. data/spec/lib/oauth/forbidden_token_response_spec.rb +0 -22
  204. data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -98
  205. data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -21
  206. data/spec/lib/oauth/helpers/uri_checker_spec.rb +0 -262
  207. data/spec/lib/oauth/invalid_request_response_spec.rb +0 -75
  208. data/spec/lib/oauth/invalid_token_response_spec.rb +0 -55
  209. data/spec/lib/oauth/password_access_token_request_spec.rb +0 -192
  210. data/spec/lib/oauth/pre_authorization_spec.rb +0 -225
  211. data/spec/lib/oauth/refresh_token_request_spec.rb +0 -178
  212. data/spec/lib/oauth/scopes_spec.rb +0 -148
  213. data/spec/lib/oauth/token_request_spec.rb +0 -153
  214. data/spec/lib/oauth/token_response_spec.rb +0 -86
  215. data/spec/lib/oauth/token_spec.rb +0 -158
  216. data/spec/lib/request/strategy_spec.rb +0 -54
  217. data/spec/lib/secret_storing/base_spec.rb +0 -60
  218. data/spec/lib/secret_storing/bcrypt_spec.rb +0 -49
  219. data/spec/lib/secret_storing/plain_spec.rb +0 -44
  220. data/spec/lib/secret_storing/sha256_hash_spec.rb +0 -48
  221. data/spec/lib/server_spec.rb +0 -49
  222. data/spec/lib/stale_records_cleaner_spec.rb +0 -89
  223. data/spec/models/doorkeeper/access_grant_spec.rb +0 -163
  224. data/spec/models/doorkeeper/access_token_spec.rb +0 -622
  225. data/spec/models/doorkeeper/application_spec.rb +0 -377
  226. data/spec/requests/applications/applications_request_spec.rb +0 -259
  227. data/spec/requests/applications/authorized_applications_spec.rb +0 -32
  228. data/spec/requests/endpoints/authorization_spec.rb +0 -89
  229. data/spec/requests/endpoints/token_spec.rb +0 -75
  230. data/spec/requests/flows/authorization_code_errors_spec.rb +0 -79
  231. data/spec/requests/flows/authorization_code_spec.rb +0 -513
  232. data/spec/requests/flows/client_credentials_spec.rb +0 -166
  233. data/spec/requests/flows/implicit_grant_errors_spec.rb +0 -46
  234. data/spec/requests/flows/implicit_grant_spec.rb +0 -91
  235. data/spec/requests/flows/password_spec.rb +0 -296
  236. data/spec/requests/flows/refresh_token_spec.rb +0 -233
  237. data/spec/requests/flows/revoke_token_spec.rb +0 -151
  238. data/spec/requests/flows/skip_authorization_spec.rb +0 -66
  239. data/spec/requests/protected_resources/metal_spec.rb +0 -16
  240. data/spec/requests/protected_resources/private_api_spec.rb +0 -83
  241. data/spec/routing/custom_controller_routes_spec.rb +0 -133
  242. data/spec/routing/default_routes_spec.rb +0 -41
  243. data/spec/routing/scoped_routes_spec.rb +0 -47
  244. data/spec/spec_helper.rb +0 -57
  245. data/spec/spec_helper_integration.rb +0 -4
  246. data/spec/support/dependencies/factory_bot.rb +0 -4
  247. data/spec/support/doorkeeper_rspec.rb +0 -22
  248. data/spec/support/helpers/access_token_request_helper.rb +0 -13
  249. data/spec/support/helpers/authorization_request_helper.rb +0 -43
  250. data/spec/support/helpers/config_helper.rb +0 -11
  251. data/spec/support/helpers/model_helper.rb +0 -78
  252. data/spec/support/helpers/request_spec_helper.rb +0 -110
  253. data/spec/support/helpers/url_helper.rb +0 -62
  254. data/spec/support/http_method_shim.rb +0 -29
  255. data/spec/support/orm/active_record.rb +0 -5
  256. data/spec/support/shared/controllers_shared_context.rb +0 -123
  257. data/spec/support/shared/hashing_shared_context.rb +0 -36
  258. data/spec/support/shared/models_shared_examples.rb +0 -54
  259. data/spec/validators/redirect_uri_validator_spec.rb +0 -183
  260. data/spec/version/version_spec.rb +0 -17
@@ -1,222 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- module Doorkeeper::OAuth
6
- describe BaseRequest do
7
- let(:access_token) do
8
- double :access_token,
9
- plaintext_token: "some-token",
10
- expires_in: "3600",
11
- expires_in_seconds: "300",
12
- scopes_string: "two scopes",
13
- plaintext_refresh_token: "some-refresh-token",
14
- token_type: "bearer",
15
- created_at: 0
16
- end
17
-
18
- let(:client) { double :client, id: "1" }
19
-
20
- let(:scopes_array) { %w[public write] }
21
-
22
- let(:server) do
23
- double :server,
24
- access_token_expires_in: 100,
25
- custom_access_token_expires_in: ->(_context) { nil },
26
- refresh_token_enabled?: false
27
- end
28
-
29
- before do
30
- allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
31
- end
32
-
33
- subject do
34
- BaseRequest.new
35
- end
36
-
37
- describe "#authorize" do
38
- before do
39
- allow(subject).to receive(:access_token).and_return(access_token)
40
- end
41
-
42
- it "validates itself" do
43
- expect(subject).to receive(:validate).once
44
- subject.authorize
45
- end
46
-
47
- context "valid" do
48
- before do
49
- allow(subject).to receive(:valid?).and_return(true)
50
- end
51
-
52
- it "calls callback methods" do
53
- expect(subject).to receive(:before_successful_response).once
54
- expect(subject).to receive(:after_successful_response).once
55
- subject.authorize
56
- end
57
-
58
- it "returns a TokenResponse object" do
59
- result = subject.authorize
60
-
61
- expect(result).to be_an_instance_of(TokenResponse)
62
- expect(result.body).to eq(
63
- TokenResponse.new(access_token).body
64
- )
65
- end
66
- end
67
-
68
- context "invalid" do
69
- context "with error other than invalid_request" do
70
- before do
71
- allow(subject).to receive(:valid?).and_return(false)
72
- allow(subject).to receive(:error).and_return(:server_error)
73
- allow(subject).to receive(:state).and_return("hello")
74
- end
75
-
76
- it "returns an ErrorResponse object" do
77
- result = subject.authorize
78
-
79
- expect(result).to be_an_instance_of(ErrorResponse)
80
-
81
- expect(result.body).to eq(
82
- error: :server_error,
83
- error_description: translated_error_message(:server_error),
84
- state: "hello"
85
- )
86
- end
87
- end
88
-
89
- context "with invalid_request error" do
90
- before do
91
- allow(subject).to receive(:valid?).and_return(false)
92
- allow(subject).to receive(:error).and_return(:invalid_request)
93
- allow(subject).to receive(:state).and_return("hello")
94
- end
95
-
96
- it "returns an InvalidRequestResponse object" do
97
- result = subject.authorize
98
-
99
- expect(result).to be_an_instance_of(InvalidRequestResponse)
100
-
101
- expect(result.body).to eq(
102
- error: :invalid_request,
103
- error_description: translated_invalid_request_error_message(:unknown, :unknown),
104
- state: "hello"
105
- )
106
- end
107
- end
108
- end
109
- end
110
-
111
- describe "#default_scopes" do
112
- it "delegates to the server" do
113
- expect(subject).to receive(:server).and_return(server).once
114
- expect(server).to receive(:default_scopes).once
115
-
116
- subject.default_scopes
117
- end
118
- end
119
-
120
- describe "#find_or_create_access_token" do
121
- it "returns an instance of AccessToken" do
122
- result = subject.find_or_create_access_token(
123
- client,
124
- "1",
125
- "public",
126
- server
127
- )
128
-
129
- expect(result).to be_an_instance_of(Doorkeeper::AccessToken)
130
- end
131
-
132
- it "respects custom_access_token_expires_in" do
133
- server = double(:server,
134
- access_token_expires_in: 100,
135
- custom_access_token_expires_in: ->(context) { context.scopes == "public" ? 500 : nil },
136
- refresh_token_enabled?: false)
137
-
138
- allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
139
-
140
- result = subject.find_or_create_access_token(
141
- client,
142
- "1",
143
- "public",
144
- server
145
- )
146
- expect(result.expires_in).to eql(500)
147
- end
148
-
149
- it "respects use_refresh_token with a block" do
150
- server = double(:server,
151
- access_token_expires_in: 100,
152
- custom_access_token_expires_in: ->(_context) { nil },
153
- refresh_token_enabled?: lambda { |context|
154
- context.scopes == "public"
155
- })
156
-
157
- allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
158
-
159
- result = subject.find_or_create_access_token(
160
- client,
161
- "1",
162
- "public",
163
- server
164
- )
165
- expect(result.refresh_token).to_not be_nil
166
-
167
- result = subject.find_or_create_access_token(
168
- client,
169
- "1",
170
- "private",
171
- server
172
- )
173
- expect(result.refresh_token).to be_nil
174
- end
175
- end
176
-
177
- describe "#scopes" do
178
- context "@original_scopes is present" do
179
- before do
180
- subject.instance_variable_set(:@original_scopes, "public write")
181
- end
182
-
183
- it "returns array of @original_scopes" do
184
- result = subject.scopes
185
-
186
- expect(result).to eq(scopes_array)
187
- end
188
- end
189
-
190
- context "@original_scopes is not present" do
191
- before do
192
- subject.instance_variable_set(:@original_scopes, "")
193
- end
194
-
195
- it "calls #default_scopes" do
196
- allow(subject).to receive(:server).and_return(server).once
197
- allow(server).to receive(:default_scopes).and_return(scopes_array).once
198
-
199
- result = subject.scopes
200
-
201
- expect(result).to eq(scopes_array)
202
- end
203
- end
204
- end
205
-
206
- describe "#valid?" do
207
- context "error is nil" do
208
- it "returns true" do
209
- allow(subject).to receive(:error).and_return(nil).once
210
- expect(subject.valid?).to eq(true)
211
- end
212
- end
213
-
214
- context "error is not nil" do
215
- it "returns false" do
216
- allow(subject).to receive(:error).and_return(Object.new).once
217
- expect(subject.valid?).to eq(false)
218
- end
219
- end
220
- end
221
- end
222
- end
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- module Doorkeeper::OAuth
6
- describe BaseResponse do
7
- subject do
8
- BaseResponse.new
9
- end
10
-
11
- describe "#body" do
12
- it "returns an empty Hash" do
13
- expect(subject.body).to eq({})
14
- end
15
- end
16
-
17
- describe "#description" do
18
- it "returns an empty String" do
19
- expect(subject.description).to eq("")
20
- end
21
- end
22
-
23
- describe "#headers" do
24
- it "returns an empty Hash" do
25
- expect(subject.headers).to eq({})
26
- end
27
- end
28
-
29
- describe "#redirectable?" do
30
- it "returns false" do
31
- expect(subject.redirectable?).to eq(false)
32
- end
33
- end
34
-
35
- describe "#redirect_uri" do
36
- it "returns an empty String" do
37
- expect(subject.redirect_uri).to eq("")
38
- end
39
- end
40
-
41
- describe "#status" do
42
- it "returns :ok" do
43
- expect(subject.status).to eq(:ok)
44
- end
45
- end
46
- end
47
- end
@@ -1,90 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- class Doorkeeper::OAuth::Client
6
- describe Credentials do
7
- let(:client_id) { "some-uid" }
8
- let(:client_secret) { "some-secret" }
9
-
10
- it "is blank when the uid in credentials is blank" do
11
- expect(Credentials.new(nil, nil)).to be_blank
12
- expect(Credentials.new(nil, "something")).to be_blank
13
- expect(Credentials.new("something", nil)).to be_present
14
- expect(Credentials.new("something", "something")).to be_present
15
- end
16
-
17
- describe :from_request do
18
- let(:request) { double.as_null_object }
19
-
20
- let(:method) do
21
- ->(_request) { %w[uid secret] }
22
- end
23
-
24
- it "accepts anything that responds to #call" do
25
- expect(method).to receive(:call).with(request)
26
- Credentials.from_request request, method
27
- end
28
-
29
- it "delegates methods received as symbols to Credentials class" do
30
- expect(Credentials).to receive(:from_params).with(request)
31
- Credentials.from_request request, :from_params
32
- end
33
-
34
- it "stops at the first credentials found" do
35
- not_called_method = double
36
- expect(not_called_method).not_to receive(:call)
37
- Credentials.from_request request, ->(_) {}, method, not_called_method
38
- end
39
-
40
- it "returns new Credentials" do
41
- credentials = Credentials.from_request request, method
42
- expect(credentials).to be_a(Credentials)
43
- end
44
-
45
- it "returns uid and secret from extractor method" do
46
- credentials = Credentials.from_request request, method
47
- expect(credentials.uid).to eq("uid")
48
- expect(credentials.secret).to eq("secret")
49
- end
50
- end
51
-
52
- describe :from_params do
53
- it "returns credentials from parameters when Authorization header is not available" do
54
- request = double parameters: { client_id: client_id, client_secret: client_secret }
55
- uid, secret = Credentials.from_params(request)
56
-
57
- expect(uid).to eq("some-uid")
58
- expect(secret).to eq("some-secret")
59
- end
60
-
61
- it "is blank when there are no credentials" do
62
- request = double parameters: {}
63
- uid, secret = Credentials.from_params(request)
64
-
65
- expect(uid).to be_blank
66
- expect(secret).to be_blank
67
- end
68
- end
69
-
70
- describe :from_basic do
71
- let(:credentials) { Base64.encode64("#{client_id}:#{client_secret}") }
72
-
73
- it "decodes the credentials" do
74
- request = double authorization: "Basic #{credentials}"
75
- uid, secret = Credentials.from_basic(request)
76
-
77
- expect(uid).to eq("some-uid")
78
- expect(secret).to eq("some-secret")
79
- end
80
-
81
- it "is blank if Authorization is not Basic" do
82
- request = double authorization: credentials.to_s
83
- uid, secret = Credentials.from_basic(request)
84
-
85
- expect(uid).to be_blank
86
- expect(secret).to be_blank
87
- end
88
- end
89
- end
90
- end
@@ -1,97 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- class Doorkeeper::OAuth::ClientCredentialsRequest
6
- describe Creator do
7
- let(:client) { FactoryBot.create :application }
8
- let(:scopes) { Doorkeeper::OAuth::Scopes.from_string("public") }
9
-
10
- before do
11
- default_scopes_exist :public
12
- end
13
-
14
- it "creates a new token" do
15
- expect do
16
- subject.call(client, scopes)
17
- end.to change { Doorkeeper::AccessToken.count }.by(1)
18
- end
19
-
20
- context "when reuse_access_token is true" do
21
- context "when expiration is disabled" do
22
- it "returns the existing valid token" do
23
- allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
24
- existing_token = subject.call(client, scopes)
25
-
26
- result = subject.call(client, scopes)
27
-
28
- expect(Doorkeeper::AccessToken.count).to eq(1)
29
- expect(result).to eq(existing_token)
30
- end
31
- end
32
-
33
- context "when existing token has not crossed token_reuse_limit" do
34
- it "returns the existing valid token" do
35
- allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
36
- allow(Doorkeeper.configuration).to receive(:token_reuse_limit).and_return(50)
37
- existing_token = subject.call(client, scopes, expires_in: 1000)
38
-
39
- allow_any_instance_of(Doorkeeper::AccessToken).to receive(:expires_in_seconds).and_return(600)
40
- result = subject.call(client, scopes, expires_in: 1000)
41
-
42
- expect(Doorkeeper::AccessToken.count).to eq(1)
43
- expect(result).to eq(existing_token)
44
- end
45
- end
46
-
47
- context "when existing token has crossed token_reuse_limit" do
48
- it "returns a new token" do
49
- allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
50
- allow(Doorkeeper.configuration).to receive(:token_reuse_limit).and_return(50)
51
- existing_token = subject.call(client, scopes, expires_in: 1000)
52
-
53
- allow_any_instance_of(Doorkeeper::AccessToken).to receive(:expires_in_seconds).and_return(400)
54
- result = subject.call(client, scopes, expires_in: 1000)
55
-
56
- expect(Doorkeeper::AccessToken.count).to eq(2)
57
- expect(result).not_to eq(existing_token)
58
- expect(existing_token.reload).to be_revoked
59
- end
60
- end
61
-
62
- context "when existing token has been expired" do
63
- it "returns a new token" do
64
- allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
65
- allow(Doorkeeper.configuration).to receive(:token_reuse_limit).and_return(50)
66
- existing_token = subject.call(client, scopes, expires_in: 1000)
67
-
68
- allow_any_instance_of(Doorkeeper::AccessToken).to receive(:expired?).and_return(true)
69
- result = subject.call(client, scopes, expires_in: 1000)
70
-
71
- expect(Doorkeeper::AccessToken.count).to eq(2)
72
- expect(result).not_to eq(existing_token)
73
- expect(existing_token.reload).to be_revoked
74
- end
75
- end
76
- end
77
-
78
- context "when reuse_access_token is false" do
79
- it "returns a new token" do
80
- allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(false)
81
- existing_token = subject.call(client, scopes)
82
-
83
- result = subject.call(client, scopes)
84
-
85
- expect(Doorkeeper::AccessToken.count).to eq(2)
86
- expect(result).not_to eq(existing_token)
87
- expect(existing_token.reload).to be_revoked
88
- end
89
- end
90
-
91
- it "returns false if creation fails" do
92
- expect(Doorkeeper::AccessToken).to receive(:find_or_create_for).and_return(false)
93
- created = subject.call(client, scopes)
94
- expect(created).to be_falsey
95
- end
96
- end
97
- end
@@ -1,112 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- class Doorkeeper::OAuth::ClientCredentialsRequest
6
- describe Issuer do
7
- let(:creator) { double :access_token_creator }
8
- let(:server) do
9
- double(
10
- :server,
11
- access_token_expires_in: 100
12
- )
13
- end
14
- let(:validation) { double :validation, valid?: true }
15
-
16
- before do
17
- allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(false)
18
- end
19
-
20
- subject { Issuer.new(server, validation) }
21
-
22
- describe :create do
23
- let(:client) { double :client, id: "some-id" }
24
- let(:scopes) { "some scope" }
25
-
26
- it "creates and sets the token" do
27
- expect(creator).to receive(:call).and_return("token")
28
- subject.create client, scopes, creator
29
-
30
- expect(subject.token).to eq("token")
31
- end
32
-
33
- it "creates with correct token parameters" do
34
- expect(creator).to receive(:call).with(
35
- client,
36
- scopes,
37
- expires_in: 100,
38
- use_refresh_token: false
39
- )
40
-
41
- subject.create client, scopes, creator
42
- end
43
-
44
- it "has error set to :server_error if creator fails" do
45
- expect(creator).to receive(:call).and_return(false)
46
- subject.create client, scopes, creator
47
-
48
- expect(subject.error).to eq(:server_error)
49
- end
50
-
51
- context "when validation fails" do
52
- before do
53
- allow(validation).to receive(:valid?).and_return(false)
54
- allow(validation).to receive(:error).and_return(:validation_error)
55
- expect(creator).not_to receive(:create)
56
- end
57
-
58
- it "has error set from validation" do
59
- subject.create client, scopes, creator
60
- expect(subject.error).to eq(:validation_error)
61
- end
62
-
63
- it "returns false" do
64
- expect(subject.create(client, scopes, creator)).to be_falsey
65
- end
66
- end
67
-
68
- context "with custom expirations" do
69
- let(:custom_ttl_grant) { 1234 }
70
- let(:custom_ttl_scope) { 1235 }
71
- let(:custom_scope) { "special" }
72
- let(:server) do
73
- double(
74
- :server,
75
- custom_access_token_expires_in: lambda { |context|
76
- # scopes is normally an object but is a string in this test
77
- if context.scopes == custom_scope
78
- custom_ttl_scope
79
- elsif context.grant_type == Doorkeeper::OAuth::CLIENT_CREDENTIALS
80
- custom_ttl_grant
81
- end
82
- }
83
- )
84
- end
85
-
86
- before do
87
- allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
88
- end
89
-
90
- it "respects grant based rules" do
91
- expect(creator).to receive(:call).with(
92
- client,
93
- scopes,
94
- expires_in: custom_ttl_grant,
95
- use_refresh_token: false
96
- )
97
- subject.create client, scopes, creator
98
- end
99
-
100
- it "respects scope based rules" do
101
- expect(creator).to receive(:call).with(
102
- client,
103
- custom_scope,
104
- expires_in: custom_ttl_scope,
105
- use_refresh_token: false
106
- )
107
- subject.create client, custom_scope, creator
108
- end
109
- end
110
- end
111
- end
112
- end
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- class Doorkeeper::OAuth::ClientCredentialsRequest
6
- describe Validation do
7
- let(:server) { double :server, scopes: nil }
8
- let(:application) { double scopes: nil }
9
- let(:client) { double application: application }
10
- let(:request) { double :request, client: client, scopes: nil }
11
-
12
- subject { Validation.new(server, request) }
13
-
14
- it "is valid with valid request" do
15
- expect(subject).to be_valid
16
- end
17
-
18
- it "is invalid when client is not present" do
19
- allow(request).to receive(:client).and_return(nil)
20
- expect(subject).not_to be_valid
21
- end
22
-
23
- context "with scopes" do
24
- it "is invalid when scopes are not included in the server" do
25
- server_scopes = Doorkeeper::OAuth::Scopes.from_string "email"
26
- allow(request).to receive(:grant_type).and_return(Doorkeeper::OAuth::CLIENT_CREDENTIALS)
27
- allow(server).to receive(:scopes).and_return(server_scopes)
28
- allow(request).to receive(:scopes).and_return(
29
- Doorkeeper::OAuth::Scopes.from_string("invalid")
30
- )
31
- expect(subject).not_to be_valid
32
- end
33
-
34
- context "with application scopes" do
35
- it "is valid when scopes are included in the application" do
36
- application_scopes = Doorkeeper::OAuth::Scopes.from_string "app"
37
- server_scopes = Doorkeeper::OAuth::Scopes.from_string "email app"
38
- allow(application).to receive(:scopes).and_return(application_scopes)
39
- allow(server).to receive(:scopes).and_return(server_scopes)
40
- allow(request).to receive(:grant_type).and_return(Doorkeeper::OAuth::CLIENT_CREDENTIALS)
41
- allow(request).to receive(:scopes).and_return(application_scopes)
42
- expect(subject).to be_valid
43
- end
44
-
45
- it "is invalid when scopes are not included in the application" do
46
- application_scopes = Doorkeeper::OAuth::Scopes.from_string "app"
47
- server_scopes = Doorkeeper::OAuth::Scopes.from_string "email app"
48
- allow(application).to receive(:scopes).and_return(application_scopes)
49
- allow(request).to receive(:grant_type).and_return(Doorkeeper::OAuth::CLIENT_CREDENTIALS)
50
- allow(server).to receive(:scopes).and_return(server_scopes)
51
- allow(request).to receive(:scopes).and_return(
52
- Doorkeeper::OAuth::Scopes.from_string("email")
53
- )
54
- expect(subject).not_to be_valid
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- module Doorkeeper::OAuth
6
- describe ClientCredentialsRequest do
7
- let(:server) { Doorkeeper.configuration }
8
-
9
- context "with a valid request" do
10
- let(:client) { FactoryBot.create :application }
11
-
12
- it "issues an access token" do
13
- request = ClientCredentialsRequest.new(server, client, {})
14
- expect do
15
- request.authorize
16
- end.to change { Doorkeeper::AccessToken.count }.by(1)
17
- end
18
- end
19
-
20
- describe "with an invalid request" do
21
- it "does not issue an access token" do
22
- request = ClientCredentialsRequest.new(server, nil, {})
23
- expect do
24
- request.authorize
25
- end.to_not(change { Doorkeeper::AccessToken.count })
26
- end
27
- end
28
- end
29
- end