diff options
| author | Standa Opichal <stanislav.opichal@rossum.ai> | 2023-11-10 17:40:24 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-11-24 12:06:54 +0100 |
| commit | 1c6e8ec4ed6d9c374161eda965160e4782c7d71e (patch) | |
| tree | 3a8b9d2ef22a94606d353455376be823919b17fa /tests/requests_tests/tests.py | |
| parent | 5e28cd3f2cfc31bf947a747256bc036f8f64888a (diff) | |
Fixed #34968 -- Made multipart parsing of headers raise an error on too long headers.
This also allow customizing the maximum size of headers via
MAX_TOTAL_HEADER_SIZE.
Diffstat (limited to 'tests/requests_tests/tests.py')
| -rw-r--r-- | tests/requests_tests/tests.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/tests/requests_tests/tests.py b/tests/requests_tests/tests.py index 228198ae8a..035552713c 100644 --- a/tests/requests_tests/tests.py +++ b/tests/requests_tests/tests.py @@ -11,7 +11,7 @@ from django.http import ( RawPostDataException, UnreadablePostError, ) -from django.http.multipartparser import MultiPartParserError +from django.http.multipartparser import MAX_TOTAL_HEADER_SIZE, MultiPartParserError from django.http.request import split_domain_port from django.test import RequestFactory, SimpleTestCase, override_settings from django.test.client import BOUNDARY, MULTIPART_CONTENT, FakePayload @@ -691,6 +691,31 @@ class RequestsTests(SimpleTestCase): with self.assertRaisesMessage(MultiPartParserError, msg): request.POST + def test_multipart_with_header_fields_too_large(self): + payload = FakePayload( + "\r\n".join( + [ + "--boundary", + 'Content-Disposition: form-data; name="name"', + "X-Long-Header: %s" % ("-" * (MAX_TOTAL_HEADER_SIZE + 1)), + "", + "value", + "--boundary--", + ] + ) + ) + request = WSGIRequest( + { + "REQUEST_METHOD": "POST", + "CONTENT_TYPE": "multipart/form-data; boundary=boundary", + "CONTENT_LENGTH": len(payload), + "wsgi.input": payload, + } + ) + msg = "Request max total header size exceeded." + with self.assertRaisesMessage(MultiPartParserError, msg): + request.POST + def test_POST_connection_error(self): """ If wsgi.input.read() raises an exception while trying to read() the |
