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

This commit is contained in:
Victor Rodionov 2012-10-28 17:27:15 +04:00
parent 7eb4025eb7
commit fc578ec377
3 changed files with 13 additions and 6 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.egg-info *.egg-info
*.py[co] *.py[co]
.DS_Store .DS_Store
.idea

View File

@ -506,9 +506,9 @@ class BucketController(WSGIContext):
try: try:
content_length = int(content_length) content_length = int(content_length)
except (ValueError, TypeError): except (ValueError, TypeError):
get_err_response('InvalidArgument') return get_err_response('InvalidArgument')
if content_length < 0: if content_length < 0:
get_err_response('InvalidArgument') return get_err_response('InvalidArgument')
if 'QUERY_STRING' in env: if 'QUERY_STRING' in env:
args = dict(urlparse.parse_qsl(env['QUERY_STRING'], 1)) args = dict(urlparse.parse_qsl(env['QUERY_STRING'], 1))

View File

@ -201,11 +201,11 @@ class TestSwift3(unittest.TestCase):
code = dom.getElementsByTagName('Code')[0].childNodes[0].nodeValue code = dom.getElementsByTagName('Code')[0].childNodes[0].nodeValue
self.assertEquals(code, 'InvalidURI') 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)) local_app = swift3.filter_factory({})(cl(status))
req = Request.blank(path, headers.update({'Authorization': 'AWS test:tester:hmac'})
environ={'REQUEST_METHOD': method}, req = Request.blank(path, environ={'REQUEST_METHOD': method},
headers={'Authorization': 'AWS test:tester:hmac'}) headers=headers)
resp = local_app(req.environ, start_response) resp = local_app(req.environ, start_response)
dom = xml.dom.minidom.parseString("".join(resp)) dom = xml.dom.minidom.parseString("".join(resp))
self.assertEquals(dom.firstChild.nodeName, 'Error') self.assertEquals(dom.firstChild.nodeName, 'Error')
@ -358,6 +358,12 @@ class TestSwift3(unittest.TestCase):
self.assertEquals(args['prefix'], 'c') self.assertEquals(args['prefix'], 'c')
def test_bucket_PUT_error(self): 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) code = self._test_method_error(FakeAppBucket, 'PUT', '/bucket', 401)
self.assertEquals(code, 'AccessDenied') self.assertEquals(code, 'AccessDenied')
code = self._test_method_error(FakeAppBucket, 'PUT', '/bucket', 202) code = self._test_method_error(FakeAppBucket, 'PUT', '/bucket', 202)