[Checkins] SVN: zope.webdav/trunk/src/zope/webdav/ Fix COPY and
MOVE methods so that we don't raise a BadGateway error when a
Michael Kerrin
michael.kerrin at openapp.biz
Wed Sep 27 10:24:48 EDT 2006
Log message for revision 70400:
Fix COPY and MOVE methods so that we don't raise a BadGateway error when a
username is embeded in the URL of the origin or destination address.
Changed:
U zope.webdav/trunk/src/zope/webdav/copymove.py
U zope.webdav/trunk/src/zope/webdav/tests/test_copymove.py
-=-
Modified: zope.webdav/trunk/src/zope/webdav/copymove.py
===================================================================
--- zope.webdav/trunk/src/zope/webdav/copymove.py 2006-09-27 14:11:00 UTC (rev 70399)
+++ zope.webdav/trunk/src/zope/webdav/copymove.py 2006-09-27 14:24:33 UTC (rev 70400)
@@ -61,14 +61,16 @@
scheme, location, destpath, query, fragment = urlparse.urlsplit(dest)
# XXX - this is likely to break under virtual hosting.
- if location and self.request.get("HTTP_HOST", None) is not None and \
- location != self.request.get("HTTP_HOST"):
- # This may occur when the destination is on another
- # server, repository or URL namespace. Either the source namespace
- # does not support copying to the destination namespace, or the
- # destination namespace refuses to accept the resource. The client
- # may wish to try GET/PUT and PROPFIND/PROPPATCH instead.
- raise zope.webdav.interfaces.BadGateway(self.context, self.request)
+ if location and self.request.get("HTTP_HOST", None) is not None:
+ if location.split("@", 1)[-1] != self.request.get("HTTP_HOST"):
+ # This may occur when the destination is on another
+ # server, repository or URL namespace. Either the source
+ # namespace does not support copying to the destination
+ # namespace, or the destination namespace refuses to accept
+ # the resource. The client may wish to try GET/PUT and
+ # PROPFIND/PROPPATCH instead.
+ raise zope.webdav.interfaces.BadGateway(
+ self.context, self.request)
return destpath
Modified: zope.webdav/trunk/src/zope/webdav/tests/test_copymove.py
===================================================================
--- zope.webdav/trunk/src/zope/webdav/tests/test_copymove.py 2006-09-27 14:11:00 UTC (rev 70399)
+++ zope.webdav/trunk/src/zope/webdav/tests/test_copymove.py 2006-09-27 14:24:33 UTC (rev 70400)
@@ -146,6 +146,36 @@
self.assertRaises(zope.webdav.interfaces.BadGateway,
copy.getDestinationPath)
+ def test_getDestinationPath_with_username(self):
+ resource = self.root["resource"] = test_locking.Resource()
+ request = TestRequest(
+ environ = {"DESTINATION": "http://michael@localhost/testpath"})
+ copy = COPY(resource, request)
+ destname, destob, parent = copy.getDestinationNameAndParentObject()
+ self.assertEqual(destname, "testpath")
+ self.assertEqual(destob, None)
+ self.assertEqual(parent, self.root)
+
+ def test_getDestinationPath_with_username_and_password(self):
+ resource = self.root["resource"] = test_locking.Resource()
+ request = TestRequest(
+ environ = {"DESTINATION": "http://michael:pw@localhost/testpath"})
+ copy = COPY(resource, request)
+ destname, destob, parent = copy.getDestinationNameAndParentObject()
+ self.assertEqual(destname, "testpath")
+ self.assertEqual(destob, None)
+ self.assertEqual(parent, self.root)
+
+ def test_getDestinationPath_with_port(self):
+ # this is correct since localhost:10080 is a different server to
+ # localhost.
+ resource = self.root["resource"] = test_locking.Resource()
+ request = TestRequest(
+ environ = {"DESTINATION": "http://localhost:10080/testpath"})
+ copy = COPY(resource, request)
+ self.assertRaises(zope.webdav.interfaces.BadGateway,
+ copy.getDestinationNameAndParentObject)
+
def test_getDestinationNameAndParentObject(self):
resource = self.root["resource"] = test_locking.Resource()
request = TestRequest(
More information about the Checkins
mailing list