diff --git a/seahub/api2/endpoints/admin/groups.py b/seahub/api2/endpoints/admin/groups.py index 13bd23f1b8..33f8f47a37 100644 --- a/seahub/api2/endpoints/admin/groups.py +++ b/seahub/api2/endpoints/admin/groups.py @@ -117,7 +117,7 @@ class AdminGroups(APIView): group_name = group_name.strip() # Check whether group name is validate. if not validate_group_name(group_name): - error_msg = _(u'Group name can only contain letters, numbers, blank, hyphen, single quote or underscore') + error_msg = _(u'Group name can only contain letters, numbers, blank, hyphen, period, single quote or underscore') return api_error(status.HTTP_400_BAD_REQUEST, error_msg) # Check whether group name is duplicated. diff --git a/seahub/api2/endpoints/groups.py b/seahub/api2/endpoints/groups.py index deb38d602e..aac79864d8 100644 --- a/seahub/api2/endpoints/groups.py +++ b/seahub/api2/endpoints/groups.py @@ -202,7 +202,7 @@ class Groups(APIView): # Check whether group name is validate. if not validate_group_name(group_name): - error_msg = _(u'Group name can only contain letters, numbers, blank, hyphen, single quote or underscore') + error_msg = _(u'Group name can only contain letters, numbers, blank, hyphen, period, single quote or underscore') return api_error(status.HTTP_400_BAD_REQUEST, error_msg) # Check whether group name is duplicated. diff --git a/seahub/group/utils.py b/seahub/group/utils.py index 035ecec47d..696b2a449f 100644 --- a/seahub/group/utils.py +++ b/seahub/group/utils.py @@ -30,7 +30,7 @@ def validate_group_name(group_name): """ if len(group_name) > 255: return False - return re.match('^[\w\s\'-]+$', group_name, re.U) + return re.match('^[\w\s\'-.]+$', group_name, re.U) def check_group_name_conflict(request, new_group_name): """Check if new group name conflict with existed group. diff --git a/tests/api/endpoints/admin/test_groups.py b/tests/api/endpoints/admin/test_groups.py index 4b2052ca4d..3f823f0722 100644 --- a/tests/api/endpoints/admin/test_groups.py +++ b/tests/api/endpoints/admin/test_groups.py @@ -62,8 +62,8 @@ class GroupsTest(BaseTestCase): self.login_as(self.admin) url = reverse('api-v2.1-admin-groups') - limit_punctuation = """-'_""" - group_name = randstring(5) + random.choice(limit_punctuation) + limit_punctuation = """-'_.""" + group_name = randstring(2) + random.choice(limit_punctuation) + randstring(2) data = { 'group_name': group_name, @@ -83,8 +83,8 @@ class GroupsTest(BaseTestCase): self.login_as(self.admin) url = reverse('api-v2.1-admin-groups') - other_punctuation = """!"#$%&()*+,./:;<=>?@[\]^`{|}~""" - group_name = randstring(5) + random.choice(other_punctuation) + other_punctuation = """!"#$%&()*+,/:;<=>?@[\]^`{|}~""" + group_name = randstring(2) + random.choice(other_punctuation) + randstring(2) data = { 'group_name': group_name, diff --git a/tests/api/endpoints/test_groups.py b/tests/api/endpoints/test_groups.py index 92b8f1b24f..ae803e634c 100644 --- a/tests/api/endpoints/test_groups.py +++ b/tests/api/endpoints/test_groups.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import json from mock import patch +import random from django.core.urlresolvers import reverse from seaserv import seafile_api @@ -90,6 +91,26 @@ class GroupsTest(BaseTestCase): resp = self.client.post(self.url, {'group_name': self.group_name}) self.assertEqual(400, resp.status_code) + def test_can_create_by_limit_punctuation(self): + limit_punctuation = """-'_.""" + new_group_name = randstring(2) + random.choice(limit_punctuation) + randstring(2) + + resp = self.client.post(self.url, {'name': new_group_name}) + self.assertEqual(201, resp.status_code) + + json_resp = json.loads(resp.content) + assert json_resp['name'] == new_group_name + assert json_resp['owner'] == self.user.email + + self.remove_group(json_resp['id']) + + def test_can_not_create_by_other_punctuation(self): + other_punctuation = """!"#$%&()*+,/:;<=>?@[\]^`{|}~""" + new_group_name = randstring(2) + random.choice(other_punctuation) + randstring(2) + + resp = self.client.post(self.url, {'name': new_group_name}) + self.assertEqual(400, resp.status_code) + def test_can_not_create_group_with_invalid_name(self): new_group_name = 'new%group-' + randstring(6)