Skip to content

Commit 49c6f99

Browse files
authored
test(client-s3): integration for config 'authSchemePreference' (#7063)
1 parent 48bdda3 commit 49c6f99

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

clients/client-s3/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"test": "yarn g:vitest run",
1616
"test:browser": "node ./test/browser-build/esbuild && yarn g:vitest run -c vitest.config.browser.ts",
1717
"test:browser:watch": "node ./test/browser-build/esbuild && yarn g:vitest watch -c vitest.config.browser.ts",
18+
"test:integration": "yarn g:vitest run -c vitest.config.integ.ts",
19+
"test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.ts",
1820
"test:e2e": "yarn g:vitest run -c vitest.config.e2e.ts && yarn test:browser",
1921
"test:e2e:watch": "yarn g:vitest watch -c vitest.config.e2e.ts",
2022
"test:watch": "yarn g:vitest watch"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { FinalizeRequestMiddleware } from "@smithy/types";
2+
import { describe, expect, test as it } from "vitest";
3+
4+
import { S3 } from "@aws-sdk/client-s3";
5+
import "@aws-sdk/signature-v4-crt";
6+
7+
describe("authSchemePreference", () => {
8+
const credentials = { accessKeyId: "key", secretAccessKey: "secret" };
9+
const Bucket = `arn:aws:s3-outposts:us-west-2:123456789012:outpost/op-01234567890123456/accesspoint/abc-111`;
10+
const Key = "key";
11+
const Body = "body";
12+
13+
const SIGNATURE_PREFIX: Record<string, string> = {
14+
sigv4: "AWS4-HMAC-SHA256",
15+
sigv4a: "AWS4-ECDSA-P256-SHA256",
16+
};
17+
18+
const interceptorMiddleware: FinalizeRequestMiddleware<any, any> = (next, context) => (args) => {
19+
// middleware intercept the request and return it early
20+
const request = args.request;
21+
return Promise.resolve({
22+
output: { $metadata: { attempts: 0, httpStatusCode: 200 }, request, context },
23+
response: {},
24+
});
25+
};
26+
27+
const getAuthorizationHeader = (headers: Record<string, string>) =>
28+
headers["authorization"] || headers["Authorization"];
29+
30+
it.each([
31+
["sigv4a", undefined],
32+
["sigv4a", ["sigv3"]],
33+
["sigv4", ["sigv4"]],
34+
["sigv4", ["sigv4", "sigv4a"]],
35+
["sigv4a", ["sigv4a"]],
36+
["sigv4a", ["sigv4a", "sigv4"]],
37+
])("selects '%s' when authSchemePreference: %s", async (output, authSchemePreference) => {
38+
const client = new S3({ credentials, authSchemePreference });
39+
client.middlewareStack.add(interceptorMiddleware, { step: "finalizeRequest", priority: "low" });
40+
const result: any = await client.putObject({ Bucket, Key, Body });
41+
42+
const authorizationHeader = getAuthorizationHeader(result.request.headers);
43+
expect(authorizationHeader.startsWith(SIGNATURE_PREFIX[output])).toBe(true);
44+
});
45+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
include: ["**/*.integ.spec.ts"],
6+
environment: "node",
7+
},
8+
});

0 commit comments

Comments
 (0)