diff options
| author | Vincenzo Pandolfo <pandolfovince@gmail.com> | 2016-03-14 20:21:05 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-03-14 20:20:24 -0400 |
| commit | d0fe6c915665fa3220e84bd691ba7002a357e5c5 (patch) | |
| tree | 6b295468e71e1ef7a887af7875c67d60b316edca /tests/auth_tests/test_forms.py | |
| parent | b4347d82b767c5a6c288ae010669dea92336fadd (diff) | |
Fixed #26334 -- Removed whitespace stripping from contrib.auth password fields.
Diffstat (limited to 'tests/auth_tests/test_forms.py')
| -rw-r--r-- | tests/auth_tests/test_forms.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py index c0afe2912d..6172c44783 100644 --- a/tests/auth_tests/test_forms.py +++ b/tests/auth_tests/test_forms.py @@ -139,6 +139,17 @@ class UserCreationFormTest(TestDataMixin, TestCase): form = CustomUserCreationForm(data) self.assertTrue(form.is_valid()) + def test_password_whitespace_not_stripped(self): + data = { + 'username': 'testuser', + 'password1': ' testpassword ', + 'password2': ' testpassword ', + } + form = UserCreationForm(data) + self.assertTrue(form.is_valid()) + self.assertEqual(form.cleaned_data['password1'], data['password1']) + self.assertEqual(form.cleaned_data['password2'], data['password2']) + class AuthenticationFormTest(TestDataMixin, TestCase): @@ -248,6 +259,15 @@ class AuthenticationFormTest(TestDataMixin, TestCase): form = CustomAuthenticationForm() self.assertEqual(form.fields['username'].label, "") + def test_password_whitespace_not_stripped(self): + data = { + 'username': 'testuser', + 'password': ' pass ', + } + form = AuthenticationForm(None, data) + form.is_valid() # Not necessary to have valid credentails for the test. + self.assertEqual(form.cleaned_data['password'], data['password']) + class SetPasswordFormTest(TestDataMixin, TestCase): @@ -298,6 +318,17 @@ class SetPasswordFormTest(TestDataMixin, TestCase): form["new_password2"].errors ) + def test_password_whitespace_not_stripped(self): + user = User.objects.get(username='testclient') + data = { + 'new_password1': ' password ', + 'new_password2': ' password ', + } + form = SetPasswordForm(user, data) + self.assertTrue(form.is_valid()) + self.assertEqual(form.cleaned_data['new_password1'], data['new_password1']) + self.assertEqual(form.cleaned_data['new_password2'], data['new_password2']) + class PasswordChangeFormTest(TestDataMixin, TestCase): @@ -348,6 +379,20 @@ class PasswordChangeFormTest(TestDataMixin, TestCase): self.assertEqual(list(PasswordChangeForm(user, {}).fields), ['old_password', 'new_password1', 'new_password2']) + def test_password_whitespace_not_stripped(self): + user = User.objects.get(username='testclient') + user.set_password(' oldpassword ') + data = { + 'old_password': ' oldpassword ', + 'new_password1': ' pass ', + 'new_password2': ' pass ', + } + form = PasswordChangeForm(user, data) + self.assertTrue(form.is_valid()) + self.assertEqual(form.cleaned_data['old_password'], data['old_password']) + self.assertEqual(form.cleaned_data['new_password1'], data['new_password1']) + self.assertEqual(form.cleaned_data['new_password2'], data['new_password2']) + class UserChangeFormTest(TestDataMixin, TestCase): @@ -635,3 +680,14 @@ class AdminPasswordChangeFormTest(TestDataMixin, TestCase): self.assertEqual(password_changed.call_count, 0) form.save() self.assertEqual(password_changed.call_count, 1) + + def test_password_whitespace_not_stripped(self): + user = User.objects.get(username='testclient') + data = { + 'password1': ' pass ', + 'password2': ' pass ', + } + form = AdminPasswordChangeForm(user, data) + self.assertTrue(form.is_valid()) + self.assertEqual(form.cleaned_data['password1'], data['password1']) + self.assertEqual(form.cleaned_data['password2'], data['password2']) |
