diff options
| author | François Freitag <mail@franek.fr> | 2021-04-19 09:58:34 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-04-20 07:34:53 +0200 |
| commit | 6b0b3eafd6674305f7b09dbeb1aa0d8d8bb4df57 (patch) | |
| tree | 952b0327f570411069b0ab2bb8a4a1bb7704388e /tests/auth_tests | |
| parent | b13af4752fa3e5e7c08163902f32260a50f69ef7 (diff) | |
Fixed #32664 -- Made PasswordResetTokenGenerator.secret validation lazy.
Django apps initialization to run management command triggers the admin
autodiscovery. Importing django.contrib.auth.tokens creates an instance
of PasswordResetTokenGenerator which required a SECRET_KEY.
For several management commands, the token generator is unused. It
should only complain about a missing SECRET_KEY when it is used.
Diffstat (limited to 'tests/auth_tests')
| -rw-r--r-- | tests/auth_tests/test_tokens.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/auth_tests/test_tokens.py b/tests/auth_tests/test_tokens.py index af823b1114..ff26bd626b 100644 --- a/tests/auth_tests/test_tokens.py +++ b/tests/auth_tests/test_tokens.py @@ -3,7 +3,9 @@ from datetime import datetime, timedelta from django.conf import settings from django.contrib.auth.models import User from django.contrib.auth.tokens import PasswordResetTokenGenerator +from django.core.exceptions import ImproperlyConfigured from django.test import TestCase +from django.test.utils import override_settings from .models import CustomEmailField @@ -131,3 +133,10 @@ class TokenGeneratorTest(TestCase): tk_default = default_password_generator.make_token(user) self.assertIs(custom_password_generator.check_token(user, tk_default), False) self.assertIs(default_password_generator.check_token(user, tk_custom), False) + + @override_settings(SECRET_KEY='') + def test_secret_lazy_validation(self): + default_token_generator = PasswordResetTokenGenerator() + msg = 'The SECRET_KEY setting must not be empty.' + with self.assertRaisesMessage(ImproperlyConfigured, msg): + default_token_generator.secret |
