Be more strict when chartering a new group, only accept [a-z][a-z0-9]+
as acronym (specifically not hyphens), closes #1080. - Legacy-Id: 5965
This commit is contained in:
parent
52cefc5909
commit
214b1e0a3b
|
@ -62,8 +62,8 @@ class WGForm(forms.Form):
|
|||
if self.wg and acronym == self.wg.acronym:
|
||||
return acronym # no change, no check
|
||||
|
||||
if not re.match(r'^[-a-z0-9]+$', acronym):
|
||||
raise forms.ValidationError("Acronym is invalid, may only contain letters, numbers and dashes.")
|
||||
if not re.match(r'^[a-z][a-z0-9]+$', acronym):
|
||||
raise forms.ValidationError("Acronym is invalid, must be at least two characters and only contain lowercase letters and numbers starting with a letter.")
|
||||
|
||||
existing = Group.objects.filter(acronym__iexact=acronym)
|
||||
if existing:
|
||||
|
|
|
@ -100,12 +100,14 @@ class WgEditTestCase(django.test.TestCase):
|
|||
|
||||
num_wgs = len(Group.objects.filter(type="wg"))
|
||||
|
||||
bof_state = GroupStateName.objects.get(slug="bof")
|
||||
|
||||
# normal get
|
||||
r = self.client.get(url)
|
||||
self.assertEquals(r.status_code, 200)
|
||||
q = PyQuery(r.content)
|
||||
self.assertEquals(len(q('form input[name=acronym]')), 1)
|
||||
|
||||
|
||||
# faulty post
|
||||
r = self.client.post(url, dict(acronym="foobarbaz")) # No name
|
||||
self.assertEquals(r.status_code, 200)
|
||||
|
@ -113,9 +115,24 @@ class WgEditTestCase(django.test.TestCase):
|
|||
self.assertTrue(len(q('form ul.errorlist')) > 0)
|
||||
self.assertEquals(len(Group.objects.filter(type="wg")), num_wgs)
|
||||
|
||||
# acronym contains non-alphanumeric
|
||||
r = self.client.post(url, dict(acronym="test...", name="Testing WG", state=bof_state.pk))
|
||||
self.assertEquals(r.status_code, 200)
|
||||
|
||||
# acronym contains hyphen
|
||||
r = self.client.post(url, dict(acronym="test-wg", name="Testing WG", state=bof_state.pk))
|
||||
self.assertEquals(r.status_code, 200)
|
||||
|
||||
# acronym too short
|
||||
r = self.client.post(url, dict(acronym="t", name="Testing WG", state=bof_state.pk))
|
||||
self.assertEquals(r.status_code, 200)
|
||||
|
||||
# acronym doesn't start with an alpha character
|
||||
r = self.client.post(url, dict(acronym="1startwithalpha", name="Testing WG", state=bof_state.pk))
|
||||
self.assertEquals(r.status_code, 200)
|
||||
|
||||
# creation
|
||||
state = GroupStateName.objects.get(slug="bof")
|
||||
r = self.client.post(url, dict(acronym="testwg", name="Testing WG", state=state.pk))
|
||||
r = self.client.post(url, dict(acronym="testwg", name="Testing WG", state=bof_state.pk))
|
||||
self.assertEquals(r.status_code, 302)
|
||||
self.assertEquals(len(Group.objects.filter(type="wg")), num_wgs + 1)
|
||||
group = Group.objects.get(acronym="testwg")
|
||||
|
|
Loading…
Reference in a new issue