1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Refs #29628, Refs #33178 -- Made createsuperuser validate password against required fields passed in options.

This commit is contained in:
Mariusz Felisiak
2021-10-12 06:21:14 +02:00
committed by GitHub
parent 5b0f1f95d0
commit da266b3c5c
2 changed files with 43 additions and 3 deletions

View File

@@ -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()