Commit 1b017c2c authored by Jérome Perrin's avatar Jérome Perrin

open_api: support requests with "something" in the request path

For zope, a request to /erp5/person_module/person1 or
/erp5/organisation_module/person_module/person1 can both be resolved
and are (more or less) equivalent. This change brings support for
similar request paths for Open API Connectors.
parent 5144c256
Pipeline #27695 failed with stage
in 0 seconds
...@@ -188,10 +188,12 @@ class OpenAPIService(XMLObject): ...@@ -188,10 +188,12 @@ class OpenAPIService(XMLObject):
unquote(part) for part in request['URL'] unquote(part) for part in request['URL']
[1 + len(request.physicalPathToURL(root.getPhysicalPath())):].split('/') [1 + len(request.physicalPathToURL(root.getPhysicalPath())):].split('/')
] ]
# then strip everything corresponding to the "self" open api service # then strip everything corresponding to the "self" open api service.
# Here, unlike getPhysicalPath(), we don't use the inner acquistion,
# but keep the acquisition chain from this request traversal.
i = 0 i = 0
for self_relative_url_part in self.getRelativeUrl().split('/'): for aq_parent in reversed(self.aq_chain[:self.aq_chain.index(root)]):
if self_relative_url_part == request_path_parts[i]: if aq_parent.id == request_path_parts[i]:
i += 1 i += 1
else: else:
break break
......
...@@ -1076,7 +1076,7 @@ class TestOpenAPIErrorHandling(OpenAPIPetStoreTestCase): ...@@ -1076,7 +1076,7 @@ class TestOpenAPIErrorHandling(OpenAPIPetStoreTestCase):
class TestRestrictedAPI(OpenAPIPetStoreTestCase): class TestRestrictedAPI(OpenAPIPetStoreTestCase):
_public_api = False _public_api = False
def test_unauthorized(self): def test_unauthorized(self):
# the connector can not be traversed by anonymous user because the API # the connector can not be traversed by anonymous user because the connector
# is not public in this test. # is not public in this test.
self.addPythonScript( self.addPythonScript(
'TestPetStoreOpenAPI_findPetsByStatus', 'status', 'TestPetStoreOpenAPI_findPetsByStatus', 'status',
...@@ -1222,3 +1222,23 @@ class TestURLPathWithWebSiteAndVirtualHost(OpenAPIPetStoreTestCase): ...@@ -1222,3 +1222,23 @@ class TestURLPathWithWebSiteAndVirtualHost(OpenAPIPetStoreTestCase):
self.connector.getPath() self.connector.getPath()
)) ))
self.assertEqual(response.getBody(), b'"ok"') self.assertEqual(response.getBody(), b'"ok"')
def test_acquisition_path(self):
response = self.publish(
'/{}/person_module/{}/pet/789'.format(
self.portal.getId(),
self.connector.getRelativeUrl(),
))
self.assertEqual(response.getBody(), b'"ok"')
response = self.publish(
'/VirtualHostBase/https/example.com:443/{}/VirtualHostRoot/person_module/{}/pet/789'.format(
self.portal.getId(),
self.connector.getRelativeUrl(),
))
self.assertEqual(response.getBody(), b'"ok"')
response = self.publish(
'/VirtualHostBase/https/example.com:443/{}/VirtualHostRoot/_vh_vh1/_vh_vh2/person_module/{}/pet/789'.format(
self.portal.getId(),
self.connector.getRelativeUrl()
))
self.assertEqual(response.getBody(), b'"ok"')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment