From 214b1e0a3bb78869a655c009858c7ae58417062b Mon Sep 17 00:00:00 2001 From: Ole Laursen Date: Wed, 7 Aug 2013 15:23:37 +0000 Subject: [PATCH] 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 --- ietf/wginfo/edit.py | 4 ++-- ietf/wginfo/tests.py | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/ietf/wginfo/edit.py b/ietf/wginfo/edit.py index 13a75d841..945129ff7 100644 --- a/ietf/wginfo/edit.py +++ b/ietf/wginfo/edit.py @@ -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: diff --git a/ietf/wginfo/tests.py b/ietf/wginfo/tests.py index 431232d41..7e5bcdec3 100644 --- a/ietf/wginfo/tests.py +++ b/ietf/wginfo/tests.py @@ -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")