From fc578ec3777333f056f38725620ca28e96cda2fc Mon Sep 17 00:00:00 2001 From: Victor Rodionov Date: Sun, 28 Oct 2012 17:27:15 +0400 Subject: [PATCH] BucketController.PUT don't return error response if CONTENT_LENGTH is invalid --- .gitignore | 1 + swift3/middleware.py | 4 ++-- swift3/test/unit/test_swift3.py | 14 ++++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 0558c26b..8a07d5bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.egg-info *.py[co] .DS_Store +.idea diff --git a/swift3/middleware.py b/swift3/middleware.py index 129aa615..2fbba49d 100644 --- a/swift3/middleware.py +++ b/swift3/middleware.py @@ -506,9 +506,9 @@ class BucketController(WSGIContext): try: content_length = int(content_length) except (ValueError, TypeError): - get_err_response('InvalidArgument') + return get_err_response('InvalidArgument') if content_length < 0: - get_err_response('InvalidArgument') + return get_err_response('InvalidArgument') if 'QUERY_STRING' in env: args = dict(urlparse.parse_qsl(env['QUERY_STRING'], 1)) diff --git a/swift3/test/unit/test_swift3.py b/swift3/test/unit/test_swift3.py index 8e2646ba..9dc99acc 100644 --- a/swift3/test/unit/test_swift3.py +++ b/swift3/test/unit/test_swift3.py @@ -201,11 +201,11 @@ class TestSwift3(unittest.TestCase): code = dom.getElementsByTagName('Code')[0].childNodes[0].nodeValue self.assertEquals(code, 'InvalidURI') - def _test_method_error(self, cl, method, path, status): + def _test_method_error(self, cl, method, path, status, headers={}): local_app = swift3.filter_factory({})(cl(status)) - req = Request.blank(path, - environ={'REQUEST_METHOD': method}, - headers={'Authorization': 'AWS test:tester:hmac'}) + headers.update({'Authorization': 'AWS test:tester:hmac'}) + req = Request.blank(path, environ={'REQUEST_METHOD': method}, + headers=headers) resp = local_app(req.environ, start_response) dom = xml.dom.minidom.parseString("".join(resp)) self.assertEquals(dom.firstChild.nodeName, 'Error') @@ -358,6 +358,12 @@ class TestSwift3(unittest.TestCase): self.assertEquals(args['prefix'], 'c') def test_bucket_PUT_error(self): + code = self._test_method_error(FakeAppBucket, 'PUT', '/bucket', 201, + headers={'Content-Length': 'a'}) + self.assertEqual(code, 'InvalidArgument') + code = self._test_method_error(FakeAppBucket, 'PUT', '/bucket', 201, + headers={'Content-Length': '-1'}) + self.assertEqual(code, 'InvalidArgument') code = self._test_method_error(FakeAppBucket, 'PUT', '/bucket', 401) self.assertEquals(code, 'AccessDenied') code = self._test_method_error(FakeAppBucket, 'PUT', '/bucket', 202)