|
1 | 1 | 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"; |
3 | 10 | import { expect } from "vitest"; |
4 | 11 |
|
5 | 12 | /** |
@@ -34,6 +41,7 @@ export type HttpRequestMatcher = { |
34 | 41 | const MOCK_CREDENTIALS = { |
35 | 42 | accessKeyId: "MOCK_ACCESS_KEY_ID", |
36 | 43 | secretAccessKey: "MOCK_SECRET_ACCESS_KEY_ID", |
| 44 | + token: "MOCK_TOKEN", |
37 | 45 | }; |
38 | 46 |
|
39 | 47 | /** |
@@ -103,14 +111,25 @@ export class TestHttpHandler implements HttpHandler { |
103 | 111 | for (const authScheme of client.config.httpAuthSchemes) { |
104 | 112 | authScheme.identityProvider = () => { |
105 | 113 | return async () => { |
106 | | - return { |
107 | | - ...MOCK_CREDENTIALS, |
108 | | - token: "MOCK_TOKEN", |
109 | | - }; |
| 114 | + return MOCK_CREDENTIALS; |
110 | 115 | }; |
111 | 116 | }; |
112 | 117 | } |
113 | 118 | } |
| 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 | + ); |
114 | 133 |
|
115 | 134 | client.config.requestHandler = new TestHttpHandler(matcher); |
116 | 135 | if (!(client as any)[TestHttpHandler.WATCHER]) { |
|
0 commit comments