mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #21379 -- Created auth-specific username validators
Thanks Tim Graham for the review.
This commit is contained in:
parent
2265ff3710
commit
526575c641
11 changed files with 168 additions and 33 deletions
|
@ -1,7 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
|
||||
from django.contrib.auth import validators
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.password_validation import (
|
||||
CommonPasswordValidator, MinimumLengthValidator, NumericPasswordValidator,
|
||||
|
@ -174,3 +176,29 @@ class NumericPasswordValidatorTest(TestCase):
|
|||
NumericPasswordValidator().get_help_text(),
|
||||
"Your password can't be entirely numeric."
|
||||
)
|
||||
|
||||
|
||||
class UsernameValidatorsTests(TestCase):
|
||||
def test_unicode_validator(self):
|
||||
valid_usernames = ['joe', 'René', 'ᴮᴵᴳᴮᴵᴿᴰ', 'أحمد']
|
||||
invalid_usernames = [
|
||||
"o'connell", "عبد ال",
|
||||
"zerowidth\u200Bspace", "nonbreaking\u00A0space",
|
||||
"en\u2013dash",
|
||||
]
|
||||
v = validators.UnicodeUsernameValidator()
|
||||
for valid in valid_usernames:
|
||||
v(valid)
|
||||
for invalid in invalid_usernames:
|
||||
with self.assertRaises(ValidationError):
|
||||
v(invalid)
|
||||
|
||||
def test_ascii_validator(self):
|
||||
valid_usernames = ['glenn', 'GLEnN', 'jean-marc']
|
||||
invalid_usernames = ["o'connell", 'Éric', 'jean marc', "أحمد"]
|
||||
v = validators.ASCIIUsernameValidator()
|
||||
for valid in valid_usernames:
|
||||
v(valid)
|
||||
for invalid in invalid_usernames:
|
||||
with self.assertRaises(ValidationError):
|
||||
v(invalid)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue