summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-11-08 21:05:32 +0000
committerGerrit Code Review <review@openstack.org>2012-11-08 21:05:32 +0000
commitab9ee3d232e0000dd8b8f1d2623d8ac72a6c9247 (patch)
tree276b0fa70eed85bd21ebec88c4803de58f226ef7
parentfab607c72c36ace398cee817bae2525162dcb9f1 (diff)
parent8935c3bde9e9635f65522488c1aca5df5b03050d (diff)
downloadnova-ab9ee3d232e0000dd8b8f1d2623d8ac72a6c9247.tar.gz
nova-ab9ee3d232e0000dd8b8f1d2623d8ac72a6c9247.tar.xz
nova-ab9ee3d232e0000dd8b8f1d2623d8ac72a6c9247.zip
Merge "Limit formatting routes when adding resources"
-rw-r--r--nova/api/openstack/__init__.py9
-rw-r--r--nova/tests/api/openstack/compute/test_extensions.py28
2 files changed, 37 insertions, 0 deletions
diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py
index d27b018c2..67ea6e1b5 100644
--- a/nova/api/openstack/__init__.py
+++ b/nova/api/openstack/__init__.py
@@ -90,6 +90,15 @@ class APIMapper(routes.Mapper):
return result[0], result[1]
return routes.Mapper.routematch(self, url, environ)
+ def connect(self, *args, **kargs):
+ # NOTE(vish): Default the format part of a route to only accept json
+ # and xml so it doesn't eat all characters after a '.'
+ # in the url.
+ kargs.setdefault('requirements', {})
+ if not kargs['requirements'].get('format'):
+ kargs['requirements']['format'] = 'json|xml'
+ return routes.Mapper.connect(self, *args, **kargs)
+
class ProjectMapper(APIMapper):
def resource(self, member_name, collection_name, **kwargs):
diff --git a/nova/tests/api/openstack/compute/test_extensions.py b/nova/tests/api/openstack/compute/test_extensions.py
index 466fd3636..ceb90d24c 100644
--- a/nova/tests/api/openstack/compute/test_extensions.py
+++ b/nova/tests/api/openstack/compute/test_extensions.py
@@ -666,3 +666,31 @@ class ExtensionsXMLSerializerTest(test.TestCase):
self.assertEqual(link_nodes[i].get(key), value)
xmlutil.validate_schema(root, 'extensions')
+
+
+class ExtensionControllerIdFormatTest(test.TestCase):
+
+ def _bounce_id(self, test_id):
+
+ class BounceController(object):
+ def show(self, req, id):
+ return id
+ res_ext = base_extensions.ResourceExtension('bounce',
+ BounceController())
+ manager = StubExtensionManager(res_ext)
+ app = compute.APIRouter(manager)
+ request = webob.Request.blank("/fake/bounce/%s" % test_id)
+ response = request.get_response(app)
+ return response.body
+
+ def test_id_with_xml_format(self):
+ result = self._bounce_id('foo.xml')
+ self.assertEqual(result, 'foo')
+
+ def test_id_with_json_format(self):
+ result = self._bounce_id('foo.json')
+ self.assertEqual(result, 'foo')
+
+ def test_id_with_bad_format(self):
+ result = self._bounce_id('foo.bad')
+ self.assertEqual(result, 'foo.bad')