Skip to content

Commit d4325dd

Browse files
committed
fix(lib-storage): add e2e test to trigger validation
1 parent 5d8903e commit d4325dd

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

lib/lib-storage/src/Upload.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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", () => {

lib/lib-storage/src/Upload.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff 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
}

lib/lib-storage/src/lib-storage.e2e.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff 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(/The byte size for part number 2, size \d+ does not match expected size \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(/Expected \d+ part\(s\) but uploaded \d+ part\(s\)\./);
178+
});
142179
});
143180
}
144181
);

0 commit comments

Comments
 (0)