diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java index b9a9bc20c8..8633499994 100644 --- a/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java +++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java @@ -1147,16 +1147,17 @@ public class S3Controller { private Response handleGetBucketLocation(String bucket) { String region = s3Service.getBucketRegion(bucket); - if (region == null) { - region = regionResolver.getDefaultRegion(); + XmlBuilder xml = new XmlBuilder() + .raw(""); + if (region == null || "us-east-1".equals(region)) { + xml.start("LocationConstraint", AwsNamespaces.S3) + .end("LocationConstraint"); + } else { + xml.start("LocationConstraint", AwsNamespaces.S3) + .raw(XmlBuilder.escape(region)) + .end("LocationConstraint"); } - String xml = new XmlBuilder() - .raw("") - .start("LocationConstraint", AwsNamespaces.S3) - .raw(XmlBuilder.escape(region)) - .end("LocationConstraint") - .build(); - return Response.ok(xml).type(MediaType.APPLICATION_XML).build(); + return Response.ok(xml.build()).type(MediaType.APPLICATION_XML).build(); } // --- Bucket Tagging --- diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java index 313d668deb..d1324e6756 100644 --- a/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java @@ -1272,4 +1272,54 @@ class S3IntegrationTest { given().when().delete("/pag-test-bucket/c.txt"); given().when().delete("/pag-test-bucket"); } + + @Test + @Order(120) + void getBucketLocation_usEast1ReturnsEmptyLocationConstraint() { + String bucket = "location-us-east-1-bucket"; + + given() + .when() + .put("/" + bucket) + .then() + .statusCode(200); + + given() + .when() + .get("/" + bucket + "?location") + .then() + .statusCode(200) + .body(containsString(" + eu-central-1 + + """; + + given() + .contentType("application/xml") + .body(createBucketConfiguration) + .when() + .put("/" + bucket) + .then() + .statusCode(200); + + given() + .when() + .get("/" + bucket + "?location") + .then() + .statusCode(200) + .body(containsString("eu-central-1")); + + given().when().delete("/" + bucket); + } }