Repository: django/django
File: tests/requests_tests/tests.py (Python)

Code before:
                return post, files

        class CustomWSGIRequest(WSGIRequest):
            multipart_parser_class = CustomMultiPartParser

        payload = FakePayload(
            "\r\n".join(
                [
                    "--boundary",
                    'Content-Disposition: form-data; name="name"',
                    "",
                    "value",
                    "--boundary--",
                ]
            )
        )
        request = CustomWSGIRequest(
            {
                "REQUEST_METHOD": "POST",
                "CONTENT_TYPE": "multipart/form-data; boundary=boundary",
                "CONTENT_LENGTH": len(payload),
                "wsgi.input": payload,
            }
        )

        # This assertion would FAIL without the _multipart_parser_class change
        # because the hardcoded MultiPartParser would be used instead.
        self.assertEqual(request.POST.get("custom_parser_used"), "yes")
        self.assertEqual(request.POST.get("name"), "value")


class HostValidationTests(SimpleTestCase):
    poisoned_hosts = [
        "example.com@evil.tld",
        "example.com:dr.frankenstein@evil.tld",
        "example.com:dr.frankenstein@evil.tld:80",
        "example.com:80/badpath",
        "example.com: recovermypassword.com",
    ]

    @override_settings(
        USE_X_FORWARDED_HOST=False,
        ALLOWED_HOSTS=[
            "forward.com",
            "example.com",
            "internal.com",
            "12.34.56.78",
            "[2001:19f0:feee::dead:beef:cafe]",
            "xn--4ca9at.com",
            ".multitenant.com",
            "INSENSITIVE.com",

Review comment (bug):
```suggestion
        # This assertion would FAIL without the multipart_parser_class change
```

Code after:
                return post, files

        class CustomWSGIRequest(WSGIRequest):
            multipart_parser_class = CustomMultiPartParser

        payload = FakePayload(
            "\r\n".join(
                [
                    "--boundary",
                    'Content-Disposition: form-data; name="name"',
                    "",
                    "value",
                    "--boundary--",
                ]
            )
        )
        request = CustomWSGIRequest(
            {
                "REQUEST_METHOD": "POST",
                "CONTENT_TYPE": "multipart/form-data; boundary=boundary",
                "CONTENT_LENGTH": len(payload),
                "wsgi.input": payload,
            }
        )
        self.assertEqual(request.POST.get("custom_parser_used"), "yes")
        self.assertEqual(request.POST.get("name"), "value")

    def test_multipart_parser_class_immutable_after_parse(self):
        payload = FakePayload(
            "\r\n".join(
                [
                    "--boundary",
                    'Content-Disposition: form-data; name="name"',
                    "",
                    "value",
                    "--boundary--",
                ]
            )
        )
        request = WSGIRequest(
            {
                "REQUEST_METHOD": "POST",
                "CONTENT_TYPE": "multipart/form-data; boundary=boundary",
                "CONTENT_LENGTH": len(payload),
                "wsgi.input": payload,
            }
        )

        # Access POST to trigger parsing.
        request.POST