diff options
| author | nessita <124304+nessita@users.noreply.github.com> | 2024-01-12 17:27:55 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-12 17:27:55 -0300 |
| commit | 02eaee12095eebb3d07d02e7b0bdc3f64785d379 (patch) | |
| tree | d5a72966d429519585ef717b388e85a099c7b4d9 /tests/auth_tests | |
| parent | 6e520d953773d25a3d3484db67feed446aca0bc1 (diff) | |
Added test ensuring that validate_password is used in AdminPasswordChangeForm.
Co-authored-by: Fabian Braun <fsbraun@gmx.de>
Diffstat (limited to 'tests/auth_tests')
| -rw-r--r-- | tests/auth_tests/test_forms.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py index 81c56a428e..14d71572da 100644 --- a/tests/auth_tests/test_forms.py +++ b/tests/auth_tests/test_forms.py @@ -1324,6 +1324,42 @@ class AdminPasswordChangeFormTest(TestDataMixin, TestCase): self.assertEqual(password_changed.call_count, 1) self.assertEqual(form.changed_data, ["password"]) + @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): + user = User.objects.get(username="testclient") + data = { + "password1": "testclient", + "password2": "testclient", + } + form = AdminPasswordChangeForm(user, 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, + ) + def test_password_whitespace_not_stripped(self): user = User.objects.get(username="testclient") data = { |
