From 960f01b4ba502c01f3433abe37fa95b1e60450f4 Mon Sep 17 00:00:00 2001 From: Peter Portante Date: Fri, 19 Apr 2013 00:10:38 -0400 Subject: [PATCH] Add an explicit unit test for handling content-length: 0 Change-Id: I3568d4dc1900e6ddb4860589ca6a7b7039cc8c2d Signed-off-by: Peter Portante --- test/unit/obj/test_server.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/unit/obj/test_server.py b/test/unit/obj/test_server.py index 7c924198cd..3ba8d02b69 100755 --- a/test/unit/obj/test_server.py +++ b/test/unit/obj/test_server.py @@ -661,6 +661,24 @@ class TestObjectController(unittest.TestCase): resp = self.object_controller.PUT(req) self.assertEquals(resp.status_int, 411) + def test_PUT_zero_content_length(self): + req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, + headers={'X-Timestamp': normalize_timestamp(time()), + 'Content-Type': 'application/octet-stream'}) + req.body = '' + self.assertEquals(req.headers['Content-Length'], '0') + resp = self.object_controller.PUT(req) + self.assertEquals(resp.status_int, 201) + + def test_PUT_zero_content_length_mismatched(self): + req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, + headers={'X-Timestamp': normalize_timestamp(time()), + 'Content-Type': 'application/octet-stream'}) + req.body = 'VERIFY' + req.headers['Content-Length'] = '0' + resp = self.object_controller.PUT(req) + self.assertEquals(resp.status_int, 499) + def test_PUT_common(self): timestamp = normalize_timestamp(time()) req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},