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

fix(middleware-flexible-checksums): use input from args and not middleware config #6677

Merged
merged 4 commits into from
Nov 19, 2024

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented Nov 19, 2024

Issue

Refs: #6492 (comment)

Description

Use input from args and not middleware config in flexible checksums middleware.

This is because args.input will have updated values, while middlewareConfig.input will have initial values.
We're updating value in input[requestAlgorithmMember] in #6492

Testing

CI

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

// Prints checksum headers for request and response.
class CustomHandler extends NodeHttpHandler {
  constructor() {
    super();
  }

  printChecksumHeaders(prefix, headers) {
    for (const [header, value] of Object.entries(headers)) {
      if (header.startsWith("x-amz-checksum-") || header.startsWith("x-amz-sdk-checksum-")) {
        console.log(`${prefix}['${header}']: '${value}'`);
      }
    }
  }

  async handle(request, options) {
    this.printChecksumHeaders("request", request.headers);
    const response = await super.handle(request, options);
    this.printChecksumHeaders("response", response.response.headers);
    return response;
  }
}

const client = new S3({ requestHandler: new CustomHandler() });
const Bucket = "test-flexible-checksums-v2"; // Replace with your test bucket name.
const Key = "hello-world.txt";
const Body = "Hello World"; // Replace with the content you want to test.

console.log("Put Object");
await client.putObject({ Bucket, Key, Body, ChecksumAlgorithm: "CRC32" });

console.log("\nGet Object");
const response = await client.getObject({ Bucket, Key, ChecksumMode: "ENABLED" });

equal(Body, await response.Body.transformToString());

Checksum headers are set when ChecksumAlgorithm and ChecksumMode are set.

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

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

Checksum headers are not set when ChecksumAlgorithm and ChecksumMode are not set.

Put Object

Get Object

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 marked this pull request as ready for review November 19, 2024 18:09
@trivikr trivikr requested a review from a team as a code owner November 19, 2024 18:09
@trivikr trivikr marked this pull request as draft November 19, 2024 18:17
@trivikr trivikr marked this pull request as ready for review November 19, 2024 18:37
@trivikr trivikr merged commit 199aad0 into aws:main Nov 19, 2024
5 checks passed
@trivikr trivikr deleted the flex-checks-input-args branch November 19, 2024 21:44
Copy link

github-actions bot commented Dec 4, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants