File tree Expand file tree Collapse file tree 3 files changed +44
-7
lines changed Expand file tree Collapse file tree 3 files changed +44
-7
lines changed Original file line number Diff line number Diff line change @@ -825,7 +825,7 @@ describe(Upload.name, () => {
825825
826826 expect ( ( ) => {
827827 ( upload as any ) . __validateUploadPart ( invalidPart , MOCK_PART_SIZE ) ;
828- } ) . toThrow ( `The Part size for part number 1, size 5 does not match expected size ${ MOCK_PART_SIZE } ` ) ;
828+ } ) . toThrow ( `The byte size for part number 1, size 5 does not match expected size ${ MOCK_PART_SIZE } ` ) ;
829829 } ) ;
830830
831831 it ( "should allow smaller size for last part" , ( ) => {
Original file line number Diff line number Diff line change @@ -440,21 +440,21 @@ export class Upload extends EventEmitter {
440440 private __validateUploadPart ( dataPart : RawDataPart ) : void {
441441 const actualPartSize = byteLength ( dataPart . data ) || undefined ;
442442
443- // Skip validation for single-part uploads (PUT operations)
444- if ( dataPart . partNumber === 1 && dataPart . lastPart ) {
445- return ;
446- }
447-
448443 if ( actualPartSize === undefined ) {
449444 throw new Error (
450445 `A dataPart was generated without a measurable data chunk size for part number ${ dataPart . partNumber } `
451446 ) ;
452447 }
453448
449+ // Skip validation for single-part uploads (PUT operations)
450+ if ( dataPart . partNumber === 1 && dataPart . lastPart ) {
451+ return ;
452+ }
453+
454454 // Validate part size (last part may be smaller)
455455 if ( ! dataPart . lastPart && actualPartSize !== this . partSize ) {
456456 throw new Error (
457- `The Part size for part number ${ dataPart . partNumber } , size ${ actualPartSize } does not match expected size ${ this . partSize } `
457+ `The byte size for part number ${ dataPart . partNumber } , size ${ actualPartSize } does not match expected size ${ this . partSize } `
458458 ) ;
459459 }
460460 }
Original file line number Diff line number Diff line change @@ -139,6 +139,43 @@ describe("@aws-sdk/lib-storage", () => {
139139 "S3Client AbortMultipartUploadCommand 204" ,
140140 ] ) ;
141141 } ) ;
142+
143+ it ( "should validate part size constraints" , ( ) => {
144+ const upload = new Upload ( {
145+ client,
146+ params : {
147+ Bucket,
148+ Key : `validation-test-${ Date . now ( ) } ` ,
149+ Body : Buffer . alloc ( 1024 * 1024 * 10 ) ,
150+ } ,
151+ } ) ;
152+
153+ const invalidPart = {
154+ partNumber : 2 ,
155+ data : Buffer . alloc ( 1024 * 1024 * 3 ) , // 3MB - too small for non-final part
156+ lastPart : false ,
157+ } ;
158+
159+ expect ( ( ) => {
160+ ( upload as any ) . __validateUploadPart ( invalidPart ) ;
161+ } ) . toThrow ( / T h e b y t e s i z e f o r p a r t n u m b e r 2 , s i z e \d + d o e s n o t m a t c h e x p e c t e d s i z e \d + / ) ;
162+ } ) ;
163+
164+ it ( "should validate part count constraints" , async ( ) => {
165+ const upload = new Upload ( {
166+ client,
167+ params : {
168+ Bucket,
169+ Key : `validation-test-${ Date . now ( ) } ` ,
170+ Body : Buffer . alloc ( 1024 * 1024 * 10 ) ,
171+ } ,
172+ } ) ;
173+
174+ ( upload as any ) . uploadedParts = [ { PartNumber : 1 , ETag : "etag1" } ] ;
175+ ( upload as any ) . isMultiPart = true ;
176+
177+ await expect ( upload . done ( ) ) . rejects . toThrow ( / E x p e c t e d \d + p a r t \( s \) b u t u p l o a d e d \d + p a r t \( s \) \. / ) ;
178+ } ) ;
142179 } ) ;
143180 }
144181 ) ;
You can’t perform that action at this time.
0 commit comments