@@ -560,7 +560,7 @@ def testPasswordMigration(self):
560560 # assume that the "best" algorithm is the first one and doesn't
561561 # need migration, all others should be migrated.
562562 cl .db .config .WEB_LOGIN_ATTEMPTS_MIN = 200
563-
563+ cl . db . config . PASSWORD_PBKDF2_DEFAULT_ROUNDS = 10000
564564 # The third item always fails. Regardless of what is there.
565565 # ['plaintext', 'SHA', 'crypt', 'MD5']:
566566 print (password .Password .deprecated_schemes )
@@ -571,23 +571,38 @@ def testPasswordMigration(self):
571571 continue # crypt is not available on Windows
572572 pw1 = password .Password ('foo' , scheme = scheme )
573573 print (pw1 )
574- self .assertEqual (pw1 .needs_migration (), True )
574+ self .assertEqual (pw1 .needs_migration (config = cl . db . config ), True )
575575 self .db .user .set (chef , password = pw1 )
576576 self .db .commit ()
577577 actions .LoginAction (cl ).handle ()
578578 pw = cl .db .user .get (chef , 'password' )
579579 print (pw )
580580 self .assertEqual (pw , 'foo' )
581- self .assertEqual (pw .needs_migration (), False )
581+ self .assertEqual (pw .needs_migration (config = cl . db . config ), False )
582582 cl .db .Otk = self .db .Otk
583583 pw1 = pw
584- self .assertEqual (pw1 .needs_migration (), False )
584+ self .assertEqual (pw1 .needs_migration (config = cl . db . config ), False )
585585 scheme = password .Password .known_schemes [0 ]
586586 self .assertEqual (scheme , pw1 .scheme )
587587 actions .LoginAction (cl ).handle ()
588588 pw = cl .db .user .get (chef , 'password' )
589589 self .assertEqual (pw , 'foo' )
590590 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+
591606 cl .db .close ()
592607
593608 def testPasswordConfigOption (self ):
@@ -596,7 +611,7 @@ def testPasswordConfigOption(self):
596611 cl = self ._make_client (form )
597612 self .db .config .PASSWORD_PBKDF2_DEFAULT_ROUNDS = 1000
598613 pw1 = password .Password ('foo' , scheme = 'MD5' )
599- self .assertEqual (pw1 .needs_migration (), True )
614+ self .assertEqual (pw1 .needs_migration (config = cl . db . config ), True )
600615 self .db .user .set (chef , password = pw1 )
601616 self .db .commit ()
602617 actions .LoginAction (cl ).handle ()
0 commit comments