Permalink
Browse files

BucketController.PUT don't return error response if CONTENT_LENGTH is…

… invalid
  • Loading branch information...
1 parent 7eb4025 commit fc578ec3777333f056f38725620ca28e96cda2fc @vitoordaz vitoordaz committed Oct 28, 2012
Showing with 13 additions and 6 deletions.
  1. +1 −0 .gitignore
  2. +2 −2 swift3/middleware.py
  3. +10 −4 swift3/test/unit/test_swift3.py
View
@@ -1,3 +1,4 @@
*.egg-info
*.py[co]
.DS_Store
+.idea
View
@@ -506,9 +506,9 @@ def PUT(self, env, start_response):
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))
@@ -201,11 +201,11 @@ def test_bad_method(self):
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 @@ def __call__(self, env, start_response):
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)

0 comments on commit fc578ec

Please sign in to comment.