Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: stub credentialDefaultProvider in test-http-handler #4781

Merged
merged 2 commits into from
Jun 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 28 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 @@ -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