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): use RequestChecksumCalculation and ResponseChecksumValidation #6492

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented Sep 18, 2024

Issue

Description

  • Uses values in RequestChecksumCalculation and ResponseChecksumValidation to decide flexible checksums algorithm.
  • Adds flexibleChecksumsInterceptorMiddleware to populate input[requestValidationModeMember]
  • Deprecates MD5, and sets CRC32 as default.

Testing

Unit testing in CI

Also, verified that checksums are computed by default

import { S3 } from "../aws-sdk-js-v3/clients/client-s3/dist-cjs/index.js";
import { NodeHttpHandler } from "@smithy/node-http-handler";

class CustomHandler extends NodeHttpHandler {
  constructor() {
    super();
  }

  async handle(request, options) {
    for (const [header, value] of Object.entries(request.headers)) {
      if (header.startsWith("x-amz-checksum-")) {
        console.log(`request['${header}']: '${value}'`);
      }
    }
    const response = await super.handle(request, options);
    for (const [header, value] of Object.entries(response.response.headers)) {
      if (header.startsWith("x-amz-checksum-")) {
        console.log(`response['${header}']: '${value}'`);
      }
    }
    return response;
  }
}

// WHEN_SUPPORTED is default.
const client = new S3({
  requestHandler: new CustomHandler(),
});

console.log("Put Object");
await client.putObject({
  Bucket: "test-flexible-checksums-v2",
  Key: "hello-world.txt",
  Body: "Hello World",
});

console.log("\nGet Object");
await client.getObject({
  Bucket: "test-flexible-checksums-v2",
  Key: "hello-world.txt",
});

console.log("");
console.log(await Body.transformToString());

Output

Put Object
request['x-amz-checksum-crc32']: 'ShexVg=='
response['x-amz-checksum-crc32']: 'ShexVg=='

Get Object
request['x-amz-checksum-mode']: 'ENABLED'
request['x-amz-checksum-crc32']: 'AAAAAA=='
response['x-amz-checksum-crc32']: 'ShexVg=='

Hello World

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@trivikr trivikr changed the title chore(middleware-flexible-checksums): add flexibleChecksumsInterceptorMiddleware chore(middleware-flexible-checksums): use RequestChecksumCalculation and ResponseChecksumValidation Sep 18, 2024
@trivikr
Copy link
Member Author

trivikr commented Sep 19, 2024

The PR is ready for review. It's marked as draft, as it shouldn't be merged at this time.

const responseChecksumValidation = await config.responseChecksumValidation();

if (requestValidationModeMember && responseChecksumValidation === ResponseChecksumValidation.WHEN_SUPPORTED) {
input[requestValidationModeMember] = "ENABLED";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if the if conditions are true but input[requestValidationModeMember] is set by the user to some other value than ENABLED (ignoring the fact that this is the only enum value)?

I would expect us to allow the value through and allow the user to receive a validation exception from the server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants