Skip to content

Commit

Permalink
test: stub credentialDefaultProvider in test-http-handler (#4781)
Browse files Browse the repository at this point in the history
* test: stub credentialDefaultProvider in test-http-handler

* test: override signer credential provider in integ test mock
  • Loading branch information
kuhe committed Jun 21, 2023
1 parent 22bb15d commit 20391b1
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions private/aws-util-test/src/requests/test-http-handler.ts
Expand Up @@ -27,6 +27,14 @@ export type HttpRequestMatcher = {
log?: boolean;
};

/**
* @internal
*/
const MOCK_CREDENTIALS = {
accessKeyId: "MOCK_ACCESS_KEY_ID",
secretAccessKey: "MOCK_SECRET_ACCESS_KEY_ID",
};

/**
* Supplied to test clients to assert correct requests.
* @internal
Expand All @@ -50,10 +58,26 @@ export class TestHttpHandler implements HttpHandler {
this.client = client;
this.originalRequestHandler = client.config.originalRequestHandler;
// mock credentials to avoid default chain lookup.
client.config.credentials = async () => ({
accessKeyId: "MOCK_ACCESS_KEY_ID",
secretAccessKey: "MOCK_SECRET_ACCESS_KEY_ID",
});
client.config.credentials = async () => MOCK_CREDENTIALS;
client.config.credentialDefaultProvider = () => {
return async () => {
return MOCK_CREDENTIALS;
};
};
const signerProvider = client.config.signer;
if (typeof signerProvider === "function") {
client.config.signer = async () => {
const _signer = await signerProvider();
if (typeof _signer.credentialProvider === "function") {
// signer is instance of SignatureV4
_signer.credentialProvider = async () => {
return MOCK_CREDENTIALS;
};
}
return _signer;
};
}

client.config.requestHandler = new TestHttpHandler(matcher);
if (!(client as any)[TestHttpHandler.WATCHER]) {
(client as any)[TestHttpHandler.WATCHER] = true;
Expand Down

0 comments on commit 20391b1

Please sign in to comment.