allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject allura git commit: [#8041] more accurate project & mount point regex matching DNS host rules
Date Mon, 11 Jan 2016 15:37:46 GMT
Repository: allura
Updated Branches:
  refs/heads/master 3424beedf -> fc1ca949c


[#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/fc1ca949
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/fc1ca949
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/fc1ca949

Branch: refs/heads/master
Commit: fc1ca949c6f00ac2df1f41fcadca45dc43dad7e4
Parents: 3424bee
Author: Dave Brondsema <dave@brondsema.net>
Authored: Thu Jan 7 11:47:33 2016 -0500
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Fri Jan 8 18:04:54 2016 -0500

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


http://git-wip-us.apache.org/repos/asf/allura/blob/fc1ca949/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 4bf92ae..c66b3f5 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -68,9 +68,14 @@ from .security import has_access
 
 log = logging.getLogger(__name__)
 
+# 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}(?<!-)$'
+
+# project & tool names must comply to DNS since used in subdomains for emailing
 re_mount_points = {
-    're_project_name': r'^[a-z][-a-z0-9]{2,14}$',  # validates project, subproject, and user
names
-    're_tool_mount_point': r'^[a-z][-a-z0-9]{0,62}$',  # validates tool mount point names
+    're_project_name': dns_var_length % '3,15',  # validates project, subproject, and user
names
+    're_tool_mount_point': dns_var_length % '1,63',  # validates tool mount point names
     're_tool_mount_point_fragment': r'[a-z][-a-z0-9]*',
     're_relaxed_tool_mount_point': r'^[a-zA-Z0-9][-a-zA-Z0-9_\.\+]{0,62}$',
     're_relaxed_tool_mount_point_fragment':  r'[a-zA-Z0-9][-a-zA-Z0-9_\.\+]*'

http://git-wip-us.apache.org/repos/asf/allura/blob/fc1ca949/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/fc1ca949/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