mirror of
https://github.com/django/django.git
synced 2025-01-03 06:55:47 +00:00
Added MultiPartParser tests for parsing base64-encoded fields.
This commit is contained in:
parent
094b0bea2c
commit
7cc138a58f
@ -14,7 +14,7 @@ from django.http import (
|
|||||||
from django.http.multipartparser import MultiPartParserError
|
from django.http.multipartparser import MultiPartParserError
|
||||||
from django.http.request import split_domain_port
|
from django.http.request import split_domain_port
|
||||||
from django.test import RequestFactory, SimpleTestCase, override_settings
|
from django.test import RequestFactory, SimpleTestCase, override_settings
|
||||||
from django.test.client import FakePayload
|
from django.test.client import BOUNDARY, MULTIPART_CONTENT, FakePayload
|
||||||
|
|
||||||
|
|
||||||
class RequestsTests(SimpleTestCase):
|
class RequestsTests(SimpleTestCase):
|
||||||
@ -537,6 +537,56 @@ class RequestsTests(SimpleTestCase):
|
|||||||
self.assertEqual(request.read(1), b"n")
|
self.assertEqual(request.read(1), b"n")
|
||||||
self.assertEqual(request.POST, {"name": ["value"]})
|
self.assertEqual(request.POST, {"name": ["value"]})
|
||||||
|
|
||||||
|
def test_multipart_post_field_with_base64(self):
|
||||||
|
payload = FakePayload(
|
||||||
|
"\r\n".join(
|
||||||
|
[
|
||||||
|
f"--{BOUNDARY}",
|
||||||
|
'Content-Disposition: form-data; name="name"',
|
||||||
|
"Content-Transfer-Encoding: base64",
|
||||||
|
"",
|
||||||
|
"dmFsdWU=",
|
||||||
|
f"--{BOUNDARY}--",
|
||||||
|
"",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
request = WSGIRequest(
|
||||||
|
{
|
||||||
|
"REQUEST_METHOD": "POST",
|
||||||
|
"CONTENT_TYPE": MULTIPART_CONTENT,
|
||||||
|
"CONTENT_LENGTH": len(payload),
|
||||||
|
"wsgi.input": payload,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
request.body # evaluate
|
||||||
|
self.assertEqual(request.POST, {"name": ["value"]})
|
||||||
|
|
||||||
|
def test_multipart_post_field_with_invalid_base64(self):
|
||||||
|
payload = FakePayload(
|
||||||
|
"\r\n".join(
|
||||||
|
[
|
||||||
|
f"--{BOUNDARY}",
|
||||||
|
'Content-Disposition: form-data; name="name"',
|
||||||
|
"Content-Transfer-Encoding: base64",
|
||||||
|
"",
|
||||||
|
"123",
|
||||||
|
f"--{BOUNDARY}--",
|
||||||
|
"",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
request = WSGIRequest(
|
||||||
|
{
|
||||||
|
"REQUEST_METHOD": "POST",
|
||||||
|
"CONTENT_TYPE": MULTIPART_CONTENT,
|
||||||
|
"CONTENT_LENGTH": len(payload),
|
||||||
|
"wsgi.input": payload,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
request.body # evaluate
|
||||||
|
self.assertEqual(request.POST, {"name": ["123"]})
|
||||||
|
|
||||||
def test_POST_after_body_read_and_stream_read_multipart(self):
|
def test_POST_after_body_read_and_stream_read_multipart(self):
|
||||||
"""
|
"""
|
||||||
POST should be populated even if body is read first, and then
|
POST should be populated even if body is read first, and then
|
||||||
|
Loading…
Reference in New Issue
Block a user