@@ -363,4 +363,62 @@ describe('Cloud Code Multipart', () => {
363363 expect ( result . status ) . toBe ( 200 ) ;
364364 expect ( result . data . result . isMaster ) . toBe ( false ) ;
365365 } ) ;
366+
367+ it ( 'should reject multipart request with many empty parts whose wire size exceeds maxUploadSize' , async ( ) => {
368+ await reconfigureServer ( { maxUploadSize : '1kb' } ) ;
369+
370+ Parse . Cloud . define ( 'multipartManyEmptyParts' , req => {
371+ return { count : Object . keys ( req . params ) . length } ;
372+ } ) ;
373+
374+ const boundary = '----TestBoundaryManyEmptyParts' ;
375+ const parts = [ ] ;
376+ for ( let i = 0 ; i < 2000 ; i ++ ) {
377+ parts . push ( { name : `f${ i } ` , value : '' } ) ;
378+ }
379+ const body = buildMultipartBody ( boundary , parts ) ;
380+ // The wire body is far larger than maxUploadSize even though every field
381+ // value is empty, so the value/chunk byte counters alone never trip.
382+ expect ( body . length ) . toBeGreaterThan ( 100 * 1024 ) ;
383+
384+ const result = await postMultipart (
385+ `http://localhost:8378/1/functions/multipartManyEmptyParts` ,
386+ {
387+ 'Content-Type' : `multipart/form-data; boundary=${ boundary } ` ,
388+ 'X-Parse-Application-Id' : 'test' ,
389+ 'X-Parse-REST-API-Key' : 'rest' ,
390+ } ,
391+ body
392+ ) ;
393+
394+ expect ( result . data . code ) . toBe ( Parse . Error . OBJECT_TOO_LARGE ) ;
395+ } ) ;
396+
397+ it ( 'should reject multipart request whose Content-Length exceeds maxUploadSize' , async ( ) => {
398+ await reconfigureServer ( { maxUploadSize : '1kb' } ) ;
399+
400+ Parse . Cloud . define ( 'multipartContentLength' , req => {
401+ return { count : Object . keys ( req . params ) . length } ;
402+ } ) ;
403+
404+ const boundary = '----TestBoundaryContentLength' ;
405+ const parts = [ ] ;
406+ for ( let i = 0 ; i < 2000 ; i ++ ) {
407+ parts . push ( { name : `f${ i } ` , value : '' } ) ;
408+ }
409+ const body = buildMultipartBody ( boundary , parts ) ;
410+
411+ const result = await postMultipart (
412+ `http://localhost:8378/1/functions/multipartContentLength` ,
413+ {
414+ 'Content-Type' : `multipart/form-data; boundary=${ boundary } ` ,
415+ 'Content-Length' : String ( body . length ) ,
416+ 'X-Parse-Application-Id' : 'test' ,
417+ 'X-Parse-REST-API-Key' : 'rest' ,
418+ } ,
419+ body
420+ ) ;
421+
422+ expect ( result . data . code ) . toBe ( Parse . Error . OBJECT_TOO_LARGE ) ;
423+ } ) ;
366424} ) ;
0 commit comments