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
This commit is contained in:
parent
9c87eb244d
commit
9c5bc99b5c
@ -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',
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user