Light, fluffy, and always free - The AWS Local Emulator alternative
fix(s3): apply CreateBucketConfiguration tags on bucket creation (#2115)
Arindam Choudhury79031a240ab0
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.javaindex f73e094a0a..083ab38ace 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@@ -331,6 +331,15 @@ public class S3Controller {}String region = locationConstraint != null ? locationConstraint : regionResolver.resolveRegion(httpHeaders);s3Service.createBucket(bucket, region);+ // CreateBucketConfiguration may carry a <Tags> array; AWS applies those tags to the+ // new bucket, so a follow-up GetBucketTagging / ListTagsForResource must return them.+ if (body != null && body.length > 0) {+ Map<String, String> creationTags = XmlParser.extractPairs(+ new String(body, StandardCharsets.UTF_8), "Tag", "Key", "Value");+ if (!creationTags.isEmpty()) {+ s3Service.putBucketTagging(bucket, creationTags);+ }+ }String lockEnabled = httpHeaders.getHeaderString("x-amz-bucket-object-lock-enabled");if ("true".equalsIgnoreCase(lockEnabled)) {s3Service.putBucketVersioning(bucket, "Enabled");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.javaindex fefe54c97b..58ae06c95a 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@@ -361,6 +361,44 @@ class S3IntegrationTest {.body(containsString("NoSuchBucket"));}+ @Test+ @Order(21)+ void createBucketAppliesTagsFromCreateBucketConfiguration() {+ String bucket = "tagged-at-create-bucket";+ String createBucketConfiguration = """+ <CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">+ <Tags>+ <Tag>+ <Key>owner</Key>+ <Value>data-team</Value>+ </Tag>+ </Tags>+ </CreateBucketConfiguration>+ """;++ given()+ .contentType("application/xml")+ .body(createBucketConfiguration)+ .when()+ .put("/" + bucket)+ .then()+ .statusCode(200);++ given()+ .when()+ .get("/" + bucket + "?tagging")+ .then()+ .statusCode(200)+ .body(containsString("owner"))+ .body(containsString("data-team"));++ given()+ .when()+ .delete("/" + bucket)+ .then()+ .statusCode(204);+ }+@Test@Order(20)void headBucketReturnsStoredRegionForLocationConstraintBucket() {