allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject allura git commit: [#8041] more accurate project & mount point regex matching DNS host rules
Date Thu, 07 Jan 2016 16:47:38 GMT
Repository: allura
Updated Branches:
  refs/heads/db/8041 [created] ed3db5675


[#8041] more accurate project & mount point regex matching DNS host rules


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/ed3db567
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/ed3db567
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/ed3db567

Branch: refs/heads/db/8041
Commit: ed3db5675f099244e4b8e587debea5465aaa7b5c
Parents: dfa249a
Author: Dave Brondsema <dave@brondsema.net>
Authored: Thu Jan 7 11:47:33 2016 -0500
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Thu Jan 7 11:47:33 2016 -0500

----------------------------------------------------------------------
 Allura/allura/lib/helpers.py         | 12 ++++++++----
 Allura/allura/tests/test_plugin.py   |  2 ++
 Allura/allura/tests/unit/test_app.py |  6 ++++++
 3 files changed, 16 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/ed3db567/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 93c0d6f..a796067 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -68,11 +68,15 @@ from .security import has_access
 
 log = logging.getLogger(__name__)
 
-# validates project, subproject, and user names
-re_project_name = re.compile(r'^[a-z][-a-z0-9]{2,14}$')
+# http://stackoverflow.com/questions/2063213/regular-expression-for-validating-dns-label-host-name
+# modified to remove capital A-Z and make length parameterized
+dns_var_length = r'^(?![0-9]+$)(?!-)[a-z0-9-]{%s}(?<!-)$'
 
-# validates tool mount point names
-re_tool_mount_point = re.compile(r'^[a-z][-a-z0-9]{0,62}$')
+# validates project, subproject, and user names; must comply to DNS since used in subdomains
for emailing
+re_project_name = re.compile(dns_var_length % '3,15')
+
+# validates tool mount point names; must comply to DNS since used in subdomains for emailing
+re_tool_mount_point = re.compile(dns_var_length % '1,63')
 re_tool_mount_point_fragment = re.compile(r'[a-z][-a-z0-9]*')
 re_relaxed_tool_mount_point = re.compile(
     r'^[a-zA-Z0-9][-a-zA-Z0-9_\.\+]{0,62}$')

http://git-wip-us.apache.org/repos/asf/allura/blob/ed3db567/Allura/allura/tests/test_plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_plugin.py b/Allura/allura/tests/test_plugin.py
index d379d97..0441f18 100644
--- a/Allura/allura/tests/test_plugin.py
+++ b/Allura/allura/tests/test_plugin.py
@@ -86,6 +86,8 @@ class TestProjectRegistrationProvider(object):
                       'this-is-valid-but-too-long', neighborhood=nbhd)
         assert_raises(ProjectShortnameInvalid, v,
                       'this is invalid and too long', neighborhood=nbhd)
+        assert_raises(ProjectShortnameInvalid, v,
+                      'end-dash-', neighborhood=nbhd)
         Project.query.get.return_value = Mock()
         assert_raises(ProjectConflict, v, 'thisislegit', neighborhood=nbhd)
 

http://git-wip-us.apache.org/repos/asf/allura/blob/ed3db567/Allura/allura/tests/unit/test_app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_app.py b/Allura/allura/tests/unit/test_app.py
index eca1ae7..667dc09 100644
--- a/Allura/allura/tests/unit/test_app.py
+++ b/Allura/allura/tests/unit/test_app.py
@@ -30,8 +30,14 @@ class TestApplication(TestCase):
 
     def test_validate_mount_point(self):
         app = Application
+
+        self.assertIsNotNone(app.validate_mount_point('dash-in-middle'))
+
+        self.assertIsNone(app.validate_mount_point('end-dash-'))
+
         mount_point = '1.2+foo_bar'
         self.assertIsNone(app.validate_mount_point(mount_point))
+
         app.relaxed_mount_points = True
         self.assertIsNotNone(app.validate_mount_point(mount_point))
 


Mime
View raw message