diff options
| author | Jacob Walls <38668450+jacobtylerwalls@users.noreply.github.com> | 2016-05-15 18:54:03 -0700 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-10-21 09:29:53 +0200 |
| commit | 0362b0e986303858081f607ffad2e8e14be8775e (patch) | |
| tree | 44fce88bd49ea4ad97cfe69af41897260eb89924 /tests/auth_tests/test_tokens.py | |
| parent | 7f9e4524d6b23424cf44fbe1bf1f4e70f6bb066e (diff) | |
Fixed #26615 -- Made password reset token invalidate when changing email.
Co-Authored-By: Silas Barta <sbarta@gmail.com>
Diffstat (limited to 'tests/auth_tests/test_tokens.py')
| -rw-r--r-- | tests/auth_tests/test_tokens.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auth_tests/test_tokens.py b/tests/auth_tests/test_tokens.py index bba435be84..42ac71148e 100644 --- a/tests/auth_tests/test_tokens.py +++ b/tests/auth_tests/test_tokens.py @@ -7,6 +7,8 @@ from django.test import TestCase from django.test.utils import ignore_warnings from django.utils.deprecation import RemovedInDjango40Warning +from .models import CustomEmailField + class MockedPasswordResetTokenGenerator(PasswordResetTokenGenerator): def __init__(self, now): @@ -37,6 +39,27 @@ class TokenGeneratorTest(TestCase): tk2 = p0.make_token(user_reload) self.assertEqual(tk1, tk2) + def test_token_with_different_email(self): + """Updating the user email address invalidates the token.""" + tests = [ + (CustomEmailField, None), + (CustomEmailField, 'test4@example.com'), + (User, 'test4@example.com'), + ] + for model, email in tests: + with self.subTest(model=model.__qualname__, email=email): + user = model.objects.create_user( + 'changeemailuser', + email=email, + password='testpw', + ) + p0 = PasswordResetTokenGenerator() + tk1 = p0.make_token(user) + self.assertIs(p0.check_token(user, tk1), True) + setattr(user, user.get_email_field_name(), 'test4new@example.com') + user.save() + self.assertIs(p0.check_token(user, tk1), False) + def test_timeout(self): """The token is valid after n seconds, but no greater.""" # Uses a mocked version of PasswordResetTokenGenerator so we can change |
