diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-10-12 06:21:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-12 06:21:14 +0200 |
commit | da266b3c5ca4bb7581d7a3cc51bc820e78cf64f0 (patch) | |
tree | 7353ca3204818793956ab436e818a32d0a58d9ac /tests/auth_tests | |
parent | 5b0f1f95d064b6fa32192a68d6c5dd14403001c4 (diff) | |
download | django-da266b3c5ca4bb7581d7a3cc51bc820e78cf64f0.tar.gz |
Refs #29628, Refs #33178 -- Made createsuperuser validate password against required fields passed in options.
Diffstat (limited to 'tests/auth_tests')
-rw-r--r-- | tests/auth_tests/test_management.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/auth_tests/test_management.py b/tests/auth_tests/test_management.py index 8a4e23952c..575975fd90 100644 --- a/tests/auth_tests/test_management.py +++ b/tests/auth_tests/test_management.py @@ -713,6 +713,46 @@ class CreatesuperuserManagementCommandTestCase(TestCase): test(self) + @override_settings( + AUTH_USER_MODEL='auth_tests.CustomUser', + AUTH_PASSWORD_VALIDATORS=[ + {'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'}, + ] + ) + def test_validate_password_against_required_fields_via_option(self): + new_io = StringIO() + first_name = 'josephine' + entered_passwords = [ + first_name, first_name, + 'superduperunguessablepassword', 'superduperunguessablepassword', + ] + + def bad_then_good_password(): + return entered_passwords.pop(0) + + @mock_inputs({ + 'password': bad_then_good_password, + 'bypass': 'n', + }) + def test(self): + call_command( + 'createsuperuser', + interactive=True, + first_name=first_name, + date_of_birth='1970-01-01', + email='joey@example.com', + stdin=MockTTY(), + stdout=new_io, + stderr=new_io, + ) + self.assertEqual( + new_io.getvalue().strip(), + 'The password is too similar to the first name.\n' + 'Superuser created successfully.' + ) + + test(self) + def test_blank_username(self): """Creation fails if --username is blank.""" new_io = StringIO() |