@@ -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 \n Host: 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 \n Host: 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 \n Host: localhost:%d\r \n '
337+ b'Transfer-Encoding: chunked\r \n \r \n 1\r \n A\r X' % 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 \n Host: localhost:%d\r \n '
350+ b'Transfer-Encoding: chunked\r \n \r \n 0;\r \n \r X' % 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 \n Content-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