@@ -287,6 +287,7 @@ public function testEncoders()
287
287
'memory_cost ' => null ,
288
288
'time_cost ' => null ,
289
289
'threads ' => null ,
290
+ 'migrate_from ' => [],
290
291
],
291
292
'JMS\FooBundle\Entity\User3 ' => [
292
293
'algorithm ' => 'md5 ' ,
@@ -299,6 +300,7 @@ public function testEncoders()
299
300
'memory_cost ' => null ,
300
301
'time_cost ' => null ,
301
302
'threads ' => null ,
303
+ 'migrate_from ' => [],
302
304
],
303
305
'JMS\FooBundle\Entity\User4 ' => new Reference ('security.encoder.foo ' ),
304
306
'JMS\FooBundle\Entity\User5 ' => [
@@ -320,6 +322,7 @@ public function testEncoders()
320
322
'memory_cost ' => null ,
321
323
'time_cost ' => null ,
322
324
'threads ' => null ,
325
+ 'migrate_from ' => [],
323
326
],
324
327
]], $ container ->getDefinition ('security.encoder_factory.generic ' )->getArguments ());
325
328
}
@@ -348,6 +351,7 @@ public function testEncodersWithLibsodium()
348
351
'memory_cost ' => null ,
349
352
'time_cost ' => null ,
350
353
'threads ' => null ,
354
+ 'migrate_from ' => [],
351
355
],
352
356
'JMS\FooBundle\Entity\User3 ' => [
353
357
'algorithm ' => 'md5 ' ,
@@ -360,6 +364,7 @@ public function testEncodersWithLibsodium()
360
364
'memory_cost ' => null ,
361
365
'time_cost ' => null ,
362
366
'threads ' => null ,
367
+ 'migrate_from ' => [],
363
368
],
364
369
'JMS\FooBundle\Entity\User4 ' => new Reference ('security.encoder.foo ' ),
365
370
'JMS\FooBundle\Entity\User5 ' => [
@@ -401,6 +406,7 @@ public function testEncodersWithArgon2i()
401
406
'memory_cost ' => null ,
402
407
'time_cost ' => null ,
403
408
'threads ' => null ,
409
+ 'migrate_from ' => [],
404
410
],
405
411
'JMS\FooBundle\Entity\User3 ' => [
406
412
'algorithm ' => 'md5 ' ,
@@ -413,6 +419,7 @@ public function testEncodersWithArgon2i()
413
419
'memory_cost ' => null ,
414
420
'time_cost ' => null ,
415
421
'threads ' => null ,
422
+ 'migrate_from ' => [],
416
423
],
417
424
'JMS\FooBundle\Entity\User4 ' => new Reference ('security.encoder.foo ' ),
418
425
'JMS\FooBundle\Entity\User5 ' => [
@@ -430,9 +437,74 @@ public function testEncodersWithArgon2i()
430
437
]], $ container ->getDefinition ('security.encoder_factory.generic ' )->getArguments ());
431
438
}
432
439
440
+ public function testMigratingEncoder ()
441
+ {
442
+ if (!($ sodium = SodiumPasswordEncoder::isSupported () && !\defined ('SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13 ' )) && !\defined ('PASSWORD_ARGON2I ' )) {
443
+ $ this ->markTestSkipped ('Argon2i algorithm is not supported. ' );
444
+ }
445
+
446
+ $ container = $ this ->getContainer ('migrating_encoder ' );
447
+
448
+ $ this ->assertEquals ([[
449
+ 'JMS\FooBundle\Entity\User1 ' => [
450
+ 'class ' => 'Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder ' ,
451
+ 'arguments ' => [false ],
452
+ ],
453
+ 'JMS\FooBundle\Entity\User2 ' => [
454
+ 'algorithm ' => 'sha1 ' ,
455
+ 'encode_as_base64 ' => false ,
456
+ 'iterations ' => 5 ,
457
+ 'hash_algorithm ' => 'sha512 ' ,
458
+ 'key_length ' => 40 ,
459
+ 'ignore_case ' => false ,
460
+ 'cost ' => null ,
461
+ 'memory_cost ' => null ,
462
+ 'time_cost ' => null ,
463
+ 'threads ' => null ,
464
+ 'migrate_from ' => [],
465
+ ],
466
+ 'JMS\FooBundle\Entity\User3 ' => [
467
+ 'algorithm ' => 'md5 ' ,
468
+ 'hash_algorithm ' => 'sha512 ' ,
469
+ 'key_length ' => 40 ,
470
+ 'ignore_case ' => false ,
471
+ 'encode_as_base64 ' => true ,
472
+ 'iterations ' => 5000 ,
473
+ 'cost ' => null ,
474
+ 'memory_cost ' => null ,
475
+ 'time_cost ' => null ,
476
+ 'threads ' => null ,
477
+ 'migrate_from ' => [],
478
+ ],
479
+ 'JMS\FooBundle\Entity\User4 ' => new Reference ('security.encoder.foo ' ),
480
+ 'JMS\FooBundle\Entity\User5 ' => [
481
+ 'class ' => 'Symfony\Component\Security\Core\Encoder\Pbkdf2PasswordEncoder ' ,
482
+ 'arguments ' => ['sha1 ' , false , 5 , 30 ],
483
+ ],
484
+ 'JMS\FooBundle\Entity\User6 ' => [
485
+ 'class ' => 'Symfony\Component\Security\Core\Encoder\NativePasswordEncoder ' ,
486
+ 'arguments ' => [8 , 102400 , 15 ],
487
+ ],
488
+ 'JMS\FooBundle\Entity\User7 ' => [
489
+ 'algorithm ' => 'argon2i ' ,
490
+ 'hash_algorithm ' => 'sha512 ' ,
491
+ 'key_length ' => 40 ,
492
+ 'ignore_case ' => false ,
493
+ 'encode_as_base64 ' => true ,
494
+ 'iterations ' => 5000 ,
495
+ 'cost ' => null ,
496
+ 'memory_cost ' => 256 ,
497
+ 'time_cost ' => 1 ,
498
+ 'threads ' => null ,
499
+ 'migrate_from ' => ['bcrypt ' ],
500
+ ],
501
+ ]], $ container ->getDefinition ('security.encoder_factory.generic ' )->getArguments ());
502
+ }
503
+
433
504
public function testEncodersWithBCrypt ()
434
505
{
435
506
$ container = $ this ->getContainer ('bcrypt_encoder ' );
507
+
436
508
$ this ->assertEquals ([[
437
509
'JMS\FooBundle\Entity\User1 ' => [
438
510
'class ' => 'Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder ' ,
@@ -449,6 +521,7 @@ public function testEncodersWithBCrypt()
449
521
'memory_cost ' => null ,
450
522
'time_cost ' => null ,
451
523
'threads ' => null ,
524
+ 'migrate_from ' => [],
452
525
],
453
526
'JMS\FooBundle\Entity\User3 ' => [
454
527
'algorithm ' => 'md5 ' ,
@@ -461,6 +534,7 @@ public function testEncodersWithBCrypt()
461
534
'memory_cost ' => null ,
462
535
'time_cost ' => null ,
463
536
'threads ' => null ,
537
+ 'migrate_from ' => [],
464
538
],
465
539
'JMS\FooBundle\Entity\User4 ' => new Reference ('security.encoder.foo ' ),
466
540
'JMS\FooBundle\Entity\User5 ' => [
0 commit comments