Skip to content

Commit d9d7534

Browse files
committed
test(client-s3): e2e for flexible checksums
1 parent e3d92aa commit d9d7534

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

clients/client-s3/test/e2e/S3.e2e.spec.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "@aws-sdk/signature-v4-crt";
22

3-
import { S3, SelectObjectContentEventStream } from "@aws-sdk/client-s3";
3+
import { ChecksumAlgorithm, S3, SelectObjectContentEventStream } from "@aws-sdk/client-s3";
44
import { afterAll, afterEach, beforeAll, describe, expect, test as it } from "vitest";
55

66
import { getIntegTestResources } from "../../../../tests/e2e/get-integ-test-resources";
@@ -24,9 +24,7 @@ describe("@aws-sdk/client-s3", () => {
2424

2525
Key = ``;
2626

27-
client = new S3({
28-
region,
29-
});
27+
client = new S3({ region });
3028
});
3129

3230
describe("PutObject", () => {
@@ -74,26 +72,43 @@ describe("@aws-sdk/client-s3", () => {
7472
await client.deleteObject({ Bucket, Key });
7573
});
7674

77-
it("should succeed with valid body payload", async () => {
75+
it("should succeed with valid body payload with checksums", async () => {
7876
// prepare the object.
7977
const body = createBuffer("1MB");
78+
let bodyChecksum = "";
79+
80+
const bodyChecksumReader = (next) => async (args) => {
81+
const checksumValue = args.request.headers["x-amz-checksum-crc32"];
82+
if (checksumValue) {
83+
bodyChecksum = checksumValue;
84+
}
85+
return next(args);
86+
};
87+
client.middlewareStack.addRelativeTo(bodyChecksumReader, {
88+
name: "bodyChecksumReader",
89+
relation: "before",
90+
toMiddleware: "deserializerMiddleware",
91+
});
8092

8193
try {
82-
await client.putObject({ Bucket, Key, Body: body });
94+
await client.putObject({ Bucket, Key, Body: body, ChecksumAlgorithm: ChecksumAlgorithm.CRC32 });
8395
} catch (e) {
8496
console.error("failed to put");
8597
throw e;
8698
}
8799

100+
expect(bodyChecksum).not.toEqual("");
101+
88102
try {
89103
// eslint-disable-next-line no-var
90-
var result = await client.getObject({ Bucket, Key });
104+
var result = await client.getObject({ Bucket, Key, ChecksumMode: "ENABLED" });
91105
} catch (e) {
92106
console.error("failed to get");
93107
throw e;
94108
}
95109

96110
expect(result.$metadata.httpStatusCode).toEqual(200);
111+
expect(result.ChecksumCRC32).toEqual(bodyChecksum);
97112
const { Readable } = require("stream");
98113
expect(result.Body).toBeInstanceOf(Readable);
99114
});

0 commit comments

Comments
 (0)