[Zope-Checkins] SVN: Zope/trunk/ DAV: litmus'
cond_put_corrupt_token test (#18) exposed a bug
Chris McDonough
chrism at plope.com
Sun Jun 17 11:01:30 EDT 2007
Log message for revision 76731:
DAV: litmus' cond_put_corrupt_token test (#18) exposed a bug
in webdav.Resource.dav__simpleifhandler. If the resource is
locked at all, and a DAV request contains an If header, and
none of the lock tokens present in the header match a lock on
the resource, we need to return a 423 Locked instead of 204 No
Content.
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 14:08:57 UTC (rev 76730)
+++ Zope/trunk/doc/CHANGES.txt 2007-06-17 15:01:29 UTC (rev 76731)
@@ -97,6 +97,13 @@
Bugs Fixed
+ - DAV: litmus' cond_put_corrupt_token test (#18) exposed a bug
+ in webdav.Resource.dav__simpleifhandler. If the resource is
+ locked at all, and a DAV request contains an If header, and
+ none of the lock tokens present in the header match a lock on
+ the resource, we need to return a 423 Locked instead of 204 No
+ Content.
+
- 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
Modified: Zope/trunk/lib/python/webdav/Resource.py
===================================================================
--- Zope/trunk/lib/python/webdav/Resource.py 2007-06-17 14:08:57 UTC (rev 76730)
+++ Zope/trunk/lib/python/webdav/Resource.py 2007-06-17 15:01:29 UTC (rev 76731)
@@ -157,14 +157,13 @@
for token in wehave: self.wl_getLock(token).refresh()
found = 1; break
- if resourcetagged and (not found):
- raise PreconditionFailed, 'Condition failed.'
- elif resourcetagged and found:
+ if resourcetagged and found:
return 1
- else:
- return 0
+ if (not resourcetagged) and (not found):
+ raise Locked('Resource locked and no recognized lock tokens in '
+ 'If header')
+ raise PreconditionFailed('Condition failed')
-
# WebDAV class 1 support
security.declareProtected(View, 'HEAD')
def HEAD(self, REQUEST, RESPONSE):
Modified: Zope/trunk/lib/python/webdav/tests/testResource.py
===================================================================
--- Zope/trunk/lib/python/webdav/tests/testResource.py 2007-06-17 14:08:57 UTC (rev 76730)
+++ Zope/trunk/lib/python/webdav/tests/testResource.py 2007-06-17 15:01:29 UTC (rev 76731)
@@ -35,6 +35,13 @@
verifyClass(IWriteLock, Resource)
def test_MOVE_self_locked(self):
+ """
+ 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.
+ """
app = self.app
request = DummyRequest({}, {})
response = DummyResponse()
@@ -49,6 +56,27 @@
from webdav.common import Locked
self.assertRaises(Locked, inst.MOVE, request, response)
+ def test_dav__simpleifhandler_cond_put_corrupt_token(self):
+ """
+ DAV: litmus' cond_put_corrupt_token test (#18) exposed a bug
+ in webdav.Resource.dav__simpleifhandler. If the resource is
+ locked at all, and a DAV request contains an If header, and
+ none of the lock tokens present in the header match a lock on
+ the resource, we need to return a 423 Locked instead of 204 No
+ Content.
+ """
+ ifhdr = 'If: (<locktoken:foo>) (Not <DAV:no-lock>)'
+ request = DummyRequest({'URL':'http://example.com/foo/PUT'},
+ {'If':ifhdr})
+ response = DummyResponse()
+ inst = self._makeOne()
+ 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.dav__simpleifhandler, request, response)
+
class DummyLock:
def isValid(self):
return True
@@ -77,6 +105,9 @@
def get(self, name, default):
return self.form.get(name, default)
+ def __getitem__(self, name):
+ return self.form[name]
+
def physicalPathFromURL(self, *arg):
return ['']
More information about the Zope-Checkins
mailing list