-
Notifications
You must be signed in to change notification settings - Fork 647
feat(middleware-flexible-checksums): use CRC64NVME JS implementation if CRT is not available #7595
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6ae6ccd
chore: move crt dependency to peerDependencies
trivikr 452cda4
chore: use CRC64NVME JS implementation if CRT is not available
trivikr 0883b0c
test(middleware-flexible-checksums): move crt crcr64nvme to different…
trivikr a8f15bb
test: add E2E tests for default cchecksums computation
trivikr c0bdcf7
docs: remove need of CRT for CRC64NVME
trivikr 85fa1e9
chore: remove crt dependency from nvme
trivikr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
packages/middleware-flexible-checksums/src/middleware-flexible-checksums.crt.integ.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| // Testing CRT implementation of CRC64NVME | ||
| import "@aws-sdk/crc64-nvme-crt"; | ||
|
|
||
| import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src"; | ||
| import { ChecksumAlgorithm, S3 } from "@aws-sdk/client-s3"; | ||
| import { HttpHandler, HttpRequest, HttpResponse } from "@smithy/protocol-http"; | ||
| import { Readable, Transform } from "stream"; | ||
| import { describe, expect, test as it } from "vitest"; | ||
|
|
||
| import { RequestChecksumCalculation, ResponseChecksumValidation } from "./constants"; | ||
|
|
||
| describe("middleware-flexible-checksums", () => { | ||
| const logger = { | ||
| trace() {}, | ||
| debug() {}, | ||
| info() {}, | ||
| warn() {}, | ||
| error() {}, | ||
| }; | ||
|
|
||
| const testCases: [string, string][] = [ | ||
| ["", "AAAAAAAAAAA="], | ||
| ["abc", "BeXKuz/B+us="], | ||
| ["Hello world", "OOJZ0D8xKts="], | ||
| ]; | ||
|
|
||
| describe(S3.name, () => { | ||
| describe("putObject", () => { | ||
| describe.each([undefined, RequestChecksumCalculation.WHEN_SUPPORTED, RequestChecksumCalculation.WHEN_REQUIRED])( | ||
| `when requestChecksumCalculation='%s'`, | ||
| (requestChecksumCalculation) => { | ||
| testCases.forEach(([body, checksumValue]) => { | ||
| const client = new S3({ region: "us-west-2", logger, requestChecksumCalculation }); | ||
| const checksumHeader = `x-amz-checksum-${ChecksumAlgorithm.CRC64NVME.toLowerCase()}`; | ||
|
|
||
| it(`tests ${checksumHeader}="${checksumValue}"" for checksum="${ChecksumAlgorithm.CRC64NVME}"`, async () => { | ||
| requireRequestsFrom(client).toMatch({ | ||
| method: "PUT", | ||
| hostname: "s3.us-west-2.amazonaws.com", | ||
| protocol: "https:", | ||
| path: "/b/k", | ||
| headers: { | ||
| "content-type": "application/octet-stream", | ||
| ...(body.length | ||
| ? { | ||
| "content-length": body.length.toString(), | ||
| } | ||
| : {}), | ||
| "x-amz-sdk-checksum-algorithm": ChecksumAlgorithm.CRC64NVME, | ||
| [checksumHeader]: checksumValue, | ||
| host: "s3.us-west-2.amazonaws.com", | ||
| "x-amz-user-agent": /./, | ||
| "user-agent": /./, | ||
| "amz-sdk-invocation-id": /./, | ||
| "amz-sdk-request": /./, | ||
| "x-amz-date": /./, | ||
| "x-amz-content-sha256": /./, | ||
| authorization: /./, | ||
| }, | ||
| query: { | ||
| "x-id": "PutObject", | ||
| }, | ||
| }); | ||
|
|
||
| await client.putObject({ | ||
| Bucket: "b", | ||
| Key: "k", | ||
| Body: body, | ||
| ChecksumAlgorithm: ChecksumAlgorithm.CRC64NVME, | ||
| }); | ||
|
|
||
| expect.hasAssertions(); | ||
| }); | ||
| }); | ||
| } | ||
| ); | ||
| }); | ||
|
|
||
| describe("getObject", () => { | ||
| describe.each([undefined, ResponseChecksumValidation.WHEN_SUPPORTED, ResponseChecksumValidation.WHEN_REQUIRED])( | ||
| `when responseChecksumValidation='%s'`, | ||
| (responseChecksumValidation) => { | ||
| testCases.forEach(([body, checksumValue]) => { | ||
| const checksumHeader = `x-amz-checksum-${ChecksumAlgorithm.CRC64NVME.toLowerCase()}`; | ||
|
|
||
| it(`validates ${checksumHeader}="${checksumValue}"" for checksum="${ChecksumAlgorithm.CRC64NVME}"`, async () => { | ||
| const client = new S3({ | ||
| region: "us-west-2", | ||
| logger, | ||
| requestHandler: new (class implements HttpHandler { | ||
| async handle(request: HttpRequest): Promise<any> { | ||
| expect(request).toMatchObject({ | ||
| method: "GET", | ||
| hostname: "s3.us-west-2.amazonaws.com", | ||
| protocol: "https:", | ||
| path: "/b/k", | ||
| headers: { | ||
| "x-amz-checksum-mode": "ENABLED", | ||
| host: "s3.us-west-2.amazonaws.com", | ||
| "x-amz-user-agent": /./, | ||
| "user-agent": /./, | ||
| "amz-sdk-invocation-id": /./, | ||
| "amz-sdk-request": /./, | ||
| "x-amz-date": /./, | ||
| "x-amz-content-sha256": /./, | ||
| authorization: /./, | ||
| }, | ||
| query: { | ||
| "x-id": "GetObject", | ||
| }, | ||
| }); | ||
| return { | ||
| response: new HttpResponse({ | ||
| statusCode: 200, | ||
| headers: { | ||
| "content-type": "application/octet-stream", | ||
| "content-length": body.length.toString(), | ||
| [checksumHeader]: checksumValue, | ||
| }, | ||
| body: Readable.from([body]), | ||
| }), | ||
| }; | ||
| } | ||
| updateHttpClientConfig(key: never, value: never): void {} | ||
| httpHandlerConfigs() { | ||
| return {}; | ||
| } | ||
| })(), | ||
| responseChecksumValidation, | ||
| }); | ||
|
|
||
| const response = await client.getObject({ | ||
| Bucket: "b", | ||
| Key: "k", | ||
| ChecksumMode: "ENABLED", | ||
| }); | ||
|
|
||
| await expect(response.Body?.transformToString()).resolves.toEqual(body); | ||
| }); | ||
| }); | ||
| } | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
packages/middleware-flexible-checksums/src/middleware-flexible-checksums.integ.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.