Regenerate username if it's empty after slugification
This commit is contained in:
Родитель
4de033a176
Коммит
cf60837045
|
@ -31,6 +31,10 @@ class TestAutoCreateUsername(amo.tests.TestCase):
|
|||
eq_(autocreate_username('testaccount+slug'),
|
||||
'testaccountslug')
|
||||
|
||||
def test_empty_username_is_a_random_hash(self):
|
||||
un = autocreate_username('.+') # this shouldn't happen but it could!
|
||||
assert len(un) and not un.startswith('.+'), 'Unexpected: %s' % un
|
||||
|
||||
def test_blacklisted(self):
|
||||
BlacklistedUsername.objects.create(username='firefox')
|
||||
un = autocreate_username('firefox')
|
||||
|
|
|
@ -113,9 +113,9 @@ def autocreate_username(candidate, tries=1):
|
|||
adjusted_u = make_u(candidate)
|
||||
if tries > 1:
|
||||
adjusted_u = '%s%s' % (adjusted_u, tries)
|
||||
if (BlacklistedUsername.blocked(adjusted_u)
|
||||
if (BlacklistedUsername.blocked(adjusted_u) or adjusted_u == ''
|
||||
or tries > max_tries or len(adjusted_u) > 255):
|
||||
log.info('username blocked, max tries reached, or too long;'
|
||||
log.info('username blocked, empty, max tries reached, or too long;'
|
||||
' username=%s; max=%s' % (adjusted_u, max_tries))
|
||||
return autocreate_username(uuid.uuid4().hex[0:15])
|
||||
if UserProfile.objects.filter(username=adjusted_u).count():
|
||||
|
|
Загрузка…
Ссылка в новой задаче