Skip to content

Commit

Permalink
test: use static credentials in integration
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Oct 29, 2024
1 parent e0f9e81 commit 08bc9a8
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe("middleware-flexible-checksums", () => {

requireRequestsFrom(client).toMatch({
headers: {
"user-agent": new RegExp(`(.*?) m\/${id},E$`),
"user-agent": new RegExp(`(.*?) m\/(.*?)${id}(.*?)$`),
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe("middleware-s3-express", () => {

requireRequestsFrom(client).toMatch({
headers: {
"user-agent": /(.*?) m\/J,E$/,
"user-agent": /(.*?) m\/(.*?)J(.*?)$/,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("middleware-token", () => {
},
});
requireRequestsFrom(client).toMatch({
headers: new Map([[/authorization/i, /Bearer MOCK_TOKEN/]]),
headers: new Map([[/authorization/i, /Bearer my-token/]]),
});
await client.getUserDetails({
id: "my-id",
Expand Down
1 change: 0 additions & 1 deletion private/aws-util-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"dependencies": {
"@aws-sdk/aws-protocoltests-json": "*",
"@smithy/protocol-http": "^4.1.4",
"@smithy/signature-v4": "^4.2.0",
"@smithy/types": "^3.5.0",
"tslib": "^2.6.2"
},
Expand Down
62 changes: 3 additions & 59 deletions private/aws-util-test/src/requests/test-http-handler.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
import { HttpHandler, HttpRequest, HttpResponse } from "@smithy/protocol-http";
import type { SignatureV4 } from "@smithy/signature-v4";
import {
AwsCredentialIdentity,
Client,
HandlerExecutionContext,
HttpHandlerOptions,
IdentityProvider,
RequestHandler,
RequestHandlerOutput,
SelectedHttpAuthScheme,
SMITHY_CONTEXT_KEY,
} from "@smithy/types";
import { Client, HttpHandlerOptions, RequestHandler, RequestHandlerOutput } from "@smithy/types";
import { expect } from "vitest";

/**
Expand Down Expand Up @@ -80,6 +69,8 @@ export class TestHttpHandler implements HttpHandler {
for (const key in RESERVED_ENVIRONMENT_VARIABLES) {
delete process.env[key];
}
process.env.AWS_ACCESS_KEY_ID = "INTEGRATION_TEST_MOCK";
process.env.AWS_SECRET_ACCESS_KEY = "INTEGRATION_TEST_MOCK";
}

/**
Expand All @@ -92,53 +83,6 @@ export class TestHttpHandler implements HttpHandler {
this.client = client;
this.originalRequestHandler = client.config.requestHandler;
// mock credentials to avoid default chain lookup.
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;
};
}
if (client.config.httpAuthSchemes) {
for (const authScheme of client.config.httpAuthSchemes) {
authScheme.identityProvider = () => {
return async () => {
return MOCK_CREDENTIALS;
};
};
}
}
client.middlewareStack.addRelativeTo(
(next: any, context: HandlerExecutionContext) => (args: any) => {
const scheme = context[SMITHY_CONTEXT_KEY]?.selectedHttpAuthScheme as SelectedHttpAuthScheme;
if (scheme) {
scheme.identity = MOCK_CREDENTIALS as AwsCredentialIdentity;
if ((scheme.signer as any).credentialProvider) {
(scheme.signer as any).credentialProvider = (async () =>
MOCK_CREDENTIALS) as IdentityProvider<AwsCredentialIdentity>;
}
}
return next(args);
},
{
name: "integrationTestMiddleware",
override: true,
toMiddleware: "httpSigningMiddleware",
relation: "before",
}
);

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

0 comments on commit 08bc9a8

Please sign in to comment.