Commit 98600e06 authored by Jérome Perrin's avatar Jérome Perrin

Fix handling of wsgi.input

wsgi.input is a binary file on python 3.
parent 9a152138
......@@ -1822,7 +1822,7 @@ class CaucaseTest(unittest.TestCase):
self.assertEqual(request({
'PATH_INFO': '/cau/csr',
'REQUEST_METHOD': 'PUT',
'wsgi.input': StringIO(),
'wsgi.input': BytesIO(),
})[0], 500)
self.assertEqual(request({
'PATH_INFO': '/cau/csr',
......@@ -1859,50 +1859,50 @@ class CaucaseTest(unittest.TestCase):
'REQUEST_METHOD': 'PUT',
'CONTENT_TYPE': 'application/json',
'CONTENT_LENGTH': 'a',
'wsgi.input': StringIO(),
'wsgi.input': BytesIO(),
})[0], 400)
self.assertEqual(request({
'PATH_INFO': '/cau/crt/renew',
'REQUEST_METHOD': 'PUT',
'CONTENT_TYPE': 'application/json',
'CONTENT_LENGTH': str(wsgi.MAX_BODY_LENGTH + 1),
'wsgi.input': StringIO(),
'wsgi.input': BytesIO(),
})[0], 413)
self.assertEqual(request({
'PATH_INFO': '/cau/crt/renew',
'REQUEST_METHOD': 'PUT',
'CONTENT_TYPE': 'application/json',
'wsgi.input': StringIO(u'{'),
'wsgi.input': BytesIO(b'{'),
})[0], 400)
self.assertEqual(request({
'PATH_INFO': '/cau/crt/revoke',
'REQUEST_METHOD': 'PUT',
'CONTENT_TYPE': 'application/json',
'wsgi.input': StringIO(u'{"digest": null}'),
'wsgi.input': BytesIO(b'{"digest": null}'),
})[0], UNAUTHORISED_STATUS)
self.assertEqual(request({
'PATH_INFO': '/cau/crt/revoke',
'REQUEST_METHOD': 'PUT',
'CONTENT_TYPE': 'application/json',
'wsgi.input': StringIO(u'{"digest":"sha256","payload":""}'),
'wsgi.input': BytesIO(b'{"digest":"sha256","payload":""}'),
})[0], 400)
self.assertEqual(request({
'PATH_INFO': '/cau/crt/a',
'REQUEST_METHOD': 'PUT',
'CONTENT_TYPE': 'text/plain',
'wsgi.input': StringIO(u''),
'wsgi.input': BytesIO(b''),
})[0], 400)
self.assertEqual(request({
'PATH_INFO': '/cau/crt/123',
'REQUEST_METHOD': 'PUT',
'CONTENT_TYPE': 'text/plain',
'wsgi.input': StringIO(u''),
'wsgi.input': BytesIO(b''),
})[0], UNAUTHORISED_STATUS)
self.assertEqual(request({
'PATH_INFO': '/cau/crt/123',
'REQUEST_METHOD': 'PUT',
'CONTENT_TYPE': 'text/plain',
'wsgi.input': StringIO(u'foo'),
'wsgi.input': BytesIO(b'foo'),
})[0], 400)
self.assertEqual(request({
'PATH_INFO': '/cau/crt/123',
......@@ -2087,7 +2087,7 @@ class CaucaseTest(unittest.TestCase):
'PATH_INFO': '/cors',
'REQUEST_METHOD': 'POST',
'CONTENT_TYPE': 'application/x-www-form-urlencoded',
'wsgi.input': StringIO(utils.toUnicode(urlencode(input_dict))),
'wsgi.input': BytesIO(utils.toBytes(urlencode(input_dict))),
}
base_request_reader_dict.update(kw)
return base_request_reader_dict
......
......@@ -918,7 +918,7 @@ class Application(object):
if environ.get('CONTENT_TYPE') != 'application/x-www-form-urlencoded':
raise BadRequest(b'Unhandled Content-Type')
try:
form_dict = parse_qs(self._read(environ), strict_parsing=True)
form_dict = parse_qs(self._read(environ).decode(), strict_parsing=True)
Please register or sign in to reply
origin, = form_dict['origin']
return_to, = form_dict['return_to']
grant, = form_dict['grant']
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment