Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clients/client-s3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"test": "yarn g:vitest run",
"test:browser": "node ./test/browser-build/esbuild && yarn g:vitest run -c vitest.config.browser.ts",
"test:browser:watch": "node ./test/browser-build/esbuild && yarn g:vitest watch -c vitest.config.browser.ts",
"test:integration": "yarn g:vitest run -c vitest.config.integ.ts",
"test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.ts",
"test:e2e": "yarn g:vitest run -c vitest.config.e2e.ts && yarn test:browser",
"test:e2e:watch": "yarn g:vitest watch -c vitest.config.e2e.ts",
"test:watch": "yarn g:vitest watch"
Expand Down
48 changes: 48 additions & 0 deletions clients/client-s3/test/integ/authSchemePreference.integ.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { describe, expect, test as it } from "vitest";

import { S3 } from "@aws-sdk/client-s3";
import "@aws-sdk/signature-v4-crt";

describe("authSchemePreference", () => {
const credentials = { accessKeyId: "key", secretAccessKey: "secret" };
const Bucket = `arn:aws:s3-outposts:us-west-2:123456789012:outpost/op-01234567890123456/accesspoint/abc-111`;
const Key = "key";
const Body = "body";

const SIGNATURE_PREFIX = {
sigv4: "AWS4-HMAC-SHA256",
sigv4a: "AWS4-ECDSA-P256-SHA256",
};

const interceptorMiddleware = (next, context) => (args) => {
// middleware intercept the request and return it early
const request = args.request;
return Promise.resolve({
output: {
$metadata: { attempts: 0, httpStatusCode: 200 },
request,
context,
},
response: {},
});
};

const getAuthorizationHeader = (headers: Record<string, string>) =>
headers["authorization"] || headers["Authorization"];

it.each([
["sigv4a", undefined],
["sigv4a", ["sigv3"]],
["sigv4", ["sigv4"]],
["sigv4", ["sigv4", "sigv4a"]],
["sigv4a", ["sigv4a"]],
["sigv4a", ["sigv4a", "sigv4"]],
])("selects '%s' when authSchemePreference: %s", async (output, authSchemePreference) => {
const client = new S3({ credentials, authSchemePreference });
client.middlewareStack.add(interceptorMiddleware, { step: "finalizeRequest", priority: "low" });
const result: any = await client.putObject({ Bucket, Key, Body });

const authorizationHeader = getAuthorizationHeader(result.request.headers);
expect(authorizationHeader.startsWith(SIGNATURE_PREFIX[output])).toBe(true);
});
});
8 changes: 8 additions & 0 deletions clients/client-s3/vitest.config.integ.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
include: ["**/*.integ.spec.ts"],
environment: "node",
},
});
Loading