doorkeeper-mongodb 5.2.1 → 5.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -27
- data/lib/doorkeeper/orm/concerns/mongoid/ownership.rb +1 -1
- data/lib/doorkeeper/orm/concerns/mongoid/resource_ownerable.rb +1 -1
- data/lib/doorkeeper/orm/mongoid4.rb +18 -0
- data/lib/doorkeeper/orm/mongoid5.rb +18 -0
- data/lib/doorkeeper/orm/mongoid6.rb +18 -0
- data/lib/doorkeeper/orm/mongoid7.rb +18 -0
- data/lib/doorkeeper-mongodb/mixins/mongoid/access_grant_mixin.rb +7 -6
- data/lib/doorkeeper-mongodb/mixins/mongoid/access_token_mixin.rb +8 -5
- data/lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb +82 -5
- data/lib/doorkeeper-mongodb/mixins/mongoid/base_mixin.rb +0 -8
- data/lib/doorkeeper-mongodb/mixins/mongoid/json_serializable.rb +17 -0
- data/lib/doorkeeper-mongodb/version.rb +1 -1
- data/lib/doorkeeper-mongodb.rb +1 -0
- data/spec/controllers/application_metal_controller_spec.rb +4 -4
- data/spec/controllers/applications_controller_spec.rb +198 -202
- data/spec/controllers/authorizations_controller_spec.rb +32 -31
- data/spec/controllers/protected_resources_controller_spec.rb +10 -10
- data/spec/controllers/token_info_controller_spec.rb +1 -1
- data/spec/controllers/tokens_controller_spec.rb +105 -62
- data/spec/doorkeeper/redirect_uri_validator_spec.rb +183 -0
- data/spec/{lib → doorkeeper}/server_spec.rb +5 -4
- data/spec/{lib → doorkeeper}/stale_records_cleaner_spec.rb +8 -7
- data/spec/{version → doorkeeper}/version_spec.rb +3 -3
- data/spec/dummy/app/assets/config/manifest.js +0 -0
- data/spec/dummy/app/controllers/application_controller.rb +0 -0
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +0 -0
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +0 -0
- data/spec/dummy/app/controllers/home_controller.rb +0 -0
- data/spec/dummy/app/controllers/metal_controller.rb +0 -0
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +0 -0
- data/spec/dummy/app/models/user.rb +0 -1
- data/spec/dummy/app/views/home/index.html.erb +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +0 -0
- data/spec/dummy/config/application.rb +0 -0
- data/spec/dummy/config/boot.rb +0 -0
- data/spec/dummy/config/database.yml +0 -0
- data/spec/dummy/config/environment.rb +0 -0
- data/spec/dummy/config/environments/development.rb +0 -0
- data/spec/dummy/config/environments/production.rb +0 -0
- data/spec/dummy/config/environments/test.rb +0 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/dummy/config/initializers/doorkeeper.rb +0 -0
- data/spec/dummy/config/initializers/secret_token.rb +0 -0
- data/spec/dummy/config/initializers/session_store.rb +0 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -0
- data/spec/dummy/config/locales/doorkeeper.en.yml +0 -0
- data/spec/dummy/config/mongo.yml +2 -2
- data/spec/dummy/config/routes.rb +0 -0
- data/spec/dummy/config.ru +0 -0
- data/spec/dummy/db/migrate/20111122132257_create_users.rb +0 -0
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +0 -0
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +0 -0
- data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +0 -0
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +0 -0
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +0 -0
- data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +0 -0
- data/spec/dummy/db/schema.rb +0 -0
- data/spec/dummy/public/404.html +0 -0
- data/spec/dummy/public/422.html +0 -0
- data/spec/dummy/public/500.html +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/-o/-ofn45zIfO5vx4VD6m6NXesLf6da5usA-Sbw2SVju3o.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/0_/0_ouGcG_o_1zmVmBe-tdQYk594LBwVa1bumjrKtdfEw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/2X/2XMMcHbyTSRqh1GkV0xzyIETNtt-zgN6iniziShaKmQ.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/4Q/4QQw-pMQ98JIj3xdcFhGBQdysdGPY9rWffRqWMmyjew.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/7H/7HjRsym0tTpXFCVhWt6kteMs_-CozKVbr9s5syHm8es.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8B/8BxJyv22HPFHu1se_l2J8qW1N9NzZ16UOWOy1YMSgs4.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8D/8DJG7JfPvShfLLyeSom6NZ_TcQc6QH27tJ7prEWZPfI.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/9x/9xjtGv-yKjj62x9uFwBZg8pTSh9ERPAgANwNo9uwIaA.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Bt/BtXO7f0PZ8DNt3TMLYM-zY7LkbWa_KgyB0v1V98M1CQ.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/E0/E02f1Q2tutWumMulGCFNfqQNjvEP_hMAK_5E83eWepI.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/EZ/EZGpd6pUEJZxO6uT2yIS4Fpn5KX7VDgC9VB3AaemF5Q.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/FJ/FJlQpfMtpRbrM5P8A7d2FAelFKwo6GrVs2xks8z5GKU.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/L8/L8mOWakJlWKr6MU85rj0V7yGFfNyIR6vE6YXtqArPGw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Lk/LklIq5hrBAPESXVUpFMwQ9L-1qTj90sPVi6U19_Xi-Q.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/MB/MBWRxa9S470ee8suxVKp0jYgv6K6FQOqKGV0kPGQNMs.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ma/MaK3K1AoZZ4xM5fOOifhROd73hfZJpP4yGbkGdoYtEk.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/PA/PAH_jI20wRw12tngeJ-V619c30avNLDu5U9Z-9Pc5SQ.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ph/Ph7RtH_NvG2I8XpTa8mA8SBQXZDzBPVIh4CH6g7OXJ0.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{eS/eSL1QMz46gKLM0GR6S9fL6uyARPxOImcappZ9_ZtSyg.cache → Pm/PmheG0PGFqDws1qgFOxOyIL-gpMof3Ar9eSRKVLYuik.cache} +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Pn/PnXU_mkG2fLZFm9BwiZ03BZdBTjKuInP-cRXjHS7yJo.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Qs/QsVgO6vM5Yn9oeYTYlrqtyVnK6sdVDWDa083N7zpfHw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/So/So59ksdx2dw-_A3-zFZ6Palr7fROjm7_0JDZb04temw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Wt/WtXL_iDofLeTH_v0Yf3PM421r9b1V0g-VBvMPeu9KA0.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/b6/b6QRH6ZdCc0e6bUWu4qni_kZmptaMgWciO8Jl9q6_p8.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/dX/dX6FDdUIy8yBCOoaoXcjf71rX9N_bpiXGJ4Urt32NTk.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/jC/jCTZ1jAldKBn4OTANBBmCKzxLrDgok1ur4meoTqlDNg.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/qT/qTQIQsmS0Wbbg2JxNn9rxdI5qVOTg5SfyQdaTvr9vLo.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/yN/yNOFGOsnHmxXNMkuEAWuL1u3jlmdvrdeoTx6DDJ1in8.cache +0 -0
- data/spec/factories.rb +0 -0
- data/spec/grape/grape_integration_spec.rb +1 -1
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
- data/spec/lib/config_spec.rb +23 -12
- data/spec/lib/doorkeeper_spec.rb +4 -4
- data/spec/lib/models/expirable_spec.rb +9 -9
- data/spec/lib/models/reusable_spec.rb +2 -2
- data/spec/lib/models/revocable_spec.rb +4 -7
- data/spec/lib/models/scopes_spec.rb +7 -7
- data/spec/lib/models/secret_storable_spec.rb +9 -8
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +23 -27
- data/spec/lib/oauth/authorization_code_request_spec.rb +6 -6
- data/spec/lib/oauth/base_request_spec.rb +11 -27
- data/spec/lib/oauth/base_response_spec.rb +2 -2
- data/spec/lib/oauth/client/credentials_spec.rb +25 -25
- data/spec/lib/oauth/client_credentials/creator_spec.rb +89 -91
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +84 -86
- data/spec/lib/oauth/client_credentials/validation_spec.rb +72 -39
- data/spec/lib/oauth/client_credentials_integration_spec.rb +5 -5
- data/spec/lib/oauth/client_credentials_request_spec.rb +7 -10
- data/spec/lib/oauth/client_spec.rb +8 -8
- data/spec/lib/oauth/code_request_spec.rb +5 -5
- data/spec/lib/oauth/code_response_spec.rb +4 -4
- data/spec/lib/oauth/error_response_spec.rb +6 -5
- data/spec/lib/oauth/error_spec.rb +1 -1
- data/spec/lib/oauth/forbidden_token_response_spec.rb +2 -2
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +37 -37
- data/spec/lib/oauth/helpers/unique_token_spec.rb +2 -2
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +54 -54
- data/spec/lib/oauth/invalid_request_response_spec.rb +6 -6
- data/spec/lib/oauth/invalid_token_response_spec.rb +4 -4
- data/spec/lib/oauth/password_access_token_request_spec.rb +10 -9
- data/spec/lib/oauth/pre_authorization_spec.rb +20 -8
- data/spec/lib/oauth/refresh_token_request_spec.rb +10 -10
- data/spec/lib/oauth/scopes_spec.rb +14 -14
- data/spec/lib/oauth/token_request_spec.rb +9 -9
- data/spec/lib/oauth/token_response_spec.rb +5 -5
- data/spec/lib/oauth/token_spec.rb +5 -5
- data/spec/lib/option_spec.rb +1 -1
- data/spec/lib/request/strategy_spec.rb +34 -37
- data/spec/lib/secret_storing/base_spec.rb +3 -2
- data/spec/lib/secret_storing/bcrypt_spec.rb +2 -1
- data/spec/lib/secret_storing/plain_spec.rb +2 -1
- data/spec/lib/secret_storing/sha256_hash_spec.rb +2 -1
- data/spec/models/doorkeeper/access_grant_spec.rb +7 -9
- data/spec/models/doorkeeper/access_token_spec.rb +20 -26
- data/spec/models/doorkeeper/application_spec.rb +83 -26
- data/spec/requests/applications/applications_request_spec.rb +91 -93
- data/spec/requests/applications/authorized_applications_spec.rb +0 -0
- data/spec/requests/endpoints/authorization_spec.rb +1 -1
- data/spec/requests/endpoints/token_spec.rb +22 -16
- data/spec/requests/flows/authorization_code_errors_spec.rb +12 -8
- data/spec/requests/flows/authorization_code_spec.rb +108 -79
- data/spec/requests/flows/client_credentials_spec.rb +57 -45
- data/spec/requests/flows/implicit_grant_errors_spec.rb +0 -0
- data/spec/requests/flows/implicit_grant_spec.rb +4 -4
- data/spec/requests/flows/password_spec.rb +253 -213
- data/spec/requests/flows/refresh_token_spec.rb +53 -39
- data/spec/requests/flows/revoke_token_spec.rb +24 -24
- data/spec/requests/flows/skip_authorization_spec.rb +1 -1
- data/spec/requests/protected_resources/metal_spec.rb +2 -2
- data/spec/requests/protected_resources/private_api_spec.rb +0 -0
- data/spec/routing/custom_controller_routes_spec.rb +1 -1
- data/spec/routing/default_routes_spec.rb +1 -1
- data/spec/routing/scoped_routes_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -0
- data/spec/spec_helper_integration.rb +0 -0
- data/spec/support/dependencies/factory_bot.rb +0 -0
- data/spec/support/doorkeeper_rspec.rb +0 -0
- data/spec/support/helpers/access_token_request_helper.rb +0 -0
- data/spec/support/helpers/authorization_request_helper.rb +0 -0
- data/spec/support/helpers/config_helper.rb +0 -0
- data/spec/support/helpers/model_helper.rb +0 -0
- data/spec/support/helpers/request_spec_helper.rb +1 -13
- data/spec/support/helpers/url_helper.rb +2 -2
- data/spec/support/orm/active_record.rb +0 -0
- data/spec/support/orm/mongoid4.rb +1 -1
- data/spec/support/orm/mongoid5.rb +1 -1
- data/spec/support/orm/mongoid6.rb +1 -1
- data/spec/support/orm/mongoid7.rb +1 -1
- data/spec/support/shared/controllers_shared_context.rb +5 -38
- data/spec/support/shared/hashing_shared_context.rb +4 -0
- data/spec/support/shared/models_shared_examples.rb +6 -6
- metadata +154 -167
- data/spec/dummy/log/test.log +0 -6108
@@ -2,12 +2,15 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
describe Doorkeeper::TokensController do
|
5
|
+
RSpec.describe Doorkeeper::TokensController do
|
6
|
+
subject { JSON.parse(response.body) }
|
7
|
+
|
6
8
|
let(:client) { FactoryBot.create :application }
|
7
9
|
let!(:user) { User.create!(name: "Joe", password: "sekret") }
|
8
10
|
|
9
11
|
before do
|
10
12
|
Doorkeeper.configure do
|
13
|
+
orm DOORKEEPER_ORM
|
11
14
|
resource_owner_from_credentials do
|
12
15
|
User.first
|
13
16
|
end
|
@@ -16,8 +19,6 @@ describe Doorkeeper::TokensController do
|
|
16
19
|
allow(Doorkeeper.configuration).to receive(:grant_flows).and_return(["password"])
|
17
20
|
end
|
18
21
|
|
19
|
-
subject { JSON.parse(response.body) }
|
20
|
-
|
21
22
|
describe "POST #create" do
|
22
23
|
before do
|
23
24
|
post :create, params: {
|
@@ -70,7 +71,7 @@ describe Doorkeeper::TokensController do
|
|
70
71
|
end
|
71
72
|
|
72
73
|
it "include error_description in response" do
|
73
|
-
expect(subject["error_description"]).to
|
74
|
+
expect(subject["error_description"]).to be_present
|
74
75
|
end
|
75
76
|
|
76
77
|
it "does not include access token in response" do
|
@@ -104,12 +105,12 @@ describe Doorkeeper::TokensController do
|
|
104
105
|
}
|
105
106
|
end
|
106
107
|
|
107
|
-
it "
|
108
|
+
it "calls :before_successful_authorization callback" do
|
108
109
|
expect(Doorkeeper.configuration)
|
109
110
|
.to receive_message_chain(:before_successful_authorization, :call).with(instance_of(described_class), nil)
|
110
111
|
end
|
111
112
|
|
112
|
-
it "
|
113
|
+
it "calls :after_successful_authorization callback" do
|
113
114
|
expect(Doorkeeper.configuration)
|
114
115
|
.to receive_message_chain(:after_successful_authorization, :call)
|
115
116
|
.with(instance_of(described_class), instance_of(Doorkeeper::OAuth::Hooks::Context))
|
@@ -125,12 +126,12 @@ describe Doorkeeper::TokensController do
|
|
125
126
|
}
|
126
127
|
end
|
127
128
|
|
128
|
-
it "
|
129
|
+
it "calls :before_successful_authorization callback" do
|
129
130
|
expect(Doorkeeper.configuration)
|
130
131
|
.to receive_message_chain(:before_successful_authorization, :call).with(instance_of(described_class), nil)
|
131
132
|
end
|
132
133
|
|
133
|
-
it "
|
134
|
+
it "does not call :after_successful_authorization callback" do
|
134
135
|
expect(Doorkeeper.configuration).not_to receive(:after_successful_authorization)
|
135
136
|
end
|
136
137
|
end
|
@@ -190,9 +191,11 @@ describe Doorkeeper::TokensController do
|
|
190
191
|
context "when associated app is confidential" do
|
191
192
|
let(:client) { FactoryBot.create(:application, confidential: true) }
|
192
193
|
let(:oauth_client) { Doorkeeper::OAuth::Client.new(client) }
|
194
|
+
let(:server) { instance_double(Doorkeeper::Server) }
|
193
195
|
|
194
|
-
before
|
195
|
-
|
196
|
+
before do
|
197
|
+
allow(Doorkeeper::Server).to receive(:new).and_return(server)
|
198
|
+
allow(server).to receive(:client).and_return(oauth_client)
|
196
199
|
end
|
197
200
|
|
198
201
|
it "returns 200" do
|
@@ -231,30 +234,35 @@ describe Doorkeeper::TokensController do
|
|
231
234
|
let(:access_token) { FactoryBot.create(:access_token, application: client) }
|
232
235
|
let(:token_for_introspection) { FactoryBot.create(:access_token, application: client) }
|
233
236
|
|
234
|
-
context "authorized using valid Bearer token" do
|
237
|
+
context "when authorized using valid Bearer token" do
|
235
238
|
it "responds with full token introspection" do
|
236
239
|
request.headers["Authorization"] = "Bearer #{access_token.token}"
|
237
240
|
|
238
241
|
post :introspect, params: { token: token_for_introspection.token }
|
239
242
|
|
240
|
-
|
243
|
+
expect(json_response).to include("active" => true)
|
241
244
|
expect(json_response).to include("client_id", "token_type", "exp", "iat")
|
242
245
|
end
|
243
246
|
end
|
244
247
|
|
245
|
-
context "authorized using Client Credentials of the client that token is issued to" do
|
248
|
+
context "when authorized using Client Credentials of the client that token is issued to" do
|
246
249
|
it "responds with full token introspection" do
|
247
250
|
request.headers["Authorization"] = basic_auth_header_for_client(client)
|
248
251
|
|
249
252
|
post :introspect, params: { token: token_for_introspection.token }
|
250
253
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
+
expect(json_response).to match(
|
255
|
+
"active" => true,
|
256
|
+
"client_id" => client.uid,
|
257
|
+
"token_type" => "Bearer",
|
258
|
+
"scope" => nil,
|
259
|
+
"exp" => an_instance_of(Integer),
|
260
|
+
"iat" => an_instance_of(Integer),
|
261
|
+
)
|
254
262
|
end
|
255
263
|
end
|
256
264
|
|
257
|
-
context "
|
265
|
+
context "when token introspection disabled" do
|
258
266
|
before do
|
259
267
|
Doorkeeper.configure do
|
260
268
|
orm DOORKEEPER_ORM
|
@@ -269,12 +277,12 @@ describe Doorkeeper::TokensController do
|
|
269
277
|
|
270
278
|
response_status_should_be 401
|
271
279
|
|
272
|
-
|
273
|
-
|
280
|
+
expect(json_response).not_to include("active")
|
281
|
+
expect(json_response).to include("error" => "invalid_token")
|
274
282
|
end
|
275
283
|
end
|
276
284
|
|
277
|
-
context "
|
285
|
+
context "when custom introspection response configured" do
|
278
286
|
before do
|
279
287
|
Doorkeeper.configure do
|
280
288
|
orm DOORKEEPER_ORM
|
@@ -292,13 +300,20 @@ describe Doorkeeper::TokensController do
|
|
292
300
|
|
293
301
|
post :introspect, params: { token: token_for_introspection.token }
|
294
302
|
|
295
|
-
expect(json_response).to
|
296
|
-
|
297
|
-
|
303
|
+
expect(json_response).to match(
|
304
|
+
"active" => true,
|
305
|
+
"client_id" => client.uid,
|
306
|
+
"token_type" => "Bearer",
|
307
|
+
"scope" => nil,
|
308
|
+
"exp" => an_instance_of(Integer),
|
309
|
+
"iat" => an_instance_of(Integer),
|
310
|
+
"aud" => "https://protected.example.net/resource",
|
311
|
+
"sub" => "Z5O3upPC88QrAjx00dis",
|
312
|
+
)
|
298
313
|
end
|
299
314
|
end
|
300
315
|
|
301
|
-
context "
|
316
|
+
context "when access token is public" do
|
302
317
|
let(:token_for_introspection) { FactoryBot.create(:access_token, application: nil) }
|
303
318
|
|
304
319
|
it "responds with full token introspection" do
|
@@ -306,13 +321,18 @@ describe Doorkeeper::TokensController do
|
|
306
321
|
|
307
322
|
post :introspect, params: { token: token_for_introspection.token }
|
308
323
|
|
309
|
-
|
310
|
-
|
311
|
-
|
324
|
+
expect(json_response).to match(
|
325
|
+
"active" => true,
|
326
|
+
"client_id" => nil,
|
327
|
+
"token_type" => "Bearer",
|
328
|
+
"scope" => nil,
|
329
|
+
"exp" => an_instance_of(Integer),
|
330
|
+
"iat" => an_instance_of(Integer),
|
331
|
+
)
|
312
332
|
end
|
313
333
|
end
|
314
334
|
|
315
|
-
context "token was issued to a different client than is making this request" do
|
335
|
+
context "when token was issued to a different client than is making this request" do
|
316
336
|
let(:different_client) { FactoryBot.create(:application) }
|
317
337
|
|
318
338
|
it "responds with only active state" do
|
@@ -322,12 +342,11 @@ describe Doorkeeper::TokensController do
|
|
322
342
|
|
323
343
|
expect(response).to be_successful
|
324
344
|
|
325
|
-
|
326
|
-
expect(json_response).not_to include("client_id", "token_type", "exp", "iat")
|
345
|
+
expect(json_response).to match("active" => false)
|
327
346
|
end
|
328
347
|
end
|
329
348
|
|
330
|
-
context "introspection request authorized by a client and allow_token_introspection is true" do
|
349
|
+
context "when introspection request authorized by a client and allow_token_introspection is true" do
|
331
350
|
let(:different_client) { FactoryBot.create(:application) }
|
332
351
|
|
333
352
|
before do
|
@@ -341,13 +360,18 @@ describe Doorkeeper::TokensController do
|
|
341
360
|
|
342
361
|
post :introspect, params: { token: token_for_introspection.token }
|
343
362
|
|
344
|
-
|
345
|
-
|
346
|
-
|
363
|
+
expect(json_response).to match(
|
364
|
+
"active" => true,
|
365
|
+
"client_id" => client.uid,
|
366
|
+
"token_type" => "Bearer",
|
367
|
+
"scope" => nil,
|
368
|
+
"exp" => an_instance_of(Integer),
|
369
|
+
"iat" => an_instance_of(Integer),
|
370
|
+
)
|
347
371
|
end
|
348
372
|
end
|
349
373
|
|
350
|
-
context "allow_token_introspection requires authorized token with special scope" do
|
374
|
+
context "when allow_token_introspection requires authorized token with special scope" do
|
351
375
|
let(:access_token) { FactoryBot.create(:access_token, scopes: "introspection") }
|
352
376
|
|
353
377
|
before do
|
@@ -361,8 +385,14 @@ describe Doorkeeper::TokensController do
|
|
361
385
|
|
362
386
|
post :introspect, params: { token: token_for_introspection.token }
|
363
387
|
|
364
|
-
|
365
|
-
|
388
|
+
expect(json_response).to match(
|
389
|
+
"active" => true,
|
390
|
+
"client_id" => client.uid,
|
391
|
+
"token_type" => "Bearer",
|
392
|
+
"scope" => nil,
|
393
|
+
"exp" => an_instance_of(Integer),
|
394
|
+
"iat" => an_instance_of(Integer),
|
395
|
+
)
|
366
396
|
end
|
367
397
|
|
368
398
|
it "responds with invalid_token error if authorized token doesn't have introspection scope" do
|
@@ -374,12 +404,15 @@ describe Doorkeeper::TokensController do
|
|
374
404
|
|
375
405
|
response_status_should_be 401
|
376
406
|
|
377
|
-
|
378
|
-
|
407
|
+
expect(json_response).to match(
|
408
|
+
"error" => "invalid_token",
|
409
|
+
"error_description" => an_instance_of(String),
|
410
|
+
"state" => "unauthorized",
|
411
|
+
)
|
379
412
|
end
|
380
413
|
end
|
381
414
|
|
382
|
-
context "authorized using invalid Bearer token" do
|
415
|
+
context "when authorized using invalid Bearer token" do
|
383
416
|
let(:access_token) do
|
384
417
|
FactoryBot.create(:access_token, application: client, revoked_at: 1.day.ago)
|
385
418
|
end
|
@@ -391,12 +424,15 @@ describe Doorkeeper::TokensController do
|
|
391
424
|
|
392
425
|
response_status_should_be 401
|
393
426
|
|
394
|
-
|
395
|
-
|
427
|
+
expect(json_response).to match(
|
428
|
+
"error" => "invalid_token",
|
429
|
+
"error_description" => an_instance_of(String),
|
430
|
+
"state" => "unauthorized",
|
431
|
+
)
|
396
432
|
end
|
397
433
|
end
|
398
434
|
|
399
|
-
context "authorized using the Bearer token that need to be introspected" do
|
435
|
+
context "when authorized using the Bearer token that need to be introspected" do
|
400
436
|
it "responds with invalid token error" do
|
401
437
|
request.headers["Authorization"] = "Bearer #{access_token.token}"
|
402
438
|
|
@@ -404,12 +440,15 @@ describe Doorkeeper::TokensController do
|
|
404
440
|
|
405
441
|
response_status_should_be 401
|
406
442
|
|
407
|
-
|
408
|
-
|
443
|
+
expect(json_response).to match(
|
444
|
+
"error" => "invalid_token",
|
445
|
+
"error_description" => an_instance_of(String),
|
446
|
+
"state" => "unauthorized",
|
447
|
+
)
|
409
448
|
end
|
410
449
|
end
|
411
450
|
|
412
|
-
context "
|
451
|
+
context "when invalid credentials used to authorize" do
|
413
452
|
let(:client) { double(uid: "123123", secret: "666999") }
|
414
453
|
let(:access_token) { FactoryBot.create(:access_token) }
|
415
454
|
|
@@ -421,24 +460,25 @@ describe Doorkeeper::TokensController do
|
|
421
460
|
expect(response).not_to be_successful
|
422
461
|
response_status_should_be 401
|
423
462
|
|
424
|
-
|
425
|
-
|
463
|
+
expect(json_response).to match(
|
464
|
+
"error" => "invalid_client",
|
465
|
+
"error_description" => an_instance_of(String),
|
466
|
+
)
|
426
467
|
end
|
427
468
|
end
|
428
469
|
|
429
|
-
context "
|
430
|
-
context "authorized using client credentials" do
|
470
|
+
context "when wrong token value used" do
|
471
|
+
context "when authorized using client credentials" do
|
431
472
|
it "responds with only active state" do
|
432
473
|
request.headers["Authorization"] = basic_auth_header_for_client(client)
|
433
474
|
|
434
475
|
post :introspect, params: { token: SecureRandom.hex(16) }
|
435
476
|
|
436
|
-
|
437
|
-
expect(json_response).not_to include("client_id", "token_type", "exp", "iat")
|
477
|
+
expect(json_response).to match("active" => false)
|
438
478
|
end
|
439
479
|
end
|
440
480
|
|
441
|
-
context "authorized using valid Bearer token" do
|
481
|
+
context "when authorized using valid Bearer token" do
|
442
482
|
it "responds with invalid_token error" do
|
443
483
|
request.headers["Authorization"] = "Bearer #{access_token.token}"
|
444
484
|
|
@@ -446,8 +486,11 @@ describe Doorkeeper::TokensController do
|
|
446
486
|
|
447
487
|
response_status_should_be 401
|
448
488
|
|
449
|
-
|
450
|
-
|
489
|
+
expect(json_response).to match(
|
490
|
+
"error" => "invalid_token",
|
491
|
+
"error_description" => an_instance_of(String),
|
492
|
+
"state" => "unauthorized",
|
493
|
+
)
|
451
494
|
end
|
452
495
|
end
|
453
496
|
end
|
@@ -462,8 +505,7 @@ describe Doorkeeper::TokensController do
|
|
462
505
|
|
463
506
|
post :introspect, params: { token: token_for_introspection.token }
|
464
507
|
|
465
|
-
|
466
|
-
expect(json_response).not_to include("client_id", "token_type", "exp", "iat")
|
508
|
+
expect(json_response).to match("active" => false)
|
467
509
|
end
|
468
510
|
end
|
469
511
|
|
@@ -477,12 +519,11 @@ describe Doorkeeper::TokensController do
|
|
477
519
|
|
478
520
|
post :introspect, params: { token: token_for_introspection.token }
|
479
521
|
|
480
|
-
|
481
|
-
expect(json_response).not_to include("client_id", "token_type", "exp", "iat")
|
522
|
+
expect(json_response).to match("active" => false)
|
482
523
|
end
|
483
524
|
end
|
484
525
|
|
485
|
-
context "unauthorized (no bearer token or client credentials)" do
|
526
|
+
context "when unauthorized (no bearer token or client credentials)" do
|
486
527
|
let(:token_for_introspection) { FactoryBot.create(:access_token) }
|
487
528
|
|
488
529
|
it "responds with invalid_request error" do
|
@@ -491,8 +532,10 @@ describe Doorkeeper::TokensController do
|
|
491
532
|
expect(response).not_to be_successful
|
492
533
|
response_status_should_be 400
|
493
534
|
|
494
|
-
|
495
|
-
|
535
|
+
expect(json_response).to match(
|
536
|
+
"error" => "invalid_request",
|
537
|
+
"error_description" => an_instance_of(String),
|
538
|
+
)
|
496
539
|
end
|
497
540
|
end
|
498
541
|
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe Doorkeeper::RedirectUriValidator do
|
6
|
+
subject(:client) do
|
7
|
+
FactoryBot.create(:application)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "is valid when the uri is a uri" do
|
11
|
+
client.redirect_uri = "https://example.com/callback"
|
12
|
+
expect(client).to be_valid
|
13
|
+
end
|
14
|
+
|
15
|
+
# Most mobile and desktop operating systems allow apps to register a custom URL
|
16
|
+
# scheme that will launch the app when a URL with that scheme is visited from
|
17
|
+
# the system browser.
|
18
|
+
#
|
19
|
+
# @see https://www.oauth.com/oauth2-servers/redirect-uris/redirect-uris-native-apps/
|
20
|
+
it "is valid when the uri is custom native URI" do
|
21
|
+
client.redirect_uri = "myapp:/callback"
|
22
|
+
expect(client).to be_valid
|
23
|
+
end
|
24
|
+
|
25
|
+
it "is valid when the uri has a query parameter" do
|
26
|
+
client.redirect_uri = "https://example.com/abcd?xyz=123"
|
27
|
+
expect(client).to be_valid
|
28
|
+
end
|
29
|
+
|
30
|
+
it "accepts nonstandard oob redirect uri" do
|
31
|
+
client.redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
|
32
|
+
expect(client).to be_valid
|
33
|
+
end
|
34
|
+
|
35
|
+
it "accepts nonstandard oob:auto redirect uri" do
|
36
|
+
client.redirect_uri = "urn:ietf:wg:oauth:2.0:oob:auto"
|
37
|
+
expect(client).to be_valid
|
38
|
+
end
|
39
|
+
|
40
|
+
it "is invalid when the uri is not a uri" do
|
41
|
+
client.redirect_uri = "]"
|
42
|
+
expect(client).not_to be_valid
|
43
|
+
expect(client.errors[:redirect_uri].first).to eq(I18n.t("activerecord.errors.models.doorkeeper/application.attributes.redirect_uri.invalid_uri"))
|
44
|
+
end
|
45
|
+
|
46
|
+
it "is invalid when the uri is relative" do
|
47
|
+
client.redirect_uri = "/abcd"
|
48
|
+
expect(client).not_to be_valid
|
49
|
+
expect(client.errors[:redirect_uri].first).to eq(I18n.t("activerecord.errors.models.doorkeeper/application.attributes.redirect_uri.relative_uri"))
|
50
|
+
end
|
51
|
+
|
52
|
+
it "is invalid when the uri has a fragment" do
|
53
|
+
client.redirect_uri = "https://example.com/abcd#xyz"
|
54
|
+
expect(client).not_to be_valid
|
55
|
+
expect(client.errors[:redirect_uri].first).to eq(I18n.t("activerecord.errors.models.doorkeeper/application.attributes.redirect_uri.fragment_present"))
|
56
|
+
end
|
57
|
+
|
58
|
+
it "is invalid when scheme resolves to localhost (needs an explict scheme)" do
|
59
|
+
client.redirect_uri = "localhost:80"
|
60
|
+
expect(client).to be_invalid
|
61
|
+
expect(client.errors[:redirect_uri].first).to eq(I18n.t("activerecord.errors.models.doorkeeper/application.attributes.redirect_uri.unspecified_scheme"))
|
62
|
+
end
|
63
|
+
|
64
|
+
it "is invalid if an ip address" do
|
65
|
+
client.redirect_uri = "127.0.0.1:8080"
|
66
|
+
expect(client).to be_invalid
|
67
|
+
end
|
68
|
+
|
69
|
+
it "accepts an ip address based URI if a scheme is specified" do
|
70
|
+
client.redirect_uri = "https://127.0.0.1:8080"
|
71
|
+
expect(client).to be_valid
|
72
|
+
end
|
73
|
+
|
74
|
+
context "when force secured uri configured" do
|
75
|
+
it "accepts a valid uri" do
|
76
|
+
client.redirect_uri = "https://example.com/callback"
|
77
|
+
expect(client).to be_valid
|
78
|
+
end
|
79
|
+
|
80
|
+
it "accepts custom scheme redirect uri (as per rfc8252 section 7.1)" do
|
81
|
+
client.redirect_uri = "com.example.app:/oauth/callback"
|
82
|
+
expect(client).to be_valid
|
83
|
+
end
|
84
|
+
|
85
|
+
it "accepts custom scheme redirect uri (as per rfc8252 section 7.1) #2" do
|
86
|
+
client.redirect_uri = "com.example.app:/test"
|
87
|
+
expect(client).to be_valid
|
88
|
+
end
|
89
|
+
|
90
|
+
it "accepts custom scheme redirect uri (common misconfiguration we have decided to allow)" do
|
91
|
+
client.redirect_uri = "com.example.app://oauth/callback"
|
92
|
+
expect(client).to be_valid
|
93
|
+
end
|
94
|
+
|
95
|
+
it "accepts custom scheme redirect uri (common misconfiguration we have decided to allow) #2" do
|
96
|
+
client.redirect_uri = "com.example.app://test"
|
97
|
+
expect(client).to be_valid
|
98
|
+
end
|
99
|
+
|
100
|
+
it "accepts a non secured protocol when disabled" do
|
101
|
+
client.redirect_uri = "http://example.com/callback"
|
102
|
+
allow(Doorkeeper.configuration).to receive(
|
103
|
+
:force_ssl_in_redirect_uri,
|
104
|
+
).and_return(false)
|
105
|
+
expect(client).to be_valid
|
106
|
+
end
|
107
|
+
|
108
|
+
it "accepts a non secured protocol when conditional option defined" do
|
109
|
+
Doorkeeper.configure do
|
110
|
+
orm DOORKEEPER_ORM
|
111
|
+
force_ssl_in_redirect_uri { |uri| uri.host != "localhost" }
|
112
|
+
end
|
113
|
+
|
114
|
+
application = FactoryBot.build(:application, redirect_uri: "http://localhost/callback")
|
115
|
+
expect(application).to be_valid
|
116
|
+
|
117
|
+
application = FactoryBot.build(:application, redirect_uri: "https://test.com/callback")
|
118
|
+
expect(application).to be_valid
|
119
|
+
|
120
|
+
application = FactoryBot.build(:application, redirect_uri: "http://localhost2/callback")
|
121
|
+
expect(application).not_to be_valid
|
122
|
+
|
123
|
+
application = FactoryBot.build(:application, redirect_uri: "https://test.com/callback")
|
124
|
+
expect(application).to be_valid
|
125
|
+
end
|
126
|
+
|
127
|
+
it "forbids redirect uri if required" do
|
128
|
+
client.redirect_uri = "javascript://document.cookie"
|
129
|
+
|
130
|
+
Doorkeeper.configure do
|
131
|
+
orm DOORKEEPER_ORM
|
132
|
+
forbid_redirect_uri { |uri| uri.scheme == "javascript" }
|
133
|
+
end
|
134
|
+
|
135
|
+
expect(client).to be_invalid
|
136
|
+
expect(client.errors[:redirect_uri].first).to eq("is forbidden by the server.")
|
137
|
+
|
138
|
+
client.redirect_uri = "https://localhost/callback"
|
139
|
+
expect(client).to be_valid
|
140
|
+
end
|
141
|
+
|
142
|
+
it "invalidates the uri when the uri does not use a secure protocol" do
|
143
|
+
client.redirect_uri = "http://example.com/callback"
|
144
|
+
expect(client).not_to be_valid
|
145
|
+
error = client.errors[:redirect_uri].first
|
146
|
+
expect(error).to eq(I18n.t("activerecord.errors.models.doorkeeper/application.attributes.redirect_uri.secured_uri"))
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "with multiple redirect uri" do
|
151
|
+
it "invalidates the second uri when the first uri is native uri" do
|
152
|
+
client.redirect_uri = "urn:ietf:wg:oauth:2.0:oob\nexample.com/callback"
|
153
|
+
expect(client).to be_invalid
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "with blank redirect URI" do
|
158
|
+
it "forbids blank redirect uri by default" do
|
159
|
+
client.redirect_uri = ""
|
160
|
+
|
161
|
+
expect(client).to be_invalid
|
162
|
+
expect(client.errors[:redirect_uri]).not_to be_blank
|
163
|
+
end
|
164
|
+
|
165
|
+
it "forbids blank redirect uri by custom condition" do
|
166
|
+
Doorkeeper.configure do
|
167
|
+
orm DOORKEEPER_ORM
|
168
|
+
allow_blank_redirect_uri do |_grant_flows, application|
|
169
|
+
application.name == "admin app"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
client.name = "test app"
|
174
|
+
client.redirect_uri = ""
|
175
|
+
|
176
|
+
expect(client).to be_invalid
|
177
|
+
expect(client.errors[:redirect_uri]).not_to be_blank
|
178
|
+
|
179
|
+
client.name = "admin app"
|
180
|
+
expect(client).to be_valid
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
describe Doorkeeper::Server do
|
6
|
-
let(:fake_class) { double :fake_class }
|
7
|
-
|
5
|
+
RSpec.describe Doorkeeper::Server do
|
8
6
|
subject do
|
9
|
-
described_class.new
|
7
|
+
described_class.new(context)
|
10
8
|
end
|
11
9
|
|
10
|
+
let(:fake_class) { double :fake_class }
|
11
|
+
let(:context) { double :context }
|
12
|
+
|
12
13
|
describe ".authorization_request" do
|
13
14
|
it "raises error when strategy does not match phase" do
|
14
15
|
expect do
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
describe Doorkeeper::StaleRecordsCleaner do
|
5
|
+
RSpec.describe Doorkeeper::StaleRecordsCleaner do
|
6
6
|
let(:cleaner) { described_class.new(model) }
|
7
7
|
let(:models_by_name) do
|
8
8
|
{
|
@@ -14,7 +14,7 @@ describe Doorkeeper::StaleRecordsCleaner do
|
|
14
14
|
|
15
15
|
context "when ORM has no cleaner class" do
|
16
16
|
it "raises an error" do
|
17
|
-
|
17
|
+
allow(Doorkeeper.configuration).to receive(:orm).and_return("hibernate")
|
18
18
|
|
19
19
|
expect do
|
20
20
|
described_class.for(Doorkeeper::AccessToken)
|
@@ -38,7 +38,7 @@ describe Doorkeeper::StaleRecordsCleaner do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "removes the record" do
|
41
|
-
expect { subject }.to change
|
41
|
+
expect { subject }.to change(model, :count).to(0)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -50,7 +50,7 @@ describe Doorkeeper::StaleRecordsCleaner do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it "keeps the record" do
|
53
|
-
expect { subject }.not_to(change
|
53
|
+
expect { subject }.not_to(change(model, :count))
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -62,13 +62,14 @@ describe Doorkeeper::StaleRecordsCleaner do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
it "keeps the record" do
|
65
|
-
expect { subject }.not_to(change
|
65
|
+
expect { subject }.not_to(change(model, :count))
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
70
|
describe "#clean_expired" do
|
71
71
|
subject { cleaner.clean_expired(ttl) }
|
72
|
+
|
72
73
|
let(:ttl) { 500 }
|
73
74
|
let(:expiry_border) { ttl.seconds.ago }
|
74
75
|
|
@@ -81,7 +82,7 @@ describe Doorkeeper::StaleRecordsCleaner do
|
|
81
82
|
end
|
82
83
|
|
83
84
|
it "removes the record" do
|
84
|
-
expect { subject }.to change
|
85
|
+
expect { subject }.to change(model, :count).to(0)
|
85
86
|
end
|
86
87
|
end
|
87
88
|
|
@@ -93,7 +94,7 @@ describe Doorkeeper::StaleRecordsCleaner do
|
|
93
94
|
end
|
94
95
|
|
95
96
|
it "keeps the record" do
|
96
|
-
expect { subject }.not_to(change
|
97
|
+
expect { subject }.not_to(change(model, :count))
|
97
98
|
end
|
98
99
|
end
|
99
100
|
end
|
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
describe Doorkeeper::VERSION do
|
6
|
-
|
5
|
+
RSpec.describe Doorkeeper::VERSION do
|
6
|
+
describe "#gem_version" do
|
7
7
|
it "returns Gem::Version instance" do
|
8
8
|
expect(Doorkeeper.gem_version).to be_an_instance_of(Gem::Version)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
describe "VERSION" do
|
13
13
|
it "returns gem version string" do
|
14
14
|
expect(Doorkeeper::VERSION::STRING).to match(/^\d+\.\d+\.\d+(\.\w+)?$/)
|
15
15
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|