devise_jwt_auth 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/devise_jwt_auth/concerns/resource_finder.rb +1 -1
- data/app/controllers/devise_jwt_auth/omniauth_callbacks_controller.rb +7 -14
- data/app/models/devise_jwt_auth/concerns/confirmable_support.rb +2 -12
- data/app/models/devise_jwt_auth/concerns/user.rb +0 -2
- data/app/validators/devise_jwt_auth_email_validator.rb +12 -3
- data/lib/devise_jwt_auth/blacklist.rb +1 -1
- data/lib/devise_jwt_auth/version.rb +1 -1
- data/lib/generators/devise_jwt_auth/USAGE +1 -1
- data/lib/generators/devise_jwt_auth/install_generator_helpers.rb +1 -1
- data/test/controllers/custom/custom_omniauth_callbacks_controller_test.rb +1 -1
- data/test/controllers/custom/custom_passwords_controller_test.rb +2 -2
- data/test/controllers/demo_group_controller_test.rb +0 -24
- data/test/controllers/demo_mang_controller_test.rb +0 -216
- data/test/controllers/demo_user_controller_test.rb +1 -411
- data/test/controllers/devise_jwt_auth/omniauth_callbacks_controller_test.rb +3 -3
- data/test/controllers/devise_jwt_auth/passwords_controller_test.rb +5 -5
- data/test/controllers/devise_jwt_auth/registrations_controller_test.rb +0 -12
- data/test/controllers/overrides/passwords_controller_test.rb +0 -5
- data/test/dummy/config/environments/development.rb +2 -2
- data/test/dummy/config/initializers/devise_jwt_auth.rb +1 -0
- data/test/dummy/config/routes.rb +2 -0
- data/test/dummy/config.ru +1 -1
- data/test/dummy/tmp/generators/app/models/user.rb +8 -9
- data/test/dummy/tmp/generators/db/migrate/{20201208044024_devise_jwt_auth_create_users.rb → 20220123023137_devise_jwt_auth_create_users.rb} +1 -1
- data/test/lib/devise_jwt_auth/blacklist_test.rb +2 -2
- data/test/lib/devise_jwt_auth/token_factory_test.rb +1 -1
- data/test/models/user_test.rb +0 -36
- metadata +6 -24
- data/test/dummy/tmp/generators/app/models/mang.rb +0 -9
- data/test/dummy/tmp/generators/config/routes.rb +0 -9
- data/test/dummy/tmp/generators/db/migrate/20201208044024_devise_jwt_auth_create_mangs.rb +0 -54
@@ -15,25 +15,13 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
15
15
|
before do
|
16
16
|
@resource = create(:user, :confirmed)
|
17
17
|
@auth_headers = @resource.create_named_token_pair
|
18
|
-
|
19
|
-
# @token = @auth_headers['access-token']
|
20
|
-
# @client_id = @auth_headers['client']
|
21
|
-
# @expiry = @auth_headers['expiry']
|
22
18
|
end
|
23
19
|
|
24
20
|
describe 'successful request' do
|
25
21
|
before do
|
26
|
-
# ensure that request is not treated as batch request
|
27
|
-
# age_token(@resource, @client_id)
|
28
|
-
|
29
22
|
get '/demo/members_only',
|
30
23
|
params: {},
|
31
24
|
headers: @auth_headers
|
32
|
-
|
33
|
-
# @resp_token = response.headers['access-token']
|
34
|
-
# @resp_client_id = response.headers['client']
|
35
|
-
# @resp_expiry = response.headers['expiry']
|
36
|
-
# @resp_uid = response.headers['uid']
|
37
25
|
end
|
38
26
|
|
39
27
|
describe 'devise mappings' do
|
@@ -57,42 +45,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
57
45
|
it 'should return success status' do
|
58
46
|
assert_equal 200, response.status
|
59
47
|
end
|
60
|
-
|
61
|
-
# it 'should receive new token after successful request' do
|
62
|
-
# refute_equal @token, @resp_token
|
63
|
-
# end
|
64
|
-
#
|
65
|
-
# it 'should preserve the client id from the first request' do
|
66
|
-
# assert_equal @client_id, @resp_client_id
|
67
|
-
# end
|
68
|
-
#
|
69
|
-
# it "should return the user's uid in the auth header" do
|
70
|
-
# assert_equal @resource.uid, @resp_uid
|
71
|
-
# end
|
72
|
-
#
|
73
|
-
# it 'should not treat this request as a batch request' do
|
74
|
-
# refute assigns(:is_batch_request)
|
75
|
-
# end
|
76
|
-
#
|
77
|
-
# describe 'subsequent requests' do
|
78
|
-
# before do
|
79
|
-
# @resource.reload
|
80
|
-
# # ensure that request is not treated as batch request
|
81
|
-
# # age_token(@resource, @client_id)
|
82
|
-
#
|
83
|
-
# get '/demo/members_only',
|
84
|
-
# params: {},
|
85
|
-
# headers: @auth_headers.merge('access-token' => @resp_token)
|
86
|
-
# end
|
87
|
-
#
|
88
|
-
# it 'should not treat this request as a batch request' do
|
89
|
-
# refute assigns(:is_batch_request)
|
90
|
-
# end
|
91
|
-
#
|
92
|
-
# it 'should allow a new request to be made using new token' do
|
93
|
-
# assert_equal 200, response.status
|
94
|
-
# end
|
95
|
-
# end
|
96
48
|
end
|
97
49
|
|
98
50
|
describe 'failed request' do
|
@@ -110,214 +62,13 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
110
62
|
assert_equal 401, response.status
|
111
63
|
end
|
112
64
|
end
|
113
|
-
# describe 'disable change_headers_on_each_request' do
|
114
|
-
# before do
|
115
|
-
# DeviseJwtAuth.change_headers_on_each_request = false
|
116
|
-
# @resource.reload
|
117
|
-
# # age_token(@resource, @client_id)
|
118
|
-
#
|
119
|
-
# get '/demo/members_only',
|
120
|
-
# params: {},
|
121
|
-
# headers: @auth_headers
|
122
|
-
#
|
123
|
-
# @first_is_batch_request = assigns(:is_batch_request)
|
124
|
-
# @first_user = assigns(:resource).dup
|
125
|
-
# @first_access_token = response.headers['access-token']
|
126
|
-
# @first_response_status = response.status
|
127
|
-
#
|
128
|
-
# @resource.reload
|
129
|
-
# # age_token(@resource, @client_id)
|
130
|
-
#
|
131
|
-
# # use expired auth header
|
132
|
-
# get '/demo/members_only',
|
133
|
-
# params: {},
|
134
|
-
# headers: @auth_headers
|
135
|
-
#
|
136
|
-
# @second_is_batch_request = assigns(:is_batch_request)
|
137
|
-
# @second_user = assigns(:resource).dup
|
138
|
-
# @second_access_token = response.headers['access-token']
|
139
|
-
# @second_response_status = response.status
|
140
|
-
# end
|
141
|
-
#
|
142
|
-
# after do
|
143
|
-
# DeviseJwtAuth.change_headers_on_each_request = true
|
144
|
-
# end
|
145
|
-
#
|
146
|
-
# it 'should allow the first request through' do
|
147
|
-
# assert_equal 200, @first_response_status
|
148
|
-
# end
|
149
|
-
#
|
150
|
-
# it 'should allow the second request through' do
|
151
|
-
# assert_equal 200, @second_response_status
|
152
|
-
# end
|
153
|
-
#
|
154
|
-
# it 'should return auth headers from the first request' do
|
155
|
-
# assert @first_access_token
|
156
|
-
# end
|
157
|
-
#
|
158
|
-
# it 'should not treat either requests as batch requests' do
|
159
|
-
# refute @first_is_batch_request
|
160
|
-
# refute @second_is_batch_request
|
161
|
-
# end
|
162
|
-
#
|
163
|
-
# it 'should return auth headers from the second request' do
|
164
|
-
# assert @second_access_token
|
165
|
-
# end
|
166
|
-
#
|
167
|
-
# it 'should define user during first request' do
|
168
|
-
# assert @first_user
|
169
|
-
# end
|
170
|
-
#
|
171
|
-
# it 'should define user during second request' do
|
172
|
-
# assert @second_user
|
173
|
-
# end
|
174
|
-
# end
|
175
|
-
#
|
176
|
-
# describe 'batch requests' do
|
177
|
-
# describe 'success' do
|
178
|
-
# before do
|
179
|
-
# # age_token(@resource, @client_id)
|
180
|
-
#
|
181
|
-
# get '/demo/members_only',
|
182
|
-
# params: {},
|
183
|
-
# headers: @auth_headers
|
184
|
-
#
|
185
|
-
# @first_is_batch_request = assigns(:is_batch_request)
|
186
|
-
# @first_user = assigns(:resource)
|
187
|
-
# @first_access_token = response.headers['access-token']
|
188
|
-
#
|
189
|
-
# get '/demo/members_only',
|
190
|
-
# params: {},
|
191
|
-
# headers: @auth_headers
|
192
|
-
#
|
193
|
-
# @second_is_batch_request = assigns(:is_batch_request)
|
194
|
-
# @second_user = assigns(:resource)
|
195
|
-
# @second_access_token = response.headers['access-token']
|
196
|
-
# end
|
197
|
-
#
|
198
|
-
# it 'should allow both requests through' do
|
199
|
-
# assert_equal 200, response.status
|
200
|
-
# end
|
201
|
-
#
|
202
|
-
# it 'should not treat the first request as a batch request' do
|
203
|
-
# refute @first_is_batch_request
|
204
|
-
# end
|
205
|
-
#
|
206
|
-
# it 'should treat the second request as a batch request' do
|
207
|
-
# assert @second_is_batch_request
|
208
|
-
# end
|
209
|
-
#
|
210
|
-
# it 'should return access token for first (non-batch) request' do
|
211
|
-
# assert @first_access_token
|
212
|
-
# end
|
213
|
-
#
|
214
|
-
# it 'should not return auth headers for second (batched) requests' do
|
215
|
-
# assert_equal ' ', @second_access_token
|
216
|
-
# end
|
217
|
-
# end
|
218
|
-
#
|
219
|
-
# describe 'unbatch' do
|
220
|
-
# before do
|
221
|
-
# @resource.reload
|
222
|
-
# # age_token(@resource, @client_id)
|
223
|
-
#
|
224
|
-
# get '/demo/members_only',
|
225
|
-
# params: {},
|
226
|
-
# headers: @auth_headers
|
227
|
-
#
|
228
|
-
# @first_is_batch_request = assigns(:is_batch_request)
|
229
|
-
# @first_user = assigns(:resource).dup
|
230
|
-
# @first_access_token = response.headers['access-token']
|
231
|
-
# @first_response_status = response.status
|
232
|
-
#
|
233
|
-
# get '/demo/members_only?unbatch=true',
|
234
|
-
# params: {},
|
235
|
-
# headers: @auth_headers
|
236
|
-
#
|
237
|
-
# @second_is_batch_request = assigns(:is_batch_request)
|
238
|
-
# @second_user = assigns(:resource)
|
239
|
-
# @second_access_token = response.headers['access-token']
|
240
|
-
# @second_response_status = response.status
|
241
|
-
# end
|
242
|
-
#
|
243
|
-
# it 'should NOT treat the second request as a batch request when "unbatch" param is set' do
|
244
|
-
# refute @second_is_batch_request
|
245
|
-
# end
|
246
|
-
# end
|
247
|
-
#
|
248
|
-
# describe 'time out' do
|
249
|
-
# before do
|
250
|
-
# @resource.reload
|
251
|
-
# # age_token(@resource, @client_id)
|
252
|
-
#
|
253
|
-
# get '/demo/members_only',
|
254
|
-
# params: {},
|
255
|
-
# headers: @auth_headers
|
256
|
-
#
|
257
|
-
# @first_is_batch_request = assigns(:is_batch_request)
|
258
|
-
# @first_user = assigns(:resource).dup
|
259
|
-
# @first_access_token = response.headers['access-token']
|
260
|
-
# @first_response_status = response.status
|
261
|
-
#
|
262
|
-
# @resource.reload
|
263
|
-
# # age_token(@resource, @client_id)
|
264
|
-
#
|
265
|
-
# # use expired auth header
|
266
|
-
# get '/demo/members_only',
|
267
|
-
# params: {},
|
268
|
-
# headers: @auth_headers
|
269
|
-
#
|
270
|
-
# @second_is_batch_request = assigns(:is_batch_request)
|
271
|
-
# @second_user = assigns(:resource)
|
272
|
-
# @second_access_token = response.headers['access-token']
|
273
|
-
# @second_response_status = response.status
|
274
|
-
# end
|
275
|
-
#
|
276
|
-
# it 'should allow the first request through' do
|
277
|
-
# assert_equal 200, @first_response_status
|
278
|
-
# end
|
279
|
-
#
|
280
|
-
# it 'should not allow the second request through' do
|
281
|
-
# assert_equal 401, @second_response_status
|
282
|
-
# end
|
283
|
-
#
|
284
|
-
# it 'should not treat first request as batch request' do
|
285
|
-
# refute @second_is_batch_request
|
286
|
-
# end
|
287
|
-
#
|
288
|
-
# it 'should return auth headers from the first request' do
|
289
|
-
# assert @first_access_token
|
290
|
-
# end
|
291
|
-
#
|
292
|
-
# it 'should not treat second request as batch request' do
|
293
|
-
# refute @second_is_batch_request
|
294
|
-
# end
|
295
|
-
#
|
296
|
-
# it 'should not return auth headers from the second request' do
|
297
|
-
# refute @second_access_token
|
298
|
-
# end
|
299
|
-
#
|
300
|
-
# it 'should define user during first request' do
|
301
|
-
# assert @first_user
|
302
|
-
# end
|
303
|
-
#
|
304
|
-
# it 'should not define user during second request' do
|
305
|
-
# refute @second_user
|
306
|
-
# end
|
307
|
-
# end
|
308
|
-
# end
|
309
65
|
|
310
66
|
describe 'successful password change' do
|
311
67
|
before do
|
312
|
-
# DeviseJwtAuth.remove_tokens_after_password_reset = true
|
313
|
-
|
314
68
|
# adding one more token to simulate another logged in device
|
315
69
|
@old_auth_headers = @auth_headers
|
316
70
|
@auth_headers = @resource.create_named_token_pair
|
317
71
|
|
318
|
-
# age_token(@resource, @client_id)
|
319
|
-
# assert @resource.tokens.count > 1
|
320
|
-
|
321
72
|
# password changed from new device
|
322
73
|
@resource.update(password: 'newsecret123',
|
323
74
|
password_confirmation: 'newsecret123')
|
@@ -327,14 +78,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
327
78
|
headers: @auth_headers
|
328
79
|
end
|
329
80
|
|
330
|
-
after do
|
331
|
-
# DeviseJwtAuth.remove_tokens_after_password_reset = false
|
332
|
-
end
|
333
|
-
|
334
|
-
# it 'should have only one token' do
|
335
|
-
# assert_equal 1, @resource.tokens.count
|
336
|
-
# end
|
337
|
-
|
338
81
|
it 'new request should be successful' do
|
339
82
|
assert 200, response.status
|
340
83
|
end
|
@@ -349,132 +92,34 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
349
92
|
end
|
350
93
|
end
|
351
94
|
|
352
|
-
# describe 'request including destroy of token' do
|
353
|
-
# describe 'when change_headers_on_each_request is set to false' do
|
354
|
-
# before do
|
355
|
-
# DeviseJwtAuth.change_headers_on_each_request = false
|
356
|
-
# # age_token(@resource, @client_id)
|
357
|
-
#
|
358
|
-
# get '/demo/members_only_remove_token',
|
359
|
-
# params: {},
|
360
|
-
# headers: @auth_headers
|
361
|
-
# end
|
362
|
-
#
|
363
|
-
# after do
|
364
|
-
# DeviseJwtAuth.change_headers_on_each_request = true
|
365
|
-
# end
|
366
|
-
#
|
367
|
-
# it 'should not return auth-headers' do
|
368
|
-
# refute response.headers['access-token']
|
369
|
-
# end
|
370
|
-
# end
|
371
|
-
#
|
372
|
-
# describe 'when change_headers_on_each_request is set to true' do
|
373
|
-
# before do
|
374
|
-
# # age_token(@resource, @client_id)
|
375
|
-
# get '/demo/members_only_remove_token',
|
376
|
-
# params: {},
|
377
|
-
# headers: @auth_headers
|
378
|
-
# end
|
379
|
-
#
|
380
|
-
# it 'should not return auth-headers' do
|
381
|
-
# refute response.headers['access-token']
|
382
|
-
# end
|
383
|
-
# end
|
384
|
-
# end
|
385
|
-
|
386
95
|
describe 'when access-token name has been changed' do
|
387
96
|
before do
|
388
|
-
# ensure that request is not treated as batch request
|
389
|
-
# DeviseJwtAuth.headers_names[:'access-token'] = 'new-access-token'
|
390
97
|
DeviseJwtAuth.access_token_name = 'new-access-token'
|
391
98
|
|
392
99
|
auth_headers_modified = @resource.create_named_token_pair
|
393
100
|
|
394
|
-
# client_id = auth_headers_modified['client']
|
395
|
-
# age_token(@resource, client_id)
|
396
|
-
|
397
101
|
get '/demo/members_only',
|
398
102
|
params: {},
|
399
103
|
headers: auth_headers_modified
|
400
104
|
|
401
|
-
# @resp_token = response.headers['new-access-token']
|
402
105
|
# TODO: do we want to send access-tokens with every response?
|
403
106
|
@data = JSON.parse(response.body)
|
404
107
|
end
|
405
|
-
|
406
|
-
# # assert @resp_token.present?
|
407
|
-
# # assert @data['new-access-token']
|
408
|
-
# end
|
108
|
+
|
409
109
|
after do
|
410
|
-
# DeviseJwtAuth.headers_names[:'access-token'] = 'access-token'
|
411
110
|
DeviseJwtAuth.access_token_name = 'access-token'
|
412
111
|
end
|
413
112
|
end
|
414
|
-
|
415
|
-
# describe 'maximum concurrent devices per user' do
|
416
|
-
# before do
|
417
|
-
# # Set the max_number_of_devices to a lower number
|
418
|
-
# # to expedite tests! (Default is 10)
|
419
|
-
# DeviseJwtAuth.max_number_of_devices = 5
|
420
|
-
# end
|
421
|
-
#
|
422
|
-
# it 'should limit the maximum number of concurrent devices' do
|
423
|
-
# # increment the number of devices until the maximum is exceeded
|
424
|
-
# 1.upto(DeviseJwtAuth.max_number_of_devices + 1).each do |n|
|
425
|
-
#
|
426
|
-
# assert_equal(
|
427
|
-
# [n, DeviseJwtAuth.max_number_of_devices].min,
|
428
|
-
# @resource.reload.tokens.length
|
429
|
-
# )
|
430
|
-
#
|
431
|
-
# # Add a new device (and token) ahead of the next iteration
|
432
|
-
# # @resource.create_new_auth_token
|
433
|
-
# create_token_header(@resource)
|
434
|
-
# end
|
435
|
-
# end
|
436
|
-
#
|
437
|
-
# it 'should drop the oldest token when the maximum number of devices is exceeded' do
|
438
|
-
# # create the maximum number of tokens
|
439
|
-
# 1.upto(DeviseJwtAuth.max_number_of_devices).each do
|
440
|
-
# # @resource.create_new_auth_token
|
441
|
-
# create_token_header(@resource)
|
442
|
-
# end
|
443
|
-
#
|
444
|
-
# # get the oldest token client_id
|
445
|
-
# oldest_client_id, = @resource.reload.tokens.min_by do |cid, v|
|
446
|
-
# v[:expiry] || v['expiry']
|
447
|
-
# end # => [ 'CLIENT_ID', {token: ...} ]
|
448
|
-
#
|
449
|
-
# # create another token, thereby dropping the oldest token
|
450
|
-
# # @resource.create_new_auth_token
|
451
|
-
# create_token_header(@resource)
|
452
|
-
#
|
453
|
-
# assert_not_includes @resource.reload.tokens.keys, oldest_client_id
|
454
|
-
# end
|
455
|
-
#
|
456
|
-
# after do
|
457
|
-
# DeviseJwtAuth.max_number_of_devices = 10
|
458
|
-
# end
|
459
|
-
# end
|
460
113
|
end
|
461
114
|
|
462
115
|
describe 'bypass_sign_in' do
|
463
116
|
before do
|
464
117
|
@resource = create(:user)
|
465
118
|
@auth_headers = @resource.create_named_token_pair
|
466
|
-
|
467
|
-
# @token = @auth_headers['access-token']
|
468
|
-
# @client_id = @auth_headers['client']
|
469
|
-
# @expiry = @auth_headers['expiry']
|
470
119
|
end
|
471
120
|
describe 'is default value (true)' do
|
472
121
|
before do
|
473
|
-
# age_token(@resource, @client_id)
|
474
|
-
|
475
122
|
get '/demo/members_only', params: {}, headers: @auth_headers
|
476
|
-
|
477
|
-
# @access_token = response.headers['access-token']
|
478
123
|
@response_status = response.status
|
479
124
|
end
|
480
125
|
|
@@ -482,10 +127,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
482
127
|
assert_equal 200, @response_status
|
483
128
|
end
|
484
129
|
|
485
|
-
# it 'should return auth headers' do
|
486
|
-
# assert @access_token
|
487
|
-
# end
|
488
|
-
|
489
130
|
it 'should set current user' do
|
490
131
|
assert_equal @controller.current_user, @resource
|
491
132
|
end
|
@@ -493,7 +134,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
493
134
|
describe 'is false' do
|
494
135
|
before do
|
495
136
|
DeviseJwtAuth.bypass_sign_in = false
|
496
|
-
# age_token(@resource, @client_id)
|
497
137
|
|
498
138
|
get '/demo/members_only', params: {}, headers: @auth_headers
|
499
139
|
|
@@ -530,11 +170,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
530
170
|
get '/demo/members_only',
|
531
171
|
params: {},
|
532
172
|
headers: nil
|
533
|
-
|
534
|
-
# @resp_token = response.headers['access-token']
|
535
|
-
# @resp_client_id = response.headers['client']
|
536
|
-
# @resp_expiry = response.headers['expiry']
|
537
|
-
# @resp_uid = response.headers['uid']
|
538
173
|
end
|
539
174
|
|
540
175
|
describe 'devise mappings' do
|
@@ -554,22 +189,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
554
189
|
it 'should return success status' do
|
555
190
|
assert_equal 200, response.status
|
556
191
|
end
|
557
|
-
|
558
|
-
# it 'should receive new token after successful request' do
|
559
|
-
# assert @resp_token
|
560
|
-
# end
|
561
|
-
#
|
562
|
-
# it 'should set the token expiry in the auth header' do
|
563
|
-
# assert @resp_expiry
|
564
|
-
# end
|
565
|
-
#
|
566
|
-
# it 'should return the client id in the auth header' do
|
567
|
-
# assert @resp_client_id
|
568
|
-
# end
|
569
|
-
#
|
570
|
-
# it "should return the user's uid in the auth header" do
|
571
|
-
# assert @resp_uid
|
572
|
-
# end
|
573
192
|
end
|
574
193
|
|
575
194
|
describe 'existing Warden authentication with ignored token data' do
|
@@ -580,11 +199,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
580
199
|
get '/demo/members_only',
|
581
200
|
params: {},
|
582
201
|
headers: @auth_headers
|
583
|
-
|
584
|
-
# @resp_token = response.headers['access-token']
|
585
|
-
# @resp_client_id = response.headers['client']
|
586
|
-
# @resp_expiry = response.headers['expiry']
|
587
|
-
# @resp_uid = response.headers['uid']
|
588
202
|
end
|
589
203
|
|
590
204
|
describe 'devise mappings' do
|
@@ -604,30 +218,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
604
218
|
it 'should return success status' do
|
605
219
|
assert_equal 200, response.status
|
606
220
|
end
|
607
|
-
|
608
|
-
# it 'should receive new token after successful request' do
|
609
|
-
# assert @resp_token
|
610
|
-
# end
|
611
|
-
#
|
612
|
-
# it 'should set the token expiry in the auth header' do
|
613
|
-
# assert @resp_expiry
|
614
|
-
# end
|
615
|
-
#
|
616
|
-
# it 'should return the client id in the auth header' do
|
617
|
-
# assert @resp_client_id
|
618
|
-
# end
|
619
|
-
#
|
620
|
-
# it "should not use the existing token's client" do
|
621
|
-
# refute_equal @auth_headers['client'], @resp_client_id
|
622
|
-
# end
|
623
|
-
#
|
624
|
-
# it "should return the user's uid in the auth header" do
|
625
|
-
# assert @resp_uid
|
626
|
-
# end
|
627
|
-
#
|
628
|
-
# it "should not return the token user's uid in the auth header" do
|
629
|
-
# refute_equal @resp_uid, @auth_headers['uid']
|
630
|
-
# end
|
631
221
|
end
|
632
222
|
end
|
633
223
|
end
|
@@ -14,7 +14,7 @@ class OmniauthTest < ActionDispatch::IntegrationTest
|
|
14
14
|
end
|
15
15
|
|
16
16
|
before do
|
17
|
-
@redirect_url = 'http://ng-
|
17
|
+
@redirect_url = 'http://ng-jwt-auth.dev/'
|
18
18
|
end
|
19
19
|
|
20
20
|
def get_parsed_data_json
|
@@ -58,8 +58,8 @@ class OmniauthTest < ActionDispatch::IntegrationTest
|
|
58
58
|
|
59
59
|
test 'session vars have been cleared' do
|
60
60
|
get_success
|
61
|
-
refute request.session['
|
62
|
-
refute request.session['
|
61
|
+
refute request.session['dja.omniauth.auth']
|
62
|
+
refute request.session['dja.omniauth.params']
|
63
63
|
end
|
64
64
|
|
65
65
|
test 'sign_in was called' do
|
@@ -13,7 +13,7 @@ class DeviseJwtAuth::PasswordsControllerTest < ActionController::TestCase
|
|
13
13
|
describe 'Password reset' do
|
14
14
|
before do
|
15
15
|
@resource = create(:user, :confirmed)
|
16
|
-
@redirect_url = 'http://ng-
|
16
|
+
@redirect_url = 'http://ng-jwt-auth.dev'
|
17
17
|
end
|
18
18
|
|
19
19
|
describe 'not email should return 401' do
|
@@ -340,7 +340,7 @@ class DeviseJwtAuth::PasswordsControllerTest < ActionController::TestCase
|
|
340
340
|
describe 'Using default_password_reset_url' do
|
341
341
|
before do
|
342
342
|
@resource = create(:user, :confirmed)
|
343
|
-
@redirect_url = 'http://ng-
|
343
|
+
@redirect_url = 'http://ng-jwt-auth.dev'
|
344
344
|
|
345
345
|
DeviseJwtAuth.default_password_reset_url = @redirect_url
|
346
346
|
|
@@ -798,7 +798,7 @@ class DeviseJwtAuth::PasswordsControllerTest < ActionController::TestCase
|
|
798
798
|
|
799
799
|
before do
|
800
800
|
@resource = create(:mang_user, :confirmed)
|
801
|
-
@redirect_url = 'http://ng-
|
801
|
+
@redirect_url = 'http://ng-jwt-auth.dev'
|
802
802
|
get_reset_token
|
803
803
|
end
|
804
804
|
|
@@ -816,7 +816,7 @@ class DeviseJwtAuth::PasswordsControllerTest < ActionController::TestCase
|
|
816
816
|
describe 'unconfirmed user' do
|
817
817
|
before do
|
818
818
|
@resource = create(:user)
|
819
|
-
@redirect_url = 'http://ng-
|
819
|
+
@redirect_url = 'http://ng-jwt-auth.dev'
|
820
820
|
|
821
821
|
get_reset_token
|
822
822
|
|
@@ -850,7 +850,7 @@ class DeviseJwtAuth::PasswordsControllerTest < ActionController::TestCase
|
|
850
850
|
describe 'alternate user type' do
|
851
851
|
before do
|
852
852
|
@resource = create(:user, :confirmed)
|
853
|
-
@redirect_url = 'http://ng-
|
853
|
+
@redirect_url = 'http://ng-jwt-auth.dev'
|
854
854
|
# @config_name = 'altUser'
|
855
855
|
|
856
856
|
params = { email: @resource.email,
|
@@ -879,18 +879,6 @@ class DeviseJwtAuth::RegistrationsControllerTest < ActionDispatch::IntegrationTe
|
|
879
879
|
test 'user was confirmed' do
|
880
880
|
assert @resource.confirmed?
|
881
881
|
end
|
882
|
-
|
883
|
-
# test 'auth headers were returned in response' do
|
884
|
-
# assert response.headers['access-token']
|
885
|
-
# assert response.headers['token-type']
|
886
|
-
# assert response.headers['client']
|
887
|
-
# assert response.headers['expiry']
|
888
|
-
# assert response.headers['uid']
|
889
|
-
# end
|
890
|
-
#
|
891
|
-
# test 'response token is valid' do
|
892
|
-
# assert @resource.valid_token?(@token, @client_id)
|
893
|
-
# end
|
894
882
|
end
|
895
883
|
|
896
884
|
describe 'User with only :database_authenticatable and :registerable included' do
|
@@ -46,13 +46,8 @@ class Overrides::PasswordsControllerTest < ActionDispatch::IntegrationTest
|
|
46
46
|
test 'response should contain auth params + override proof' do
|
47
47
|
# TODO: remove access-token and keep uid?
|
48
48
|
assert @query_string['access-token']
|
49
|
-
# assert @query_string['client']
|
50
|
-
# assert @query_string['client_id']
|
51
|
-
# assert @query_string['expiry']
|
52
49
|
assert @query_string['override_proof']
|
53
50
|
assert @query_string['reset_password']
|
54
|
-
# assert @query_string['token']
|
55
|
-
# assert @query_string['uid']
|
56
51
|
end
|
57
52
|
|
58
53
|
test 'override proof is correct' do
|
@@ -19,7 +19,7 @@ Rails.application.configure do
|
|
19
19
|
config.action_mailer.raise_delivery_errors = true
|
20
20
|
|
21
21
|
# use mailcatcher for development
|
22
|
-
config.action_mailer.default_url_options = { host: 'devise-
|
22
|
+
config.action_mailer.default_url_options = { host: 'devise-jwt-auth.dev' }
|
23
23
|
config.action_mailer.delivery_method = :smtp
|
24
24
|
config.action_mailer.smtp_settings = { address: 'localhost', port: 1025 }
|
25
25
|
|
@@ -42,5 +42,5 @@ Rails.application.configure do
|
|
42
42
|
# Raises error for missing translations
|
43
43
|
# config.action_view.raise_on_missing_translations = true
|
44
44
|
|
45
|
-
OmniAuth.config.full_host = 'http://devise-
|
45
|
+
OmniAuth.config.full_host = 'http://devise-jwt-auth.dev'
|
46
46
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
DeviseJwtAuth.setup do |config|
|
4
|
+
# TODO: Remove old config settings from DTA.
|
4
5
|
# By default the authorization headers will change after each request. The
|
5
6
|
# client is responsible for keeping track of the changing tokens. Change
|
6
7
|
# this to false to prevent the Authorization header from changing after
|
data/test/dummy/config/routes.rb
CHANGED
data/test/dummy/config.ru
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
1
|
+
class User < ActiveRecord::Base
|
2
|
+
# Include default devise modules.
|
3
|
+
devise :database_authenticatable, :registerable,
|
4
|
+
:recoverable, :rememberable, :trackable, :validatable,
|
5
|
+
:confirmable, :omniauthable
|
6
|
+
include DeviseJwtAuth::Concerns::User
|
7
|
+
def whatever; puts 'whatever'; end
|
8
|
+
end
|