mirror of
https://github.com/django/django.git
synced 2025-09-26 20:19:16 +00:00
Refs #21379 -- Normalized unicode username inputs
This commit is contained in:
parent
526575c641
commit
9935f97cd2
6 changed files with 56 additions and 2 deletions
|
@ -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': {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue