You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/08/13 21:18:47 UTC
[4/7] git commit: [#6554] Fixed incorrect uses of h.re_project_name
causing 404 in REST
[#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/cj/5177
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()