@@ -560,7 +560,7 @@ def testPasswordMigration(self):
560
560
# assume that the "best" algorithm is the first one and doesn't
561
561
# need migration, all others should be migrated.
562
562
cl .db .config .WEB_LOGIN_ATTEMPTS_MIN = 200
563
-
563
+ cl . db . config . PASSWORD_PBKDF2_DEFAULT_ROUNDS = 10000
564
564
# The third item always fails. Regardless of what is there.
565
565
# ['plaintext', 'SHA', 'crypt', 'MD5']:
566
566
print (password .Password .deprecated_schemes )
@@ -571,23 +571,38 @@ def testPasswordMigration(self):
571
571
continue # crypt is not available on Windows
572
572
pw1 = password .Password ('foo' , scheme = scheme )
573
573
print (pw1 )
574
- self .assertEqual (pw1 .needs_migration (), True )
574
+ self .assertEqual (pw1 .needs_migration (config = cl . db . config ), True )
575
575
self .db .user .set (chef , password = pw1 )
576
576
self .db .commit ()
577
577
actions .LoginAction (cl ).handle ()
578
578
pw = cl .db .user .get (chef , 'password' )
579
579
print (pw )
580
580
self .assertEqual (pw , 'foo' )
581
- self .assertEqual (pw .needs_migration (), False )
581
+ self .assertEqual (pw .needs_migration (config = cl . db . config ), False )
582
582
cl .db .Otk = self .db .Otk
583
583
pw1 = pw
584
- self .assertEqual (pw1 .needs_migration (), False )
584
+ self .assertEqual (pw1 .needs_migration (config = cl . db . config ), False )
585
585
scheme = password .Password .known_schemes [0 ]
586
586
self .assertEqual (scheme , pw1 .scheme )
587
587
actions .LoginAction (cl ).handle ()
588
588
pw = cl .db .user .get (chef , 'password' )
589
589
self .assertEqual (pw , 'foo' )
590
590
self .assertEqual (pw , pw1 )
591
+
592
+ # migrate if rounds has increased above rounds was 10000
593
+ # below will be 100000
594
+ cl .db .Otk = self .db .Otk
595
+ pw1 = pw
596
+ cl .db .config .PASSWORD_PBKDF2_DEFAULT_ROUNDS = 100000
597
+ self .assertEqual (pw1 .needs_migration (config = cl .db .config ), True )
598
+ scheme = password .Password .known_schemes [0 ]
599
+ self .assertEqual (scheme , pw1 .scheme )
600
+ actions .LoginAction (cl ).handle ()
601
+ pw = cl .db .user .get (chef , 'password' )
602
+ self .assertEqual (pw , 'foo' )
603
+ # do not assert self.assertEqual(pw, pw1) as pw is a 100,000
604
+ # cycle while pw1 is only 10,000. They won't compare equally.
605
+
591
606
cl .db .close ()
592
607
593
608
def testPasswordConfigOption (self ):
@@ -596,7 +611,7 @@ def testPasswordConfigOption(self):
596
611
cl = self ._make_client (form )
597
612
self .db .config .PASSWORD_PBKDF2_DEFAULT_ROUNDS = 1000
598
613
pw1 = password .Password ('foo' , scheme = 'MD5' )
599
- self .assertEqual (pw1 .needs_migration (), True )
614
+ self .assertEqual (pw1 .needs_migration (config = cl . db . config ), True )
600
615
self .db .user .set (chef , password = pw1 )
601
616
self .db .commit ()
602
617
actions .LoginAction (cl ).handle ()
0 commit comments