@@ -310,23 +310,47 @@ def @controller.reset_session
310
310
end
311
311
312
312
describe 'Unconfirmed user' do
313
- before do
314
- @unconfirmed_user = create ( :user )
315
- post :create , params : { email : @unconfirmed_user . email ,
316
- password : @unconfirmed_user . password }
317
- @resource = assigns ( :resource )
318
- @data = JSON . parse ( response . body )
319
- end
313
+ describe 'Without paranoid mode' do
314
+ before do
315
+ @unconfirmed_user = create ( :user )
316
+ post :create , params : { email : @unconfirmed_user . email ,
317
+ password : @unconfirmed_user . password }
318
+ @resource = assigns ( :resource )
319
+ @data = JSON . parse ( response . body )
320
+ end
320
321
321
- test 'request should fail' do
322
- assert_equal 401 , response . status
322
+ test 'request should fail' do
323
+ assert_equal 401 , response . status
324
+ end
325
+
326
+ test 'response should contain errors' do
327
+ assert @data [ 'errors' ]
328
+ assert_equal @data [ 'errors' ] ,
329
+ [ I18n . t ( 'devise_token_auth.sessions.not_confirmed' ,
330
+ email : @unconfirmed_user . email ) ]
331
+ end
323
332
end
333
+
334
+ describe 'With paranoid mode' do
335
+ before do
336
+ @unconfirmed_user = create ( :user )
337
+ swap Devise , paranoid : true do
338
+ post :create , params : { email : @unconfirmed_user . email ,
339
+ password : @unconfirmed_user . password }
340
+ end
341
+ @resource = assigns ( :resource )
342
+ @data = JSON . parse ( response . body )
343
+ end
324
344
325
- test 'response should contain errors' do
326
- assert @data [ 'errors' ]
327
- assert_equal @data [ 'errors' ] ,
328
- [ I18n . t ( 'devise_token_auth.sessions.not_confirmed' ,
329
- email : @unconfirmed_user . email ) ]
345
+ test 'request should fail' do
346
+ assert_equal 401 , response . status
347
+ end
348
+
349
+ test 'response should contain errors that do not leak the existence of the account' do
350
+ assert @data [ 'errors' ]
351
+ assert_equal @data [ 'errors' ] ,
352
+ [ I18n . t ( 'devise_token_auth.sessions.bad_credentials' ) ]
353
+ end
330
354
end
331
355
end
332
356
@@ -375,20 +399,42 @@ def @controller.reset_session
375
399
end
376
400
377
401
describe 'Non-existing user' do
378
- before do
379
- post :create ,
380
- params : { email : -> { Faker ::Internet . email } ,
381
- password : -> { Faker ::Number . number ( 10 ) } }
382
- @resource = assigns ( :resource )
383
- @data = JSON . parse ( response . body )
384
- end
402
+ describe 'Without paranoid mode' do
403
+ before do
404
+ post :create ,
405
+ params : { email : -> { Faker ::Internet . email } ,
406
+ password : -> { Faker ::Number . number ( 10 ) } }
407
+ @resource = assigns ( :resource )
408
+ @data = JSON . parse ( response . body )
409
+ end
385
410
386
- test 'request should fail' do
387
- assert_equal 401 , response . status
411
+ test 'request should fail' do
412
+ assert_equal 401 , response . status
413
+ end
414
+
415
+ test 'response should contain errors' do
416
+ assert @data [ 'errors' ]
417
+ end
388
418
end
389
419
390
- test 'response should contain errors' do
391
- assert @data [ 'errors' ]
420
+ describe 'With paranoid mode' do
421
+ before do
422
+ mock_hash = '$2a$04$MUWADkfA6MHXDdWHoep6QOvX1o0Y56pNqt3NMWQ9zCRwKSp1HZJba'
423
+ @bcrypt_mock = MiniTest ::Mock . new
424
+ @bcrypt_mock . expect ( :call , mock_hash , [ Object , String ] )
425
+
426
+ swap Devise , paranoid : true do
427
+ BCrypt ::Engine . stub :hash_secret , @bcrypt_mock do
428
+ post :create ,
429
+ params : { email : -> { Faker ::Internet . email } ,
430
+ password : -> { Faker ::Number . number ( 10 ) } }
431
+ end
432
+ end
433
+ end
434
+
435
+ test 'password should be hashed' do
436
+ @bcrypt_mock . verify
437
+ end
392
438
end
393
439
end
394
440
@@ -472,21 +518,44 @@ def @controller.reset_session
472
518
end
473
519
474
520
describe 'locked user' do
475
- before do
476
- @locked_user = create ( :lockable_user , :locked )
477
- post :create ,
478
- params : { email : @locked_user . email ,
479
- password : @locked_user . password }
480
- @data = JSON . parse ( response . body )
481
- end
521
+ describe 'Without paranoid mode' do
522
+ before do
523
+ @locked_user = create ( :lockable_user , :locked )
524
+ post :create ,
525
+ params : { email : @locked_user . email ,
526
+ password : @locked_user . password }
527
+ @data = JSON . parse ( response . body )
528
+ end
482
529
483
- test 'request should fail' do
484
- assert_equal 401 , response . status
530
+ test 'request should fail' do
531
+ assert_equal 401 , response . status
532
+ end
533
+
534
+ test 'response should contain errors' do
535
+ assert @data [ 'errors' ]
536
+ assert_equal @data [ 'errors' ] , [ I18n . t ( 'devise.mailer.unlock_instructions.account_lock_msg' ) ]
537
+ end
485
538
end
486
539
487
- test 'response should contain errors' do
488
- assert @data [ 'errors' ]
489
- assert_equal @data [ 'errors' ] , [ I18n . t ( 'devise.mailer.unlock_instructions.account_lock_msg' ) ]
540
+ describe 'With paranoid mode' do
541
+ before do
542
+ @locked_user = create ( :lockable_user , :locked )
543
+ swap Devise , paranoid : true do
544
+ post :create ,
545
+ params : { email : @locked_user . email ,
546
+ password : @locked_user . password }
547
+ end
548
+ @data = JSON . parse ( response . body )
549
+ end
550
+
551
+ test 'request should fail' do
552
+ assert_equal 401 , response . status
553
+ end
554
+
555
+ test 'response should contain errors that do not leak the existence of the account' do
556
+ assert @data [ 'errors' ]
557
+ assert_equal @data [ 'errors' ] , [ I18n . t ( 'devise_token_auth.sessions.bad_credentials' ) ]
558
+ end
490
559
end
491
560
end
492
561
0 commit comments