From b9f75f79580d7fc2acd91ee15c5ca4ec3a44d69d Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Thu, 19 Dec 2024 17:10:08 +0000 Subject: [PATCH] chore(middleware-flexible-checksums): change default algorithm to CRC32 --- .../middleware-flexible-checksums/src/constants.ts | 10 ++++------ .../src/flexibleChecksumsMiddleware.ts | 12 ++++-------- .../src/getChecksumAlgorithmForRequest.spec.ts | 10 +++++----- .../src/getChecksumAlgorithmForRequest.ts | 9 +++------ .../aws-middleware-test/src/middleware-serde.spec.ts | 2 +- 5 files changed, 17 insertions(+), 26 deletions(-) diff --git a/packages/middleware-flexible-checksums/src/constants.ts b/packages/middleware-flexible-checksums/src/constants.ts index 1a1d13a2efa7..e55ca2cc07e2 100644 --- a/packages/middleware-flexible-checksums/src/constants.ts +++ b/packages/middleware-flexible-checksums/src/constants.ts @@ -52,6 +52,9 @@ export const DEFAULT_RESPONSE_CHECKSUM_VALIDATION = RequestChecksumCalculation.W * Checksum Algorithms supported by the SDK. */ export enum ChecksumAlgorithm { + /** + * @deprecated Use {@link ChecksumAlgorithm.CRC32} instead. + */ MD5 = "MD5", CRC32 = "CRC32", CRC32C = "CRC32C", @@ -70,9 +73,4 @@ export enum ChecksumLocation { /** * @internal */ -export const DEFAULT_CHECKSUM_ALGORITHM = ChecksumAlgorithm.MD5; - -/** - * @internal - */ -export const S3_EXPRESS_DEFAULT_CHECKSUM_ALGORITHM = ChecksumAlgorithm.CRC32; +export const DEFAULT_CHECKSUM_ALGORITHM = ChecksumAlgorithm.CRC32; diff --git a/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.ts b/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.ts index 470a2fcc08e6..2ed8e66f8c39 100644 --- a/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.ts +++ b/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.ts @@ -74,14 +74,10 @@ export const flexibleChecksumsMiddleware = const { base64Encoder, streamHasher } = config; const { requestChecksumRequired, requestAlgorithmMember } = middlewareConfig; - const checksumAlgorithm = getChecksumAlgorithmForRequest( - input, - { - requestChecksumRequired, - requestAlgorithmMember: requestAlgorithmMember?.name, - }, - !!context.isS3ExpressBucket - ); + const checksumAlgorithm = getChecksumAlgorithmForRequest(input, { + requestChecksumRequired, + requestAlgorithmMember: requestAlgorithmMember?.name, + }); let updatedBody = requestBody; let updatedHeaders = headers; diff --git a/packages/middleware-flexible-checksums/src/getChecksumAlgorithmForRequest.spec.ts b/packages/middleware-flexible-checksums/src/getChecksumAlgorithmForRequest.spec.ts index f333b56f9d9e..1981789e9b95 100644 --- a/packages/middleware-flexible-checksums/src/getChecksumAlgorithmForRequest.spec.ts +++ b/packages/middleware-flexible-checksums/src/getChecksumAlgorithmForRequest.spec.ts @@ -1,6 +1,6 @@ import { describe, expect, test as it } from "vitest"; -import { ChecksumAlgorithm } from "./constants"; +import { ChecksumAlgorithm, DEFAULT_CHECKSUM_ALGORITHM } from "./constants"; import { getChecksumAlgorithmForRequest } from "./getChecksumAlgorithmForRequest"; import { CLIENT_SUPPORTED_ALGORITHMS } from "./types"; @@ -8,8 +8,8 @@ describe(getChecksumAlgorithmForRequest.name, () => { const mockRequestAlgorithmMember = "mockRequestAlgorithmMember"; describe("when requestAlgorithmMember is not provided", () => { - it("returns MD5 if requestChecksumRequired is set", () => { - expect(getChecksumAlgorithmForRequest({}, { requestChecksumRequired: true })).toEqual(ChecksumAlgorithm.MD5); + it(`returns ${DEFAULT_CHECKSUM_ALGORITHM} if requestChecksumRequired is set`, () => { + expect(getChecksumAlgorithmForRequest({}, { requestChecksumRequired: true })).toEqual(DEFAULT_CHECKSUM_ALGORITHM); }); it("returns undefined if requestChecksumRequired is false", () => { @@ -20,9 +20,9 @@ describe(getChecksumAlgorithmForRequest.name, () => { describe("when requestAlgorithmMember is not set in input", () => { const mockOptions = { requestAlgorithmMember: mockRequestAlgorithmMember }; - it("returns MD5 if requestChecksumRequired is set", () => { + it(`returns ${DEFAULT_CHECKSUM_ALGORITHM} if requestChecksumRequired is set`, () => { expect(getChecksumAlgorithmForRequest({}, { ...mockOptions, requestChecksumRequired: true })).toEqual( - ChecksumAlgorithm.MD5 + DEFAULT_CHECKSUM_ALGORITHM ); }); diff --git a/packages/middleware-flexible-checksums/src/getChecksumAlgorithmForRequest.ts b/packages/middleware-flexible-checksums/src/getChecksumAlgorithmForRequest.ts index f3cba4b2313f..dc79a1a0c307 100644 --- a/packages/middleware-flexible-checksums/src/getChecksumAlgorithmForRequest.ts +++ b/packages/middleware-flexible-checksums/src/getChecksumAlgorithmForRequest.ts @@ -1,4 +1,4 @@ -import { ChecksumAlgorithm, DEFAULT_CHECKSUM_ALGORITHM, S3_EXPRESS_DEFAULT_CHECKSUM_ALGORITHM } from "./constants"; +import { ChecksumAlgorithm, DEFAULT_CHECKSUM_ALGORITHM } from "./constants"; import { CLIENT_SUPPORTED_ALGORITHMS } from "./types"; export interface GetChecksumAlgorithmForRequestOptions { @@ -20,16 +20,13 @@ export interface GetChecksumAlgorithmForRequestOptions { */ export const getChecksumAlgorithmForRequest = ( input: any, - { requestChecksumRequired, requestAlgorithmMember }: GetChecksumAlgorithmForRequestOptions, - isS3Express?: boolean + { requestChecksumRequired, requestAlgorithmMember }: GetChecksumAlgorithmForRequestOptions ): ChecksumAlgorithm | undefined => { - const defaultAlgorithm = isS3Express ? S3_EXPRESS_DEFAULT_CHECKSUM_ALGORITHM : DEFAULT_CHECKSUM_ALGORITHM; - // Either the Operation input member that is used to configure request checksum behavior is not set, or // the value for input member to configure flexible checksum is not set. if (!requestAlgorithmMember || !input[requestAlgorithmMember]) { // Select an algorithm only if request checksum is required. - return requestChecksumRequired ? defaultAlgorithm : undefined; + return requestChecksumRequired ? DEFAULT_CHECKSUM_ALGORITHM : undefined; } const checksumAlgorithm = input[requestAlgorithmMember]; diff --git a/private/aws-middleware-test/src/middleware-serde.spec.ts b/private/aws-middleware-test/src/middleware-serde.spec.ts index 0d2f4ea3cfe2..9049f5bb0591 100644 --- a/private/aws-middleware-test/src/middleware-serde.spec.ts +++ b/private/aws-middleware-test/src/middleware-serde.spec.ts @@ -27,7 +27,7 @@ describe("middleware-serde", () => { "x-amz-acl": "private", "content-length": "509", Expect: "100-continue", - "content-md5": "qpwmS0vhCISEXes008aoXA==", + "x-amz-checksum-crc32": "XnKFaw==", host: "s3.us-west-2.amazonaws.com", "x-amz-content-sha256": "c0a89780e1aac5dfa17604e9e25616e7babba0b655db189be49b4c352543bb22", },