Skip to content

Commit 58fd243

Browse files
authored
fix(middleware-location-constraint): insert LocationConstraint only additively (#7433)
1 parent 9ecb6d6 commit 58fd243

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

packages/middleware-location-constraint/src/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@ export function locationConstraintMiddleware(
2525
//After region config resolution, region is a Provider<string>
2626
const region = await options.region();
2727
if (!CreateBucketConfiguration?.LocationConstraint && !CreateBucketConfiguration?.Location) {
28-
args = {
29-
...args,
30-
input: {
31-
...args.input,
32-
CreateBucketConfiguration: region === "us-east-1" ? undefined : { LocationConstraint: region },
33-
},
34-
};
28+
if (region !== "us-east-1") {
29+
args.input.CreateBucketConfiguration = args.input.CreateBucketConfiguration ?? {};
30+
args.input.CreateBucketConfiguration.LocationConstraint = region;
31+
}
3532
}
3633

3734
return next(args);

packages/middleware-location-constraint/src/middleware-location-constraint.integ.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,32 @@ describe("middleware-location-constraint", () => {
3434
expect.hasAssertions();
3535
});
3636

37+
it("should populate other elements of the CreateBucketConfiguration regardless of Location or LocationConstraint", async () => {
38+
const client = new S3({ region: "us-east-1" });
39+
40+
requireRequestsFrom(client).toMatch({
41+
body(body = "") {
42+
expect(body).toContain(
43+
`<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Tags><Tag><Key>my-tag-key</Key><Value>my-tag-value</Value></Tag></Tags></CreateBucketConfiguration>`
44+
);
45+
},
46+
});
47+
48+
await client.createBucket({
49+
Bucket: "b",
50+
CreateBucketConfiguration: {
51+
Tags: [
52+
{
53+
Key: "my-tag-key",
54+
Value: "my-tag-value",
55+
},
56+
],
57+
},
58+
});
59+
60+
expect.hasAssertions();
61+
});
62+
3763
it("also not for S3 Express buckets", async () => {
3864
const client = new S3({ region: "us-west-2" });
3965

0 commit comments

Comments
 (0)