From 9c5bc99b5cc39d1b0e84d9a01bf62c5234ad772a Mon Sep 17 00:00:00 2001 From: Fei Long Wang Date: Thu, 12 Dec 2013 00:50:40 +0800 Subject: [PATCH] Return relative URIs for href-template of homedoc Based on current implement, some href-template of homedoc are returning absolute path ('/queues'...). It may cause a 404 error because client may join a host with the path directly. This patch will make sure all the href-template start with /v1 and add unit test case to make url joining works well. Fixes bug 1245656 Change-Id: I12059249135cdb82be7d1937cf65db5da860011b --- marconi/queues/transport/wsgi/v1.py | 10 ++++----- tests/unit/queues/transport/wsgi/test_home.py | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/marconi/queues/transport/wsgi/v1.py b/marconi/queues/transport/wsgi/v1.py index 3119c1622..028abe13a 100644 --- a/marconi/queues/transport/wsgi/v1.py +++ b/marconi/queues/transport/wsgi/v1.py @@ -24,7 +24,7 @@ JSON_HOME = { # Queues #------------------------------------------------------------------ 'rel/queues': { - 'href-template': '/queues{?marker,limit,detailed}', + 'href-template': '/v1/queues{?marker,limit,detailed}', 'href-vars': { 'marker': 'param/marker', 'limit': 'param/queue_limit', @@ -38,7 +38,7 @@ JSON_HOME = { }, }, 'rel/queue': { - 'href-template': '/queues/{queue_name}', + 'href-template': '/v1/queues/{queue_name}', 'href-vars': { 'queue_name': 'param/queue_name', }, @@ -50,7 +50,7 @@ JSON_HOME = { }, }, 'rel/queue-metadata': { - 'href-template': '/queues/{queue_name}/metadata', + 'href-template': '/v1/queues/{queue_name}/metadata', 'href-vars': { 'queue_name': 'param/queue_name', }, @@ -62,7 +62,7 @@ JSON_HOME = { }, }, 'rel/queue-stats': { - 'href-template': '/queues/{queue_name}/stats', + 'href-template': '/v1/queues/{queue_name}/stats', 'href-vars': { 'queue_name': 'param/queue_name', }, @@ -78,7 +78,7 @@ JSON_HOME = { # Messages #------------------------------------------------------------------ 'rel/messages': { - 'href-template': ('/queues/{queue_name}/messages' + 'href-template': ('/v1/queues/{queue_name}/messages' '{?marker,limit,echo,include_claimed}'), 'href-vars': { 'queue_name': 'param/queue_name', diff --git a/tests/unit/queues/transport/wsgi/test_home.py b/tests/unit/queues/transport/wsgi/test_home.py index b33ac4f84..22f35196f 100644 --- a/tests/unit/queues/transport/wsgi/test_home.py +++ b/tests/unit/queues/transport/wsgi/test_home.py @@ -15,6 +15,7 @@ # limitations under the License. import json +import urlparse import falcon @@ -36,3 +37,24 @@ class TestHomeDocument(base.TestBase): json.loads(body[0]) except ValueError: self.fail('Home document is not valid JSON') + + def test_href_template(self): + body = self.simulate_get('/v1') + self.assertEqual(self.srmock.status, falcon.HTTP_200) + resp = json.loads(body[0]) + queue_href_template = resp['resources']['rel/queue']['href-template'] + path_1 = 'https://marconi.example.com/v1' + path_2 = 'https://marconi.example.com/v1/' + + # verify all the href template start with /v1 + for resource in list(resp['resources']): + self.assertTrue(resp['resources'][resource]['href-template']. + startswith('/v1')) + + url = urlparse.urljoin(path_1, queue_href_template) + self.assertEqual(url.format(queue_name='foo'), + 'https://marconi.example.com/v1/queues/foo') + + url = urlparse.urljoin(path_2, queue_href_template) + self.assertEqual(url.format(queue_name='foo'), + 'https://marconi.example.com/v1/queues/foo')