[Zope-Checkins] SVN: Zope/trunk/ - DAV: litmus "notowner_modify" tests warn during a MOVE request

Chris McDonough chrism at plope.com
Sun Jun 17 09:19:37 EDT 2007


Log message for revision 76725:
        - DAV: litmus "notowner_modify" tests warn during a MOVE request
          because we returned "412 Precondition Failed" instead of "423
          Locked" when the resource attempting to be moved was itself
          locked.  Fixed by changing Resource.Resource.MOVE to raise the
          correct error.
  
  

Changed:
  U   Zope/trunk/doc/CHANGES.txt
  U   Zope/trunk/lib/python/webdav/Resource.py
  U   Zope/trunk/lib/python/webdav/tests/testResource.py

-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt	2007-06-17 01:06:40 UTC (rev 76724)
+++ Zope/trunk/doc/CHANGES.txt	2007-06-17 13:19:36 UTC (rev 76725)
@@ -97,6 +97,12 @@
 
     Bugs Fixed
 
+      - DAV: litmus "notowner_modify" tests warn during a MOVE request
+        because we returned "412 Precondition Failed" instead of "423
+        Locked" when the resource attempting to be moved was itself
+        locked.  Fixed by changing Resource.Resource.MOVE to raise the
+        correct error.
+
       - DAV: litmus props tests 19: propvalnspace and 20:
         propwformed were failing because Zope did not strip off the
         xmlns: attribute attached to XML property values.  We now strip

Modified: Zope/trunk/lib/python/webdav/Resource.py
===================================================================
--- Zope/trunk/lib/python/webdav/Resource.py	2007-06-17 01:06:40 UTC (rev 76724)
+++ Zope/trunk/lib/python/webdav/Resource.py	2007-06-17 13:19:36 UTC (rev 76725)
@@ -456,8 +456,7 @@
         except 'Not Found':
             raise Conflict, 'The resource %s must exist.' % parent_path
         except:
-            t, v, tb=sys.exc_info()
-            raise t, v
+            raise
         if hasattr(parent, '__null_resource__'):
             raise Conflict, 'The resource %s must exist.' % parent_path
         existing=hasattr(aq_base(parent), name)
@@ -511,8 +510,7 @@
                 if not itrue:
                     raise PreconditionFailed, 'Condition failed.'
             else:
-                raise PreconditionFailed, 'Source is locked and no '\
-                      'condition was passed in.'
+                raise Locked('Source is locked and no condition was passed in')
 
         orig_container = aq_parent(aq_inner(self))
         orig_id = self.getId()

Modified: Zope/trunk/lib/python/webdav/tests/testResource.py
===================================================================
--- Zope/trunk/lib/python/webdav/tests/testResource.py	2007-06-17 01:06:40 UTC (rev 76724)
+++ Zope/trunk/lib/python/webdav/tests/testResource.py	2007-06-17 13:19:36 UTC (rev 76725)
@@ -1,18 +1,149 @@
 import unittest
+from AccessControl.SecurityManagement import newSecurityManager
+from AccessControl.SecurityManagement import noSecurityManager
+from AccessControl.SecurityManager import setSecurityPolicy
+from Acquisition import Implicit
 
-
 class TestResource(unittest.TestCase):
+    def setUp(self):
+        self.app = DummyContent()
+        self.app.acl_users = DummyUserFolder()
+        self._policy = PermissiveSecurityPolicy()
+        self._oldPolicy = setSecurityPolicy(self._policy)
+        newSecurityManager(None, OmnipotentUser().__of__(self.app.acl_users))
 
+    def tearDown(self):
+        noSecurityManager()
+        setSecurityPolicy(self._oldPolicy)
+
+    def _getTargetClass(self):
+        from webdav.Resource import Resource
+        return Resource
+
+    def _makeOne(self):
+        klass = self._getTargetClass()
+        inst = klass()
+        return inst
+
     def test_z3interfaces(self):
         from webdav.interfaces import IDAVResource
         from webdav.interfaces import IWriteLock
-        from webdav.Resource import Resource
+        Resource = self._getTargetClass()
         from zope.interface.verify import verifyClass
 
         verifyClass(IDAVResource, Resource)
         verifyClass(IWriteLock, Resource)
 
+    def test_MOVE_self_locked(self):
+        app = self.app
+        request = DummyRequest({}, {})
+        response = DummyResponse()
+        inst = self._makeOne()
+        inst.cb_isMoveable = lambda *arg: True
+        inst.restrictedTraverse = lambda *arg: app
+        inst.getId = lambda *arg: '123'
+        inst._dav_writelocks = {'a':DummyLock()}
+        from zope.interface import directlyProvides
+        from webdav.interfaces import IWriteLock
+        directlyProvides(inst, IWriteLock)
+        from webdav.common import Locked
+        self.assertRaises(Locked, inst.MOVE, request, response)
 
+class DummyLock:
+    def isValid(self):
+        return True
+
+class DummyContent(Implicit):
+    def cb_isMoveable(self):
+        return True
+
+    def _checkId(self, *arg, **kw):
+        return True
+
+    def _verifyObjectPaste(self, *arg):
+        return True
+
+class DummyUserFolder(Implicit):
+    pass
+
+class DummyRequest:
+    def __init__(self, form, headers):
+        self.form = form
+        self.headers = headers
+        
+    def get_header(self, name, default):
+        return self.headers.get(name, default)
+
+    def get(self, name, default):
+        return self.form.get(name, default)
+
+    def physicalPathFromURL(self, *arg):
+        return ['']
+
+class DummyResponse:
+    def __init__(self):
+        self.headers = {}
+
+    def setHeader(self, name, value, *arg):
+        self.headers[name] = value
+
+from AccessControl.PermissionRole import rolesForPermissionOn
+from Acquisition import Implicit
+
+
+class PermissiveSecurityPolicy:
+    """
+        Very permissive security policy for unit testing purposes.
+    """
+    #
+    #   Standard SecurityPolicy interface
+    #
+    def validate( self
+                , accessed=None
+                , container=None
+                , name=None
+                , value=None
+                , context=None
+                , roles=None
+                , *args
+                , **kw):
+        if name and name.startswith('hidden'):
+            return False
+        else:
+            return True
+
+    def checkPermission(self, permission, object, context):
+        if permission == 'forbidden permission':
+            return 0
+        if permission == 'addFoo':
+            return context.user.allowed(object, ['FooAdder'])
+        roles = rolesForPermissionOn(permission, object)
+        if isinstance(roles, basestring):
+            roles=[roles]
+        return context.user.allowed(object, roles)
+
+
+class OmnipotentUser( Implicit ):
+    """
+      Omnipotent User for unit testing purposes.
+    """
+    def getId( self ):
+        return 'all_powerful_Oz'
+
+    getUserName = getId
+
+    def getRoles(self):
+        return ('Manager',)
+
+    def allowed( self, object, object_roles=None ):
+        return 1
+
+    def getRolesInContext(self, object):
+        return ('Manager',)
+
+    def _check_context(self, object):
+        return True
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(TestResource),



More information about the Zope-Checkins mailing list