[py3] Fixed contrib.auth tests

This commit is contained in:
Claude Paroz 2012-08-13 12:39:47 +02:00
parent 367bfaa522
commit 34ac145796
3 changed files with 5 additions and 2 deletions

View File

@ -108,7 +108,7 @@ def get_default_username(check_db=True):
default_username = get_system_username() default_username = get_system_username()
try: try:
default_username = unicodedata.normalize('NFKD', default_username)\ default_username = unicodedata.normalize('NFKD', default_username)\
.encode('ascii', 'ignore').replace(' ', '').lower() .encode('ascii', 'ignore').decode('ascii').replace(' ', '').lower()
except UnicodeDecodeError: except UnicodeDecodeError:
return '' return ''
if not RE_VALID_USERNAME.match(default_username): if not RE_VALID_USERNAME.match(default_username):

View File

@ -1,9 +1,11 @@
import sys
from datetime import date, timedelta from datetime import date, timedelta
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.auth.tokens import PasswordResetTokenGenerator from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.test import TestCase from django.test import TestCase
from django.utils import unittest
class TokenGeneratorTest(TestCase): class TokenGeneratorTest(TestCase):
@ -51,6 +53,7 @@ class TokenGeneratorTest(TestCase):
p2 = Mocked(date.today() + timedelta(settings.PASSWORD_RESET_TIMEOUT_DAYS + 1)) p2 = Mocked(date.today() + timedelta(settings.PASSWORD_RESET_TIMEOUT_DAYS + 1))
self.assertFalse(p2.check_token(user, tk1)) self.assertFalse(p2.check_token(user, tk1))
@unittest.skipIf(sys.version_info[:2] >= (3, 0), "Unnecessary test with Python 3")
def test_date_length(self): def test_date_length(self):
""" """
Make sure we don't allow overly long dates, causing a potential DoS. Make sure we don't allow overly long dates, causing a potential DoS.

View File

@ -200,7 +200,7 @@ def password_reset_confirm(request, uidb36=None, token=None,
try: try:
uid_int = base36_to_int(uidb36) uid_int = base36_to_int(uidb36)
user = User.objects.get(id=uid_int) user = User.objects.get(id=uid_int)
except (ValueError, User.DoesNotExist): except (ValueError, OverflowError, User.DoesNotExist):
user = None user = None
if user is not None and token_generator.check_token(user, token): if user is not None and token_generator.check_token(user, token):