summaryrefslogtreecommitdiff
path: root/tests/auth_tests
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-07-06 14:14:59 -0400
committerTim Graham <timograham@gmail.com>2015-07-20 13:44:34 -0400
commit774c16d16ed67d7cf12bc2b2752768b544bdb363 (patch)
tree1c72e971f62511dd5acda191f47d1bea45ba0b1c /tests/auth_tests
parentf5e9d67907510881c7f132d0a80e39f47caea5f6 (diff)
downloaddjango-774c16d16ed67d7cf12bc2b2752768b544bdb363.tar.gz
Fixed #25052; refs #16860 -- Added password validation to UserCreationForm.
Diffstat (limited to 'tests/auth_tests')
-rw-r--r--tests/auth_tests/test_forms.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py
index ab1cff3ea3..aa0a6af41a 100644
--- a/tests/auth_tests/test_forms.py
+++ b/tests/auth_tests/test_forms.py
@@ -132,6 +132,27 @@ class UserCreationFormTest(TestDataMixin, TestCase):
self.assertEqual(password_changed.call_count, 1)
self.assertEqual(repr(u), '<User: jsmith@example.com>')
+ @override_settings(AUTH_PASSWORD_VALIDATORS=[
+ {'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'},
+ {'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 'OPTIONS': {
+ 'min_length': 12,
+ }},
+ ])
+ def test_validates_password(self):
+ data = {
+ 'username': 'testclient',
+ 'password1': 'testclient',
+ 'password2': 'testclient',
+ }
+ form = UserCreationForm(data)
+ self.assertFalse(form.is_valid())
+ self.assertEqual(len(form['password2'].errors), 2)
+ self.assertIn('The password is too similar to the username.', form['password2'].errors)
+ self.assertIn(
+ 'This password is too short. It must contain at least 12 characters.',
+ form['password2'].errors
+ )
+
@override_settings(USE_TZ=False, PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'])
class AuthenticationFormTest(TestDataMixin, TestCase):