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

feat(middleware-sdk-s3): add middleware for following region redirects #5185

Merged
merged 8 commits into from
Oct 5, 2023
Prev Previous commit
Next Next commit
test(middleware-sdk-s3): add initial unit tests for region redirect m…
…iddleware
siddsriv committed Sep 13, 2023
commit a6073225d80cbe0623e3ecc67073905ee077f221
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { HandlerExecutionContext } from "@smithy/types";

import { regionRedirectMiddleware } from "./region-redirect-middleware";

describe(regionRedirectMiddleware.name, () => {
const region = async () => "us-east-1";
const redirectRegion = "us-west-2";
let call = 0;
const next = (arg: any) => {
if (call === 0) {
call++;
throw Object.assign(new Error(), {
Code: "PermanentRedirect",
$metadata: { httpStatusCode: 301 },
$response: { headers: { "x-amz-bucket-region": redirectRegion } },
});
}
return null as any;
};

beforeEach(() => {
call = 0;
});

it("set S3 region redirect on context if receiving a PermanentRedirect error code with status 301", async () => {
const middleware = regionRedirectMiddleware({ region, followRegionRedirects: true });
const context = {} as HandlerExecutionContext;
const handler = middleware(next, context);
await handler({ input: null });
expect(context.__s3RegionRedirect).toEqual(redirectRegion);
});
});