Commit 09f2cdbe authored by Tim Graham's avatar Tim Graham
Browse files

Refs #16860 -- Fixed a resource and deprecation warning in password validation.

parent e6dd7f99
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -161,7 +161,9 @@ class CommonPasswordValidator(object):
        try:
            common_passwords_lines = gzip.open(password_list_path).read().decode('utf-8').splitlines()
        except IOError:
            common_passwords_lines = open(password_list_path).readlines()
            with open(password_list_path) as f:
                common_passwords_lines = f.readlines()

        self.passwords = {p.strip() for p in common_passwords_lines}

    def validate(self, password, user=None):
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ class PasswordValidationTest(TestCase):
        self.assertIsNone(validate_password('sufficiently-long'))
        msg_too_short = 'This password is too short. It must contain at least 12 characters.'

        with self.assertRaises(ValidationError, args=['This password is too short.']) as cm:
        with self.assertRaises(ValidationError) as cm:
            validate_password('django4242')
        self.assertEqual(cm.exception.messages, [msg_too_short])
        self.assertEqual(cm.exception.error_list[0].code, 'password_too_short')