Fix 503 on account/container HEAD w/invalid format.
A HEAD request to /v1/a[/c]?format=%FF would result in a 503 since there was an unhandled UnicodeDecodeError. Now it doesn't. bug 1190395 Change-Id: I4d8ec677092617391fe154a25f22d919536a72a5
This commit is contained in:
parent
1384171613
commit
aff39d75bb
@ -167,9 +167,14 @@ class AccountController(object):
|
||||
except ValueError, err:
|
||||
return HTTPBadRequest(body=str(err), content_type='text/plain',
|
||||
request=req)
|
||||
if get_param(req, 'format'):
|
||||
try:
|
||||
query_format = get_param(req, 'format')
|
||||
except UnicodeDecodeError:
|
||||
return HTTPBadRequest(body='parameters not utf8',
|
||||
content_type='text/plain', request=req)
|
||||
if query_format:
|
||||
req.accept = FORMAT2CONTENT_TYPE.get(
|
||||
get_param(req, 'format').lower(), FORMAT2CONTENT_TYPE['plain'])
|
||||
query_format.lower(), FORMAT2CONTENT_TYPE['plain'])
|
||||
out_content_type = req.accept.best_match(
|
||||
['text/plain', 'application/json', 'application/xml', 'text/xml'])
|
||||
if not out_content_type:
|
||||
|
@ -303,9 +303,14 @@ class ContainerController(object):
|
||||
except ValueError, err:
|
||||
return HTTPBadRequest(body=str(err), content_type='text/plain',
|
||||
request=req)
|
||||
if get_param(req, 'format'):
|
||||
try:
|
||||
query_format = get_param(req, 'format')
|
||||
except UnicodeDecodeError:
|
||||
return HTTPBadRequest(body='parameters not utf8',
|
||||
content_type='text/plain', request=req)
|
||||
if query_format:
|
||||
req.accept = FORMAT2CONTENT_TYPE.get(
|
||||
get_param(req, 'format').lower(), FORMAT2CONTENT_TYPE['plain'])
|
||||
query_format.lower(), FORMAT2CONTENT_TYPE['plain'])
|
||||
out_content_type = req.accept.best_match(
|
||||
['text/plain', 'application/json', 'application/xml', 'text/xml'])
|
||||
if not out_content_type:
|
||||
|
@ -203,6 +203,13 @@ class TestAccountController(unittest.TestCase):
|
||||
resp = self.controller.HEAD(req)
|
||||
self.assertEquals(resp.status_int, 507)
|
||||
|
||||
def test_HEAD_invalid_format(self):
|
||||
format = '%D1%BD%8A9' # invalid UTF-8; should be %E1%BD%8A9 (E -> D)
|
||||
req = Request.blank('/sda1/p/a?format=' + format,
|
||||
environ={'REQUEST_METHOD': 'HEAD'})
|
||||
resp = self.controller.HEAD(req)
|
||||
self.assertEquals(resp.status_int, 400)
|
||||
|
||||
def test_PUT_not_found(self):
|
||||
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'PUT'},
|
||||
headers={'X-PUT-Timestamp': normalize_timestamp(1),
|
||||
|
@ -143,6 +143,13 @@ class TestContainerController(unittest.TestCase):
|
||||
resp = self.controller.HEAD(req)
|
||||
self.assertEquals(resp.status_int, 406)
|
||||
|
||||
def test_HEAD_invalid_format(self):
|
||||
format = '%D1%BD%8A9' # invalid UTF-8; should be %E1%BD%8A9 (E -> D)
|
||||
req = Request.blank('/sda1/p/a/c?format=' + format,
|
||||
environ={'REQUEST_METHOD': 'HEAD'})
|
||||
resp = self.controller.HEAD(req)
|
||||
self.assertEquals(resp.status_int, 400)
|
||||
|
||||
def test_PUT(self):
|
||||
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'PUT',
|
||||
'HTTP_X_TIMESTAMP': '1'})
|
||||
|
Loading…
x
Reference in New Issue
Block a user