mirror of
https://github.com/zulip/zulip.git
synced 2025-11-20 22:48:16 +00:00
users: Ban names shorter than 3 characters.
The empty string is not a reasonable name.
This commit is contained in:
@@ -12,6 +12,8 @@ def check_full_name(full_name_raw):
|
|||||||
full_name = full_name_raw.strip()
|
full_name = full_name_raw.strip()
|
||||||
if len(full_name) > UserProfile.MAX_NAME_LENGTH:
|
if len(full_name) > UserProfile.MAX_NAME_LENGTH:
|
||||||
raise JsonableError(_("Name too long!"))
|
raise JsonableError(_("Name too long!"))
|
||||||
|
if len(full_name) < UserProfile.MIN_NAME_LENGTH:
|
||||||
|
raise JsonableError(_("Name too short!"))
|
||||||
if list(set(full_name).intersection(UserProfile.NAME_INVALID_CHARS)):
|
if list(set(full_name).intersection(UserProfile.NAME_INVALID_CHARS)):
|
||||||
raise JsonableError(_("Invalid characters in name!"))
|
raise JsonableError(_("Invalid characters in name!"))
|
||||||
return full_name
|
return full_name
|
||||||
|
|||||||
@@ -534,6 +534,7 @@ class UserProfile(ModelReprMixin, AbstractBaseUser, PermissionsMixin):
|
|||||||
|
|
||||||
USERNAME_FIELD = 'email'
|
USERNAME_FIELD = 'email'
|
||||||
MAX_NAME_LENGTH = 100
|
MAX_NAME_LENGTH = 100
|
||||||
|
MIN_NAME_LENGTH = 3
|
||||||
API_KEY_LENGTH = 32
|
API_KEY_LENGTH = 32
|
||||||
NAME_INVALID_CHARS = ['*', '`', '>', '"', '@']
|
NAME_INVALID_CHARS = ['*', '`', '>', '"', '@']
|
||||||
|
|
||||||
|
|||||||
@@ -62,13 +62,25 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
|
|||||||
self.login("hamlet@zulip.com")
|
self.login("hamlet@zulip.com")
|
||||||
self.assert_num_bots_equal(0)
|
self.assert_num_bots_equal(0)
|
||||||
bot_info = dict(
|
bot_info = dict(
|
||||||
full_name='',
|
full_name='My bot name',
|
||||||
short_name='',
|
short_name='@',
|
||||||
)
|
)
|
||||||
result = self.client_post("/json/bots", bot_info)
|
result = self.client_post("/json/bots", bot_info)
|
||||||
self.assert_json_error(result, 'Bad name or username')
|
self.assert_json_error(result, 'Bad name or username')
|
||||||
self.assert_num_bots_equal(0)
|
self.assert_num_bots_equal(0)
|
||||||
|
|
||||||
|
def test_add_bot_with_no_name(self):
|
||||||
|
# type: () -> None
|
||||||
|
self.login("hamlet@zulip.com")
|
||||||
|
self.assert_num_bots_equal(0)
|
||||||
|
bot_info = dict(
|
||||||
|
full_name='a',
|
||||||
|
short_name='bot',
|
||||||
|
)
|
||||||
|
result = self.client_post("/json/bots", bot_info)
|
||||||
|
self.assert_json_error(result, 'Name too short!')
|
||||||
|
self.assert_num_bots_equal(0)
|
||||||
|
|
||||||
def test_add_bot(self):
|
def test_add_bot(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.login("hamlet@zulip.com")
|
self.login("hamlet@zulip.com")
|
||||||
|
|||||||
@@ -107,6 +107,11 @@ class ChangeSettingsTest(ZulipTestCase):
|
|||||||
dict(full_name='x' * 1000))
|
dict(full_name='x' * 1000))
|
||||||
self.assert_json_error(json_result, 'Name too long!')
|
self.assert_json_error(json_result, 'Name too long!')
|
||||||
|
|
||||||
|
# Now try a too-short name
|
||||||
|
json_result = self.client_post("/json/settings/change",
|
||||||
|
dict(full_name='x'))
|
||||||
|
self.assert_json_error(json_result, 'Name too short!')
|
||||||
|
|
||||||
def test_illegal_characters_in_name_changes(self):
|
def test_illegal_characters_in_name_changes(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
email = 'hamlet@zulip.com'
|
email = 'hamlet@zulip.com'
|
||||||
|
|||||||
@@ -156,6 +156,14 @@ class PermissionTest(ZulipTestCase):
|
|||||||
result = self.client_patch('/json/users/hamlet@zulip.com', req)
|
result = self.client_patch('/json/users/hamlet@zulip.com', req)
|
||||||
self.assert_json_error(result, 'Name too long!')
|
self.assert_json_error(result, 'Name too long!')
|
||||||
|
|
||||||
|
def test_admin_cannot_set_short_full_name(self):
|
||||||
|
# type: () -> None
|
||||||
|
new_name = 'a'
|
||||||
|
self.login('iago@zulip.com')
|
||||||
|
req = dict(full_name=ujson.dumps(new_name))
|
||||||
|
result = self.client_patch('/json/users/hamlet@zulip.com', req)
|
||||||
|
self.assert_json_error(result, 'Name too short!')
|
||||||
|
|
||||||
def test_admin_cannot_set_full_name_with_invalid_characters(self):
|
def test_admin_cannot_set_full_name_with_invalid_characters(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
new_name = 'Opheli*'
|
new_name = 'Opheli*'
|
||||||
|
|||||||
Reference in New Issue
Block a user