We do need to do some wrapping when objects are found via namespace

traversal.
parent 51f1cb82
...@@ -23,6 +23,7 @@ from AccessControl import getSecurityManager ...@@ -23,6 +23,7 @@ from AccessControl import getSecurityManager
from AccessControl import Unauthorized from AccessControl import Unauthorized
from AccessControl.ZopeGuards import guarded_getattr from AccessControl.ZopeGuards import guarded_getattr
from Acquisition import Acquired, aq_inner, aq_parent, aq_acquire, aq_base from Acquisition import Acquired, aq_inner, aq_parent, aq_acquire, aq_base
from Acquisition.interfaces import IAcquirer
from zExceptions import NotFound from zExceptions import NotFound
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from OFS.interfaces import ITraversable from OFS.interfaces import ITraversable
...@@ -193,6 +194,8 @@ class Traversable: ...@@ -193,6 +194,8 @@ class Traversable:
try: try:
next = namespaceLookup( next = namespaceLookup(
ns, nm, obj, aq_acquire(self, 'REQUEST')) ns, nm, obj, aq_acquire(self, 'REQUEST'))
if IAcquirer.providedBy(next):
next = next.__of__(obj)
if restricted and not validate( if restricted and not validate(
obj, obj, name, next): obj, obj, name, next):
raise Unauthorized(name) raise Unauthorized(name)
......
...@@ -18,7 +18,10 @@ which mix-in one of the Acquisition base classes without knowing ...@@ -18,7 +18,10 @@ which mix-in one of the Acquisition base classes without knowing
better) still work. better) still work.
""" """
import Acquisition import Acquisition
import OFS.SimpleItem
from zope.interface import implements from zope.interface import implements
from zope.traversing.interfaces import ITraversable
from zope.contentprovider.interfaces import IContentProvider from zope.contentprovider.interfaces import IContentProvider
from Products.Five import BrowserView from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
...@@ -115,3 +118,19 @@ class BrowserViewViewlet(BrowserView): ...@@ -115,3 +118,19 @@ class BrowserViewViewlet(BrowserView):
def render(self): def render(self):
return 'BrowserView viewlet' return 'BrowserView viewlet'
class LegacyNamespace(object):
implements(ITraversable)
def __init__(self, context, request):
self.context = context
self.request = request
def traverse(self, name, ignored):
return LegacyNamespaceObject(name)
class LegacyNamespaceObject(OFS.SimpleItem.SimpleItem):
def __init__(self, name):
self.id = name
...@@ -112,4 +112,24 @@ ...@@ -112,4 +112,24 @@
permission="zope.Public" permission="zope.Public"
/> />
<!-- Namespace traversal -->
<adapter
for="*"
factory=".aqlegacy.LegacyNamespace"
name="aqlegacy"
/>
<adapter
for="* *"
factory=".aqlegacy.LegacyNamespace"
name="aqlegacy"
/>
<browser:page
for=".aqlegacy.LegacyNamespaceObject"
name="index.html"
template="falcon.pt"
permission="zope.Public"
/>
</configure> </configure>
\ No newline at end of file
...@@ -141,6 +141,28 @@ Testing legacy content providers and viewlets ...@@ -141,6 +141,28 @@ Testing legacy content providers and viewlets
Viewlet inheriting from Explicit</p> Viewlet inheriting from Explicit</p>
Testing namespace traversal
===========================
Namespace traversal can turn up objects during traversal without
attribute access. That means they might not be wrapped by default.
Here we make sure that they are wrapped and that things like the
request can be acquired.
First let's try ``restrictedTraverse()``:
>>> foo = self.folder.restrictedTraverse('++aqlegacy++foo')
>>> import Acquisition
>>> Acquisition.aq_acquire(foo, 'REQUEST')
<HTTPRequest, URL=http://nohost>
Now let's try URL traversal:
>>> browser.open('http://localhost/test_folder_1_/++aqlegacy++foo/index.html')
>>> print browser.contents
<p>The falcon has taken flight</p>
Clean up Clean up
-------- --------
......
...@@ -18,6 +18,7 @@ from urllib import quote as urllib_quote ...@@ -18,6 +18,7 @@ from urllib import quote as urllib_quote
import xmlrpc import xmlrpc
from zExceptions import Forbidden, Unauthorized, NotFound from zExceptions import Forbidden, Unauthorized, NotFound
from Acquisition import aq_base from Acquisition import aq_base
from Acquisition.interfaces import IAcquirer
from zope.interface import implements, providedBy, Interface from zope.interface import implements, providedBy, Interface
from zope.component import queryMultiAdapter from zope.component import queryMultiAdapter
...@@ -312,6 +313,9 @@ class BaseRequest: ...@@ -312,6 +313,9 @@ class BaseRequest:
ob2 = namespaceLookup(ns, nm, ob, self) ob2 = namespaceLookup(ns, nm, ob, self)
except TraversalError: except TraversalError:
raise KeyError(ob, name) raise KeyError(ob, name)
if IAcquirer.providedBy(ob2):
ob2 = ob2.__of__(ob)
return ob2 return ob2
if name == '.': if name == '.':
......
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