Skip to content

Commit cd52227

Browse files
committed
update tests
1 parent 04efb25 commit cd52227

2 files changed

Lines changed: 56 additions & 5 deletions

File tree

tests/http_server.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,12 @@ def upload(request, content_type=b'application/octet-stream', **server):
266266
size = int(request.query['size'][0])
267267
yield request.read(0) + request.read(size)
268268
except KeyError:
269+
body = bytearray()
270+
269271
for data in request.stream():
270-
yield data
272+
body.extend(data)
273+
274+
yield body
271275

272276
for data in request.stream():
273277
# should not raised

tests/test_http_server.py

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,57 @@ def test_post_upload2_ok_11(self):
304304
)
305305
self.assertEqual(read_chunked(body), create_dummy_body(65536))
306306

307+
def test_post_bad_chunked_encoding(self):
308+
header, body = getcontents(
309+
host=HTTP_HOST,
310+
port=HTTP_PORT + 2,
311+
raw=b'POST /upload HTTP/1.1\r\nHost: localhost:%d\r\n'
312+
b'Transfer-Encoding: chunked\r\n\r\n-1\r\n' % HTTP_PORT
313+
)
314+
315+
self.assertEqual(header[:header.find(b'\r\n')],
316+
b'HTTP/1.1 400 Bad Request')
317+
self.assertEqual(body, b'bad chunked encoding')
318+
319+
def test_post_no_chunk_size(self):
320+
header, body = getcontents(
321+
host=HTTP_HOST,
322+
port=HTTP_PORT + 2,
323+
raw=b'POST /upload HTTP/1.1\r\nHost: localhost:%d\r\n'
324+
b'Transfer-Encoding: chunked\r\n\r\n%s' %
325+
(HTTP_PORT, b'X' * 65)
326+
)
327+
328+
self.assertEqual(header[:header.find(b'\r\n')],
329+
b'HTTP/1.1 400 Bad Request')
330+
self.assertEqual(body, b'bad chunked encoding: no chunk size')
331+
332+
def test_post_invalid_chunk_terminator(self):
333+
header, body = getcontents(
334+
host=HTTP_HOST,
335+
port=HTTP_PORT + 2,
336+
raw=b'POST /upload HTTP/1.1\r\nHost: localhost:%d\r\n'
337+
b'Transfer-Encoding: chunked\r\n\r\n1\r\nA\rX' % HTTP_PORT
338+
)
339+
340+
self.assertEqual(header[:header.find(b'\r\n')],
341+
b'HTTP/1.1 400 Bad Request')
342+
self.assertEqual(body,
343+
b'bad chunked encoding: invalid chunk terminator')
344+
345+
def test_post_invalid_chunk_end(self):
346+
header, body = getcontents(
347+
host=HTTP_HOST,
348+
port=HTTP_PORT + 2,
349+
raw=b'POST /upload HTTP/1.1\r\nHost: localhost:%d\r\n'
350+
b'Transfer-Encoding: chunked\r\n\r\n0;\r\n\rX' % HTTP_PORT
351+
)
352+
353+
self.assertEqual(header[:header.find(b'\r\n')],
354+
b'HTTP/1.1 400 Bad Request')
355+
self.assertEqual(body,
356+
b'bad chunked encoding: invalid chunk terminator')
357+
307358
def test_post_upload_maxqueue(self):
308359
header, body = getcontents(
309360
host=HTTP_HOST,
@@ -396,10 +447,6 @@ def test_post_upload_payloadtoolarge_11(self):
396447
self.assertTrue(
397448
b'\r\nContent-Type: application/octet-stream' in header
398449
)
399-
self.assertEqual(
400-
read_chunked(body) if chunked_detected(header) else body,
401-
False
402-
)
403450

404451
def test_payloadtoolarge(self):
405452
header, body = getcontents(

0 commit comments

Comments
 (0)