[extensions-web] extensions: Fix UUID policy
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] extensions: Fix UUID policy
- Date: Sat, 3 Mar 2012 11:17:00 +0000 (UTC)
commit b5e5bd487774032d06f87dfdbf1915bcac348e86
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Sat Mar 3 05:58:12 2012 -0500
extensions: Fix UUID policy
It was broken. Add a test, too.
sweettooth/extensions/models.py | 6 ++++--
sweettooth/extensions/tests.py | 18 ++++++++++++++++++
2 files changed, 22 insertions(+), 2 deletions(-)
---
diff --git a/sweettooth/extensions/models.py b/sweettooth/extensions/models.py
index 4d8cad1..2ad2b39 100644
--- a/sweettooth/extensions/models.py
+++ b/sweettooth/extensions/models.py
@@ -33,10 +33,12 @@ REJECTED_STATUSES = (STATUS_REJECTED,)
REVIEWED_STATUSES = (STATUS_REJECTED, STATUS_INACTIVE, STATUS_ACTIVE)
def validate_uuid(uuid):
- if re.match('[-a-zA-Z0-9 _]+$', uuid) is None:
+ if re.match(r'[-a-zA-Z0-9 _]+$', uuid) is None:
return False
- if uuid.endswith('.gnome.org'):
+ # Don't blacklist "gnome.org" - we don't want to eliminate
+ # world-of-gnome.org or something like that.
+ if re.search(r'[ ]gnome\ org$', uuid) is not None:
return False
return True
diff --git a/sweettooth/extensions/tests.py b/sweettooth/extensions/tests.py
index 8e6637c..ac36015 100644
--- a/sweettooth/extensions/tests.py
+++ b/sweettooth/extensions/tests.py
@@ -1,6 +1,7 @@
import os.path
import tempfile
+import uuid
from zipfile import ZipFile
try:
@@ -28,6 +29,23 @@ def get_test_zipfile(testname):
return new_temp
+class UUIDPolicyTest(TestCase):
+ def test_uuid_policy(self):
+ self.assertTrue(models.validate_uuid("foo mecheye net"))
+ self.assertTrue(models.validate_uuid("foo_2 mecheye net"))
+ self.assertTrue(models.validate_uuid("foo-3 mecheye net"))
+ self.assertTrue(models.validate_uuid("Foo4 mecheye net"))
+
+ for i in xrange(10):
+ self.assertTrue(models.validate_uuid(str(uuid.uuid4())))
+
+ self.assertFalse(models.validate_uuid("<Wonderful>"))
+
+ self.assertFalse(models.validate_uuid("foo gnome org"))
+ self.assertFalse(models.validate_uuid("bar people gnome org"))
+
+ self.assertTrue(models.validate_uuid("bar i-love-gnome org"))
+
class ParseZipfileTest(BasicUserTestCase, TestCase):
def test_simple_metadata(self):
metadata = {"uuid": "test-metadata mecheye net",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]