Skip to content

Commit 467913a

Browse files
committed
test: override selected httpAuthScheme.identity in integration tests
1 parent f5e4b0c commit 467913a

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

private/aws-util-test/src/requests/test-http-handler.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { HttpHandler, HttpRequest, HttpResponse } from "@smithy/protocol-http";
2-
import { Client, HttpHandlerOptions, RequestHandler, RequestHandlerOutput } from "@smithy/types";
2+
import {
3+
Client,
4+
HandlerExecutionContext,
5+
HttpHandlerOptions,
6+
RequestHandler,
7+
RequestHandlerOutput,
8+
SMITHY_CONTEXT_KEY,
9+
} from "@smithy/types";
310
import { expect } from "vitest";
411

512
/**
@@ -34,6 +41,7 @@ export type HttpRequestMatcher = {
3441
const MOCK_CREDENTIALS = {
3542
accessKeyId: "MOCK_ACCESS_KEY_ID",
3643
secretAccessKey: "MOCK_SECRET_ACCESS_KEY_ID",
44+
token: "MOCK_TOKEN",
3745
};
3846

3947
/**
@@ -103,14 +111,25 @@ export class TestHttpHandler implements HttpHandler {
103111
for (const authScheme of client.config.httpAuthSchemes) {
104112
authScheme.identityProvider = () => {
105113
return async () => {
106-
return {
107-
...MOCK_CREDENTIALS,
108-
token: "MOCK_TOKEN",
109-
};
114+
return MOCK_CREDENTIALS;
110115
};
111116
};
112117
}
113118
}
119+
client.middlewareStack.addRelativeTo(
120+
(next: any, context: HandlerExecutionContext) => (args: any) => {
121+
if (context[SMITHY_CONTEXT_KEY]?.selectedHttpAuthScheme) {
122+
(context[SMITHY_CONTEXT_KEY] as any).selectedHttpAuthScheme.identity = MOCK_CREDENTIALS;
123+
}
124+
return next(args);
125+
},
126+
{
127+
name: "integrationTestMiddleware",
128+
override: true,
129+
toMiddleware: "httpSigningMiddleware",
130+
relation: "before",
131+
}
132+
);
114133

115134
client.config.requestHandler = new TestHttpHandler(matcher);
116135
if (!(client as any)[TestHttpHandler.WATCHER]) {

0 commit comments

Comments
 (0)