Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(middleware-flexible-checksums): change default algorithm to CRC32 #6749

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions packages/middleware-flexible-checksums/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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";

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", () => {
Expand All @@ -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
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion private/aws-middleware-test/src/middleware-serde.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
Loading