From f2d74ac7955812bc63ce6fc8092ed023e0d0ceba Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Mon, 16 Dec 2024 22:38:18 +0000 Subject: [PATCH] fix(middleware-flexible-checksums): use object for requestAlgorithmMember --- .../src/flexibleChecksumsInputMiddleware.spec.ts | 10 +++------- .../src/flexibleChecksumsInputMiddleware.ts | 14 ++------------ .../src/flexibleChecksumsMiddleware.spec.ts | 6 ++++-- .../src/flexibleChecksumsMiddleware.ts | 8 +++++--- 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/packages/middleware-flexible-checksums/src/flexibleChecksumsInputMiddleware.spec.ts b/packages/middleware-flexible-checksums/src/flexibleChecksumsInputMiddleware.spec.ts index 2371740b96c7..7f715114d18c 100644 --- a/packages/middleware-flexible-checksums/src/flexibleChecksumsInputMiddleware.spec.ts +++ b/packages/middleware-flexible-checksums/src/flexibleChecksumsInputMiddleware.spec.ts @@ -9,10 +9,7 @@ vi.mock("@aws-sdk/core"); describe(flexibleChecksumsInputMiddleware.name, () => { const mockNext = vi.fn(); - - const mockRequestAlgorithmMember = "mockRequestAlgorithmMember"; const mockRequestValidationModeMember = "mockRequestValidationModeMember"; - const mockMiddlewareConfig = { requestChecksumRequired: false }; const mockConfig = { requestChecksumCalculation: () => Promise.resolve(RequestChecksumCalculation.WHEN_SUPPORTED), @@ -27,7 +24,6 @@ describe(flexibleChecksumsInputMiddleware.name, () => { describe("sets input.requestValidationModeMember", () => { it("when requestValidationModeMember is defined and responseChecksumValidation is supported", async () => { const mockMiddlewareConfigWithMockRequestValidationModeMember = { - ...mockMiddlewareConfig, requestValidationModeMember: mockRequestValidationModeMember, }; const handler = flexibleChecksumsInputMiddleware( @@ -43,7 +39,7 @@ describe(flexibleChecksumsInputMiddleware.name, () => { const mockArgs = { input: {} }; it("when requestValidationModeMember is not defined", async () => { - const handler = flexibleChecksumsInputMiddleware(mockConfig, mockMiddlewareConfig)(mockNext, {}); + const handler = flexibleChecksumsInputMiddleware(mockConfig, {})(mockNext, {}); await handler(mockArgs); expect(mockNext).toHaveBeenCalledWith(mockArgs); }); @@ -54,7 +50,7 @@ describe(flexibleChecksumsInputMiddleware.name, () => { responseChecksumValidation: () => Promise.resolve(ResponseChecksumValidation.WHEN_REQUIRED), } as PreviouslyResolved; - const handler = flexibleChecksumsInputMiddleware(mockConfigResWhenRequired, mockMiddlewareConfig)(mockNext, {}); + const handler = flexibleChecksumsInputMiddleware(mockConfigResWhenRequired, {})(mockNext, {}); await handler(mockArgs); expect(mockNext).toHaveBeenCalledWith(mockArgs); @@ -93,7 +89,7 @@ describe(flexibleChecksumsInputMiddleware.name, () => { [configKey]: () => Promise.resolve(configValue), } as PreviouslyResolved; - const handler = flexibleChecksumsInputMiddleware(mockConfigOverride, mockMiddlewareConfig)(mockNext, {}); + const handler = flexibleChecksumsInputMiddleware(mockConfigOverride, {})(mockNext, {}); await handler({ input: {} }); expect(setFeature).toHaveBeenCalledTimes(2); diff --git a/packages/middleware-flexible-checksums/src/flexibleChecksumsInputMiddleware.ts b/packages/middleware-flexible-checksums/src/flexibleChecksumsInputMiddleware.ts index 832fb8bbf060..0dcb7c94cba9 100644 --- a/packages/middleware-flexible-checksums/src/flexibleChecksumsInputMiddleware.ts +++ b/packages/middleware-flexible-checksums/src/flexibleChecksumsInputMiddleware.ts @@ -10,24 +10,14 @@ import { } from "@smithy/types"; import { PreviouslyResolved } from "./configuration"; -import { DEFAULT_CHECKSUM_ALGORITHM, RequestChecksumCalculation, ResponseChecksumValidation } from "./constants"; +import { RequestChecksumCalculation, ResponseChecksumValidation } from "./constants"; export interface FlexibleChecksumsInputMiddlewareConfig { - /** - * Indicates an operation requires a checksum in its HTTP request. - */ - requestChecksumRequired: boolean; - /** * Defines a top-level operation input member used to opt-in to best-effort validation * of a checksum returned in the HTTP response of the operation. */ requestValidationModeMember?: string; - - /** - * Defines a top-level operation input member that is used to configure request checksum behavior. - */ - requestAlgorithmMember?: string; } /** @@ -57,7 +47,7 @@ export const flexibleChecksumsInputMiddleware = ): SerializeHandler => async (args: SerializeHandlerArguments): Promise> => { const input = args.input; - const { requestValidationModeMember, requestAlgorithmMember, requestChecksumRequired } = middlewareConfig; + const { requestValidationModeMember } = middlewareConfig; const requestChecksumCalculation = await config.requestChecksumCalculation(); const responseChecksumValidation = await config.responseChecksumValidation(); diff --git a/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.spec.ts b/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.spec.ts index 5156907134d1..27afd7773cce 100644 --- a/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.spec.ts +++ b/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.spec.ts @@ -108,8 +108,10 @@ describe(flexibleChecksumsMiddleware.name, () => { describe("input[requestAlgorithmMember] is not defined and", () => { const mockMwConfigWithReqAlgoMember = { ...mockMiddlewareConfig, - requestAlgorithmMember: mockRequestAlgorithmMember, - requestAlgorithmMemberHttpHeader: mockRequestAlgorithmMemberHttpHeader, + requestAlgorithmMember: { + name: mockRequestAlgorithmMember, + httpHeader: mockRequestAlgorithmMemberHttpHeader, + }, }; it("requestChecksumCalculation is supported", async () => { diff --git a/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.ts b/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.ts index 46caf46174c2..8872adde5d93 100644 --- a/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.ts +++ b/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.ts @@ -72,15 +72,17 @@ export const flexibleChecksumsMiddleware = const { request, input } = args; const { body: requestBody, headers } = request; const { base64Encoder, streamHasher } = config; - const { requestChecksumRequired, requestAlgorithmMember, requestAlgorithmMemberHttpHeader } = middlewareConfig; + const { requestChecksumRequired, requestAlgorithmMember } = middlewareConfig; const requestChecksumCalculation = await config.requestChecksumCalculation(); + const requestAlgorithmMemberName = requestAlgorithmMember?.name; + const requestAlgorithmMemberHttpHeader = requestAlgorithmMember?.httpHeader; // The value for input member to configure flexible checksum is not set. - if (requestAlgorithmMember && !input[requestAlgorithmMember]) { + if (requestAlgorithmMemberName && !input[requestAlgorithmMemberName]) { // Set requestAlgorithmMember as default checksum algorithm only if request checksum calculation is supported // or request checksum is required. if (requestChecksumCalculation === RequestChecksumCalculation.WHEN_SUPPORTED || requestChecksumRequired) { - input[requestAlgorithmMember] = DEFAULT_CHECKSUM_ALGORITHM; + input[requestAlgorithmMemberName] = DEFAULT_CHECKSUM_ALGORITHM; if (requestAlgorithmMemberHttpHeader) { headers[requestAlgorithmMemberHttpHeader] = DEFAULT_CHECKSUM_ALGORITHM; }