diff --git a/news/99.bugfix b/news/99.bugfix new file mode 100644 index 0000000..938aeea --- /dev/null +++ b/news/99.bugfix @@ -0,0 +1 @@ +Fix traversal with virtual hosting with a subsite as the VirtualHostRoot. @davisagli diff --git a/src/plone/rest/tests/test_traversal.py b/src/plone/rest/tests/test_traversal.py index a7be671..98210bd 100644 --- a/src/plone/rest/tests/test_traversal.py +++ b/src/plone/rest/tests/test_traversal.py @@ -141,7 +141,19 @@ def test_virtual_hosting(self): vhm.addToContainer(app) obj = self.traverse( path="/VirtualHostBase/http/localhost:8080/plone/VirtualHostRoot/" - ) # noqa + ) + self.assertTrue(isinstance(obj, Service), "Not a service") + del app["virtual_hosting"] + + def test_virtual_hosting_subpath(self): + app = self.layer["app"] + vhm = VirtualHostMonster() + vhm.id = "virtual_hosting" + vhm.addToContainer(app) + self.portal.invokeFactory("Document", id="doc1") + obj = self.traverse( + path="/VirtualHostBase/http/localhost:8080/plone/doc1/VirtualHostRoot" + ) self.assertTrue(isinstance(obj, Service), "Not a service") del app["virtual_hosting"] diff --git a/src/plone/rest/traverse.py b/src/plone/rest/traverse.py index bd21031..ed96145 100644 --- a/src/plone/rest/traverse.py +++ b/src/plone/rest/traverse.py @@ -112,7 +112,10 @@ def publishTraverse(self, request, name): try: obj = adapter.publishTraverse(request, name) if not IContentish.providedBy(obj) and not IService.providedBy(obj): - raise KeyError + if isinstance(obj, VirtualHostMonster): + return obj + else: + raise KeyError # If there's no object with the given name, we get a KeyError. # In a non-folderish context a key lookup results in an AttributeError.