Skip to content

Commit

Permalink
chore: skip checksums for x-amz-checksum-algorithm header
Browse files Browse the repository at this point in the history
This reverts commit 9204de2.
  • Loading branch information
trivikr committed Nov 13, 2024
1 parent 9204de2 commit c808a7a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,39 +174,6 @@ describe(flexibleChecksumsMiddleware.name, () => {
expect(stringHasher).toHaveBeenCalledWith(mockChecksumAlgorithmFunction, mockRequest.body);
expect(mockBase64Encoder).toHaveBeenCalledWith(mockRawChecksum);
});

it.each(["x-amz-checksum-algorithm", "X-AMZ-CHECKSUM-ALGORITHM"])(
"even if '%s' header is present",
async (headerName) => {
const mockRawChecksum = Buffer.from(mockChecksum);
const mockBase64Encoder = vi.fn().mockReturnValue(mockChecksum);
vi.mocked(stringHasher).mockResolvedValue(mockRawChecksum);
vi.mocked(hasHeader).mockReturnValue(false);

const handler = flexibleChecksumsMiddleware(
{ ...mockConfig, base64Encoder: mockBase64Encoder },
mockMiddlewareConfig
)(mockNext, {});
const mockHeadersWithAlgoHeader = { ...mockHeaders, [headerName]: "mockHeaderValue" };
const mockArgsWithAlgoHeader = {
...mockArgs,
request: { ...mockRequest, headers: mockHeadersWithAlgoHeader },
};
await handler(mockArgsWithAlgoHeader);

expect(hasHeader).toHaveBeenCalledTimes(1);
expect(mockNext).toHaveBeenCalledWith({
...mockArgs,
request: {
...mockRequest,
headers: { ...mockHeadersWithAlgoHeader, [mockChecksumLocationName]: mockChecksum },
},
});
expect(hasHeader).toHaveBeenCalledWith(mockChecksumLocationName, mockHeadersWithAlgoHeader);
expect(stringHasher).toHaveBeenCalledWith(mockChecksumAlgorithmFunction, mockRequest.body);
expect(mockBase64Encoder).toHaveBeenCalledWith(mockRawChecksum);
}
);
});

describe("set feature", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ export const flexibleChecksumsMiddleware =
return next(args);
}

for (const originalHeader of Object.keys(args.request.headers)) {
const header = originalHeader.toLowerCase();
if (header.startsWith("x-amz-checksum-") && header !== "x-amz-checksum-algorithm") {
for (const header of Object.keys(args.request.headers)) {
if (header.toLowerCase().startsWith("x-amz-checksum-")) {
return next(args);
}
}
Expand Down

0 comments on commit c808a7a

Please sign in to comment.