Skip to content

Commit c67e0ef

Browse files
committed
test(client-s3): integration for config 'authSchemePreference'
1 parent e757a6e commit c67e0ef

File tree

1 file changed

+48
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)