@@ -565,6 +565,38 @@ def test_check_password_calls_harden_runtime(self):
565565 check_password ("wrong_password" , encoded )
566566 self .assertEqual (hasher .harden_runtime .call_count , 1 )
567567
568+ def test_check_password_calls_make_password_to_fake_runtime (self ):
569+ hasher = get_hasher ("default" )
570+ cases = [
571+ (None , None , None ), # no plain text password provided
572+ ("foo" , make_password (password = None ), None ), # unusable encoded
573+ ("letmein" , make_password (password = "letmein" ), ValueError ), # valid encoded
574+ ]
575+ for password , encoded , hasher_side_effect in cases :
576+ with (
577+ self .subTest (encoded = encoded ),
578+ mock .patch (
579+ "django.contrib.auth.hashers.identify_hasher" ,
580+ side_effect = hasher_side_effect ,
581+ ) as mock_identify_hasher ,
582+ mock .patch (
583+ "django.contrib.auth.hashers.make_password"
584+ ) as mock_make_password ,
585+ mock .patch (
586+ "django.contrib.auth.hashers.get_random_string" ,
587+ side_effect = lambda size : "x" * size ,
588+ ),
589+ mock .patch .object (hasher , "verify" ),
590+ ):
591+ # Ensure make_password is called to standardize timing.
592+ check_password (password , encoded )
593+ self .assertEqual (hasher .verify .call_count , 0 )
594+ self .assertEqual (mock_identify_hasher .mock_calls , [mock .call (encoded )])
595+ self .assertEqual (
596+ mock_make_password .mock_calls ,
597+ [mock .call ("x" * UNUSABLE_PASSWORD_SUFFIX_LENGTH )],
598+ )
599+
568600 def test_encode_invalid_salt (self ):
569601 hasher_classes = [
570602 MD5PasswordHasher ,
0 commit comments