You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/08/12 23:40:13 UTC

[1/2] git commit: [#6554] Fixed incorrect uses of h.re_project_name causing 404 in REST

Updated Branches:
  refs/heads/master 3cd016078 -> d43c25447


[#6554] Fixed incorrect uses of h.re_project_name causing 404 in REST

Signed-off-by: Cory Johns <cj...@slashdotmedia.com>


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

Branch: refs/heads/master
Commit: 9e3e39413fc2879b6a52ffdd5b6b45e142cf1f72
Parents: 3cd0160
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Mon Aug 12 19:47:18 2013 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Mon Aug 12 19:47:18 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/rest.py           |  7 ++++++-
 Allura/allura/model/project.py              |  6 ++++--
 Allura/allura/tests/functional/test_rest.py |  9 +++++++++
 Allura/allura/tests/model/test_project.py   | 10 ++++++----
 4 files changed, 25 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9e3e3941/Allura/allura/controllers/rest.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/rest.py b/Allura/allura/controllers/rest.py
index c976c21..6a41be3 100644
--- a/Allura/allura/controllers/rest.py
+++ b/Allura/allura/controllers/rest.py
@@ -32,6 +32,8 @@ from ming.utils import LazyProperty
 from allura import model as M
 from allura.lib import helpers as h
 from allura.lib import security
+from allura.lib import plugin
+from allura.lib.exceptions import Invalid
 
 log = logging.getLogger(__name__)
 action_logger = h.log_action(log, 'API:')
@@ -243,7 +245,10 @@ class NeighborhoodRestController(object):
 
     @expose()
     def _lookup(self, name, *remainder):
-        if not h.re_project_name.match(name):
+        provider = plugin.ProjectRegistrationProvider.get()
+        try:
+            provider.shortname_validator.to_python(name, check_allowed=False, neighborhood=self._neighborhood)
+        except Invalid as e:
             raise exc.HTTPNotFound, name
         name = self._neighborhood.shortname_prefix + name
         project = M.Project.query.get(shortname=name, neighborhood_id=self._neighborhood._id, deleted=False)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9e3e3941/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 435cbbb..db7da13 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -638,9 +638,11 @@ class Project(MappedClass, ActivityNode, ActivityObject):
                 return ac
 
     def new_subproject(self, name, install_apps=True, user=None, project_name=None):
-        if not h.re_project_name.match(name):
-            raise exceptions.ToolError, 'Mount point "%s" is invalid' % name
         provider = plugin.ProjectRegistrationProvider.get()
+        try:
+            provider.shortname_validator.to_python(name, check_allowed=False, neighborhood=self.neighborhood)
+        except exceptions.Invalid as e:
+            raise exceptions.ToolError, 'Mount point "%s" is invalid' % name
         return provider.register_subproject(self, name, user or c.user, install_apps, project_name=project_name)
 
     def ordered_mounts(self, include_hidden=False):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9e3e3941/Allura/allura/tests/functional/test_rest.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_rest.py b/Allura/allura/tests/functional/test_rest.py
index fcfb373..d5ed769 100644
--- a/Allura/allura/tests/functional/test_rest.py
+++ b/Allura/allura/tests/functional/test_rest.py
@@ -27,6 +27,7 @@ from nose.tools import assert_equal, assert_in, assert_not_in
 from allura.tests import decorators as td
 from alluratest.controller import TestRestApiBase
 from allura.lib import helpers as h
+from allura.lib.exceptions import Invalid
 from allura import model as M
 
 class TestRestHome(TestRestApiBase):
@@ -141,3 +142,11 @@ class TestRestHome(TestRestApiBase):
                         'qux_24hr': 0,
                     },
                 })
+
+    def test_name_validation(self):
+        r = self.api_get('/rest/p/test/')
+        assert r.status_int == 200
+        with mock.patch('allura.lib.plugin.ProjectRegistrationProvider') as Provider:
+            Provider.get().shortname_validator.to_python.side_effect = Invalid('name', 'value', {})
+            r = self.api_get('/rest/p/test/')
+            assert r.status_int == 404

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9e3e3941/Allura/allura/tests/model/test_project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_project.py b/Allura/allura/tests/model/test_project.py
index 33791f4..2cd7892 100644
--- a/Allura/allura/tests/model/test_project.py
+++ b/Allura/allura/tests/model/test_project.py
@@ -28,8 +28,8 @@ from allura import model as M
 from allura.lib import helpers as h
 from allura.tests import decorators as td
 from alluratest.controller import setup_basic_test, setup_global_objects
-from allura.lib.exceptions import ToolError
-from mock import MagicMock
+from allura.lib.exceptions import ToolError, Invalid
+from mock import MagicMock, patch
 
 
 def setUp():
@@ -93,8 +93,10 @@ def test_project():
 def test_subproject():
     project = M.Project.query.get(shortname='test')
     with td.raises(ToolError):
-        # name exceeds 15 chars
-        sp = project.new_subproject('test-project-nose')
+        with patch('allura.lib.plugin.ProjectRegistrationProvider') as Provider:
+            Provider.get().shortname_validator.to_python.side_effect = Invalid('name', 'value', {})
+            # name doesn't validate
+            sp = project.new_subproject('test-proj-nose')
     sp = project.new_subproject('test-proj-nose')
     spp = sp.new_subproject('spp')
     ThreadLocalORMSession.flush_all()


[2/2] git commit: [#6554] let ProjectConflict be constructed with a single string, like it did before adding Invalid as a parent

Posted by br...@apache.org.
[#6554] let ProjectConflict be constructed with a single string, like it did before adding Invalid as a parent


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

Branch: refs/heads/master
Commit: d43c25447577c512a991b6c70b703fc8438c4cc3
Parents: 9e3e394
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Mon Aug 12 21:34:43 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Mon Aug 12 21:34:43 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/exceptions.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d43c2544/Allura/allura/lib/exceptions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/exceptions.py b/Allura/allura/lib/exceptions.py
index 4c33991..7611dd7 100644
--- a/Allura/allura/lib/exceptions.py
+++ b/Allura/allura/lib/exceptions.py
@@ -18,7 +18,14 @@
 from formencode import Invalid
 
 class ForgeError(Exception): pass
-class ProjectConflict(ForgeError, Invalid): pass
+
+class ProjectConflict(ForgeError, Invalid):
+
+    # support the single string constructor in addition to full set of params that Invalid.__init__ requires
+    def __init__(self, msg, value=None, state=None, error_list=None, error_dict=None):
+        super(ProjectConflict, self).__init__(msg, value, state, error_list, error_dict)
+
+
 class ProjectShortnameInvalid(ForgeError, Invalid): pass
 class ProjectOverlimitError(ForgeError): pass
 class ProjectRatelimitError(ForgeError): pass
@@ -45,4 +52,3 @@ class CompoundError(ForgeError):
                 parts.append('    ' + line)
         parts.append('</%s>\n' % self.__class__.__name__ )
         return ''.join(parts)
-