@@ -640,9 +640,7 @@ def test_max_files_is_customizable_low_raises(
640640 assert res .text == "Too many files. Maximum number of files is 1."
641641
642642
643- def test_max_fields_is_customizable_high (
644- test_client_factory : TestClientFactory ,
645- ) -> None :
643+ def test_max_fields_is_customizable_high (test_client_factory : TestClientFactory ) -> None :
646644 client = test_client_factory (make_app_max_parts (max_fields = 2000 , max_files = 2000 ))
647645 fields = []
648646 for i in range (2000 ):
@@ -664,3 +662,40 @@ def test_max_fields_is_customizable_high(
664662 "content" : "" ,
665663 "content_type" : None ,
666664 }
665+
666+
667+ @pytest .mark .parametrize (
668+ "app,expectation" ,
669+ [
670+ (app , pytest .raises (MultiPartException )),
671+ (Starlette (routes = [Mount ("/" , app = app )]), does_not_raise ()),
672+ ],
673+ )
674+ def test_max_part_size_exceeds_limit (
675+ app : ASGIApp ,
676+ expectation : typing .ContextManager [Exception ],
677+ test_client_factory : TestClientFactory ,
678+ ) -> None :
679+ client = test_client_factory (app )
680+ boundary = "------------------------4K1ON9fZkj9uCUmqLHRbbR"
681+
682+ multipart_data = (
683+ f"--{ boundary } \r \n "
684+ f'Content-Disposition: form-data; name="small"\r \n \r \n '
685+ "small content\r \n "
686+ f"--{ boundary } \r \n "
687+ f'Content-Disposition: form-data; name="large"\r \n \r \n '
688+ + ("x" * 1024 * 1024 + "x" ) # 1MB + 1 byte of data
689+ + "\r \n "
690+ f"--{ boundary } --\r \n "
691+ ).encode ("utf-8" )
692+
693+ headers = {
694+ "Content-Type" : f"multipart/form-data; boundary={ boundary } " ,
695+ "Transfer-Encoding" : "chunked" ,
696+ }
697+
698+ with expectation :
699+ response = client .post ("/" , data = multipart_data , headers = headers ) # type: ignore
700+ assert response .status_code == 400
701+ assert response .text == "Part exceeded maximum size of 1024KB."
0 commit comments