|
1 |
| -// see supplemental-docs/MD5_FALLBACK for more details |
| 1 | +// packages/middleware-flexible-checksums/src/middleware-md5-fallback.e2e.spec.ts |
2 | 2 | import {
|
3 | 3 | CreateBucketCommand,
|
4 | 4 | DeleteBucketCommand,
|
5 | 5 | DeleteObjectsCommand,
|
6 | 6 | PutObjectCommand,
|
7 | 7 | S3,
|
| 8 | + ServiceInputTypes, |
| 9 | + ServiceOutputTypes, |
8 | 10 | } from "@aws-sdk/client-s3";
|
| 11 | +import type { |
| 12 | + FinalizeHandler, |
| 13 | + FinalizeHandlerArguments, |
| 14 | + FinalizeHandlerOutput, |
| 15 | + HandlerExecutionContext, |
| 16 | + HttpRequest, |
| 17 | +} from "@smithy/types"; |
9 | 18 | import { createHash } from "crypto";
|
10 | 19 | import { afterAll, beforeAll, describe, expect, test as it } from "vitest";
|
11 | 20 |
|
@@ -73,38 +82,41 @@ describe("S3 MD5 Fallback for DeleteObjects", () => {
|
73 | 82 | let crc32Removed = false;
|
74 | 83 |
|
75 | 84 | 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); |
95 | 94 | }
|
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 | + }, |
108 | 120 | {
|
109 | 121 | step: "finalizeRequest",
|
110 | 122 | name: "addMD5Checksum",
|
|
0 commit comments