[Checkins] SVN: z3c.dav/trunk/src/z3c/dav/ Fix issue https://bugs.launchpad.net/z3c.dav/+bug/163153

Michael Kerrin michael.kerrin at openapp.ie
Sun Nov 18 10:39:09 EST 2007


Log message for revision 81918:
  Fix issue https://bugs.launchpad.net/z3c.dav/+bug/163153
  
  PROPFIND and MKCOL methods were incorrectly checking the content-length header.
  

Changed:
  U   z3c.dav/trunk/src/z3c/dav/mkcol.py
  U   z3c.dav/trunk/src/z3c/dav/propfind.py
  U   z3c.dav/trunk/src/z3c/dav/tests/test_propfind.py

-=-
Modified: z3c.dav/trunk/src/z3c/dav/mkcol.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/mkcol.py	2007-11-18 15:38:08 UTC (rev 81917)
+++ z3c.dav/trunk/src/z3c/dav/mkcol.py	2007-11-18 15:39:08 UTC (rev 81918)
@@ -52,11 +52,19 @@
     implementation of MKCOL doesn't understand any message body received
     with a MKCOL request and thus raise a UnsupportedMediaType exception.
 
-      >>> mkcol = MKCOL(context, TestRequest(StringIO('some request body')))
-      >>> mkcol.MKCOL() #doctest:+ELLIPSIS
+      >>> MKCOL(context,
+      ...    TestRequest(StringIO('some request data'),
+      ...                environ = {'CONTENT_LENGTH': '17'})).MKCOL() #doctest:+ELLIPSIS
       Traceback (most recent call last):
       ...
       UnsupportedMediaType: <zope.app.http.put.NullResource object at ...>, u'A request body is not supported for a MKCOL method'
+      >>> MKCOL(context,
+      ...    TestRequest(StringIO('some request data'),
+      ...                environ = {'CONTENT_LENGTH': 17})).MKCOL() #doctest:+ELLIPSIS
+      Traceback (most recent call last):
+      ...
+      UnsupportedMediaType: <zope.app.http.put.NullResource object at ...>, u'A request body is not supported for a MKCOL method'
+
       >>> events
       []
 
@@ -138,6 +146,30 @@
       >>> events[3:]
       []
 
+    Unsupported media type
+    ======================
+
+    The test for the unsupported media type is on the 'content-length' so make
+    sure that if test this against 'Content-Length': 0 and None properly.
+
+      >>> context = NullResource(container, 'newdir1')
+      >>> MKCOL(context,
+      ...    TestRequest(StringIO(''),
+      ...                environ = {'CONTENT_LENGTH': 0})).MKCOL() #doctest:+ELLIPSIS
+      ''
+
+      >>> context = NullResource(container, 'newdir2')
+      >>> MKCOL(context,
+      ...    TestRequest(StringIO(''),
+      ...                environ = {'CONTENT_LENGTH': '0'})).MKCOL() #doctest:+ELLIPSIS
+      ''
+
+      >>> context = NullResource(container, 'newdir3')
+      >>> MKCOL(context,
+      ...    TestRequest(StringIO(''),
+      ...                environ = {'CONTENT_LENGTH': None})).MKCOL() #doctest:+ELLIPSIS
+      ''
+
     Cleanup.
 
       >>> component.getGlobalSiteManager().unregisterAdapter(WriteDirectory)
@@ -156,7 +188,7 @@
         self.request = request
 
     def MKCOL(self):
-        if self.request.getHeader("content-length") > 0:
+        if int(self.request.getHeader("content-length", 0)) > 0:
             # We don't (yet) support a request body on MKCOL.
             raise z3c.dav.interfaces.UnsupportedMediaType(
                 self.context,

Modified: z3c.dav/trunk/src/z3c/dav/propfind.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/propfind.py	2007-11-18 15:38:08 UTC (rev 81917)
+++ z3c.dav/trunk/src/z3c/dav/propfind.py	2007-11-18 15:39:08 UTC (rev 81918)
@@ -68,7 +68,7 @@
         return self.request.getHeader("depth", "infinity")
 
     def PROPFIND(self):
-        if self.request.getHeader("content-length") > 0 and \
+        if int(self.request.getHeader("content-length", 0)) > 0 and \
                self.request.content_type not in ("text/xml", "application/xml"):
             raise z3c.dav.interfaces.BadRequest(
                 self.request,

Modified: z3c.dav/trunk/src/z3c/dav/tests/test_propfind.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/tests/test_propfind.py	2007-11-18 15:38:08 UTC (rev 81917)
+++ z3c.dav/trunk/src/z3c/dav/tests/test_propfind.py	2007-11-18 15:39:08 UTC (rev 81918)
@@ -100,6 +100,44 @@
 
         return propfind
 
+    def test_plaintext_body(self):
+        request = z3c.dav.publisher.WebDAVRequest(
+            StringIO("some text"), environ = {"CONTENT_TYPE": "text/plain",
+                                              "CONTENT_LENGTH": 9})
+        request.processInputs()
+
+        propfind = PROPFINDBodyParsed(None, request)
+        self.assertRaises(z3c.dav.interfaces.BadRequest, propfind.PROPFIND)
+
+    def test_plaintext_body_strlength(self):
+        request = z3c.dav.publisher.WebDAVRequest(
+            StringIO("some text"), environ = {"CONTENT_TYPE": "text/plain",
+                                              "CONTENT_LENGTH": "9"})
+        request.processInputs()
+
+        propfind = PROPFINDBodyParsed(None, request)
+        self.assertRaises(z3c.dav.interfaces.BadRequest, propfind.PROPFIND)
+
+    def test_nobody_nolength(self):
+        # Need to test that no BadRequest is raised by the PROPFIND method
+        request = z3c.dav.publisher.WebDAVRequest(StringIO(""), environ = {})
+        request.processInputs()
+
+        self.assertEqual(
+            request.getHeader("content-length", "missing"), "missing")
+
+        propfind = PROPFINDBodyParsed(None, request)
+        result = propfind.PROPFIND()
+
+    def test_nobody_length_0(self):
+        # Need to test that no BadRequest is raised by the PROPFIND method
+        request = z3c.dav.publisher.WebDAVRequest(
+            StringIO(""), environ = {"CONTENT_LENGTH": "0"})
+        request.processInputs()
+
+        propfind = PROPFINDBodyParsed(None, request)
+        result = propfind.PROPFIND()
+
     def test_notxml(self):
         self.assertRaises(z3c.dav.interfaces.BadRequest, self.checkPropfind,
             "<propname />", {"CONTENT_TYPE": "text/plain"})



More information about the Checkins mailing list