Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion packages/token-providers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"extract:docs": "api-extractor run --local",
"test": "yarn g:vitest run",
"test:watch": "yarn g:vitest watch"
"test:watch": "yarn g:vitest watch",
"test:integration": "yarn g:vitest run -c vitest.config.integ.ts",
"test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.ts"
},
"keywords": [
"aws",
Expand Down
81 changes: 81 additions & 0 deletions packages/token-providers/src/fromEnvSigningName.integ.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src";
import { Bedrock } from "@aws-sdk/client-bedrock";
import { BedrockRuntime } from "@aws-sdk/client-bedrock-runtime";
import { afterEach, beforeEach, describe, it } from "vitest";

describe("from env signing name integration", () => {
const mockBearerToken = "mock-bearer-token";
const credentials = {
accessKeyId: "INTEG",
secretAccessKey: "INTEG",
};
const region = "us-west-2";

beforeEach(() => {
delete process.env.AWS_BEARER_TOKEN_BEDROCK;
});

afterEach(() => {
delete process.env.AWS_BEARER_TOKEN_BEDROCK;
});

function expectBearerToken(client: Bedrock | BedrockRuntime) {
requireRequestsFrom(client).toMatch({
headers: {
authorization: `Bearer ${mockBearerToken}`,
},
});
}

function expectSigV4(client: Bedrock | BedrockRuntime) {
requireRequestsFrom(client).toMatch({
hostname: /bedrock/,
headers: {
authorization: /AWS4-HMAC-SHA256 Credential/,
},
});
}

describe("when environment bearer token is set", () => {
it("bedrock", async () => {
process.env.AWS_BEARER_TOKEN_BEDROCK = mockBearerToken;
const client = new Bedrock({ region, credentials });
expectBearerToken(client);
await client.listCustomModels();
});

it("bedrock runtime", async () => {
process.env.AWS_BEARER_TOKEN_BEDROCK = mockBearerToken;
const client = new BedrockRuntime({
region,
credentials,
});
expectBearerToken(client);
await client.listAsyncInvokes();
});

it("can be overridden by auth scheme preference", async () => {
process.env.AWS_BEARER_TOKEN_BEDROCK = mockBearerToken;
const client = new Bedrock({ region, credentials, authSchemePreference: ["sigv4"] });
expectSigV4(client);
await client.listCustomModels();
});
});

describe("when environment bearer token is not set", () => {
it("bedrock", async () => {
const client = new Bedrock({ region, credentials });
expectSigV4(client);
await client.listCustomModels();
});

it("bedrock runtime", async () => {
const client = new BedrockRuntime({
region,
credentials,
});
expectSigV4(client);
await client.listAsyncInvokes();
});
});
});
8 changes: 8 additions & 0 deletions packages/token-providers/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",
},
});
16 changes: 12 additions & 4 deletions private/aws-util-test/src/requests/test-http-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ export class TestHttpHandler implements HttpHandler {
this.check(m.hostname, request.hostname);
this.check(m.port, request.port);
this.check(m.path, request.path);
this.checkAll(m.query, request.query);
this.checkAll(m.query ?? {}, request.query, "query");

this.checkAll(m.headers, request.headers);
this.checkAll(m.headers ?? {}, request.headers, "header");
this.check(m.body, request.body);
this.check(m.method, request.method);

Expand Down Expand Up @@ -189,7 +189,11 @@ export class TestHttpHandler implements HttpHandler {
this.assertions++;
}

private checkAll(matchers?: Record<string, Matcher> | Map<RegExp | string, Matcher>, observed?: any) {
private checkAll(
matchers: Record<string, Matcher> | Map<RegExp | string, Matcher>,
observed: any,
type: "header" | "query"
) {
if (matchers == null) {
return;
}
Expand All @@ -201,7 +205,11 @@ export class TestHttpHandler implements HttpHandler {
if (key.startsWith("/") && key.endsWith("/")) {
key = new RegExp(key);
} else {
this.check(matcher, observed[key]);
const matchingValue =
type === "header"
? observed[Object.keys(observed).find((k) => k.toLowerCase() === String(key).toLowerCase()) ?? ""]
: observed[key];
this.check(matcher, matchingValue);
}
}
if (key instanceof RegExp) {
Expand Down
Loading