diff options
| author | Claude Paroz <claude@2xlibre.net> | 2016-04-22 21:17:42 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2016-05-16 19:38:02 +0200 |
| commit | 9935f97cd203bdcc722bc3d4e96858e221d96ff8 (patch) | |
| tree | bdc45bf056fc8ab8ff8bfeadf403d215aee699fb /tests/auth_tests/test_forms.py | |
| parent | 526575c64150e10dd8666d1ed3f86eedd00df2ed (diff) | |
Refs #21379 -- Normalized unicode username inputs
Diffstat (limited to 'tests/auth_tests/test_forms.py')
| -rw-r--r-- | tests/auth_tests/test_forms.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py index 212dff1ab0..d2ce828eb8 100644 --- a/tests/auth_tests/test_forms.py +++ b/tests/auth_tests/test_forms.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals import datetime import re +from unittest import skipIf from django import forms from django.contrib.auth.forms import ( @@ -118,6 +119,28 @@ class UserCreationFormTest(TestDataMixin, TestCase): else: self.assertFalse(form.is_valid()) + @skipIf(six.PY2, "Python 2 doesn't support unicode usernames by default.") + def test_duplicate_normalized_unicode(self): + """ + To prevent almost identical usernames, visually identical but differing + by their unicode code points only, Unicode NFKC normalization should + make appear them equal to Django. + """ + omega_username = 'iamtheΩ' # U+03A9 GREEK CAPITAL LETTER OMEGA + ohm_username = 'iamtheΩ' # U+2126 OHM SIGN + self.assertNotEqual(omega_username, ohm_username) + User.objects.create_user(username=omega_username, password='pwd') + data = { + 'username': ohm_username, + 'password1': 'pwd2', + 'password2': 'pwd2', + } + form = UserCreationForm(data) + self.assertFalse(form.is_valid()) + self.assertEqual( + form.errors['username'], ["A user with that username already exists."] + ) + @override_settings(AUTH_PASSWORD_VALIDATORS=[ {'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'}, {'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 'OPTIONS': { |
