Skip to content

Commit 539608d

Browse files
committed
test(middleware-flexible-checksums): type fix
1 parent 43092fd commit 539608d

File tree

1 file changed

+44
-32
lines changed

1 file changed

+44
-32
lines changed

packages/middleware-flexible-checksums/src/middleware-md5-fallback.e2e.spec.ts

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
// see supplemental-docs/MD5_FALLBACK for more details
1+
// packages/middleware-flexible-checksums/src/middleware-md5-fallback.e2e.spec.ts
22
import {
33
CreateBucketCommand,
44
DeleteBucketCommand,
55
DeleteObjectsCommand,
66
PutObjectCommand,
77
S3,
8+
ServiceInputTypes,
9+
ServiceOutputTypes,
810
} from "@aws-sdk/client-s3";
11+
import type {
12+
FinalizeHandler,
13+
FinalizeHandlerArguments,
14+
FinalizeHandlerOutput,
15+
HandlerExecutionContext,
16+
HttpRequest,
17+
} from "@smithy/types";
918
import { createHash } from "crypto";
1019
import { afterAll, beforeAll, describe, expect, test as it } from "vitest";
1120

@@ -73,38 +82,41 @@ describe("S3 MD5 Fallback for DeleteObjects", () => {
7382
let crc32Removed = false;
7483

7584
md5S3Client.middlewareStack.add(
76-
(next, context) => async (args) => {
77-
// Check if this is a DeleteObjects command
78-
const isDeleteObjects = context.commandName === "DeleteObjectsCommand";
79-
80-
if (!isDeleteObjects) {
81-
return next(args);
82-
}
83-
84-
const result = await next(args);
85-
const headers = args.request.headers;
86-
87-
// Remove checksum headers
88-
Object.keys(headers).forEach((header) => {
89-
if (
90-
header.toLowerCase().startsWith("x-amz-checksum-") ||
91-
header.toLowerCase().startsWith("x-amz-sdk-checksum-")
92-
) {
93-
delete headers[header];
94-
crc32Removed = true;
85+
(next: FinalizeHandler<ServiceInputTypes, ServiceOutputTypes>, context: HandlerExecutionContext) =>
86+
async (
87+
args: FinalizeHandlerArguments<ServiceInputTypes>
88+
): Promise<FinalizeHandlerOutput<ServiceOutputTypes>> => {
89+
const request = args.request as HttpRequest;
90+
const isDeleteObjects = context.commandName === "DeleteObjectsCommand";
91+
92+
if (!isDeleteObjects) {
93+
return next(args);
9594
}
96-
});
97-
98-
// Add MD5
99-
if (args.request.body) {
100-
const bodyContent = Buffer.from(args.request.body);
101-
const md5Hash = createHash("md5").update(bodyContent).digest("base64");
102-
headers["Content-MD5"] = md5Hash;
103-
md5Added = true;
104-
}
105-
106-
return result;
107-
},
95+
96+
const result = await next(args);
97+
const headers = request.headers;
98+
99+
// Remove checksum headers
100+
Object.keys(headers).forEach((header) => {
101+
if (
102+
header.toLowerCase().startsWith("x-amz-checksum-") ||
103+
header.toLowerCase().startsWith("x-amz-sdk-checksum-")
104+
) {
105+
delete headers[header];
106+
crc32Removed = true;
107+
}
108+
});
109+
110+
// Add MD5
111+
if (request.body) {
112+
const bodyContent = Buffer.from(request.body);
113+
const md5Hash = createHash("md5").update(bodyContent).digest("base64");
114+
headers["Content-MD5"] = md5Hash;
115+
md5Added = true;
116+
}
117+
118+
return result;
119+
},
108120
{
109121
step: "finalizeRequest",
110122
name: "addMD5Checksum",

0 commit comments

Comments
 (0)