Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(s3): emit x-amz-transition-default-minimum-object-size on lifecycle GET/PUT (#441) (#615)

TiMe6341cfc0994
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3LifecycleTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3LifecycleTest.java
new file mode 100644
index 0000000000..b3757c6bc0
--- /dev/null
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3LifecycleTest.java
@@ -0,0 +1,120 @@
+package com.floci.test;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+import software.amazon.awssdk.services.s3.S3Client;
+import software.amazon.awssdk.services.s3.model.BucketAlreadyOwnedByYouException;
+import software.amazon.awssdk.services.s3.model.BucketLifecycleConfiguration;
+import software.amazon.awssdk.services.s3.model.CreateBucketRequest;
+import software.amazon.awssdk.services.s3.model.DeleteBucketRequest;
+import software.amazon.awssdk.services.s3.model.ExpirationStatus;
+import software.amazon.awssdk.services.s3.model.GetBucketLifecycleConfigurationResponse;
+import software.amazon.awssdk.services.s3.model.LifecycleExpiration;
+import software.amazon.awssdk.services.s3.model.LifecycleRule;
+import software.amazon.awssdk.services.s3.model.LifecycleRuleFilter;
+import software.amazon.awssdk.services.s3.model.PutBucketLifecycleConfigurationResponse;
+import software.amazon.awssdk.services.s3.model.TransitionDefaultMinimumObjectSize;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * SDK-level round-trip tests for {@code PutBucketLifecycleConfiguration} and
+ * {@code GetBucketLifecycleConfiguration}.
+ *
+ * <p>The terraform-provider-aws v6.x stability wait
+ * ({@code waitLifecycleConfigEquals}) compares the
+ * {@code TransitionDefaultMinimumObjectSize} field between PUT input and GET
+ * output. The AWS Java/Go SDK reads that field <em>only</em> from the
+ * {@code x-amz-transition-default-minimum-object-size} response header, never
+ * from the XML body. A body-equality test against the raw HTTP API does not
+ * catch a missing header (this is the gap that let issue #441 be auto-closed
+ * by a body-only fix). These tests assert SDK-parsed equality.
+ */
+@DisplayName("S3 Lifecycle — TransitionDefaultMinimumObjectSize round-trip (#441)")
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+class S3LifecycleTest {
+
+ private static final String BUCKET = "compat-lifecycle-bucket";
+
+ private static S3Client s3;
+
+ @BeforeAll
+ static void setup() {
+ s3 = TestFixtures.s3Client();
+ try {
+ s3.createBucket(CreateBucketRequest.builder().bucket(BUCKET).build());
+ } catch (BucketAlreadyOwnedByYouException ignored) {}
+ }
+
+ @AfterAll
+ static void cleanup() {
+ if (s3 == null) return;
+ try { s3.deleteBucketLifecycle(b -> b.bucket(BUCKET)); } catch (Exception ignored) {}
+ try { s3.deleteBucket(DeleteBucketRequest.builder().bucket(BUCKET).build()); } catch (Exception ignored) {}
+ s3.close();
+ }
+
+ private static BucketLifecycleConfiguration sampleConfig() {
+ return BucketLifecycleConfiguration.builder()
+ .rules(LifecycleRule.builder()
+ .id("expire-everything")
+ .status(ExpirationStatus.ENABLED)
+ .filter(LifecycleRuleFilter.builder().prefix("").build())
+ .expiration(LifecycleExpiration.builder().days(365).build())
+ .build())
+ .build();
+ }
+
+ @Test
+ @Order(1)
+ @DisplayName("#441 PUT with VARIES_BY_STORAGE_CLASS round-trips via SDK on GET")
+ void putWithCustomSizeRoundTripsViaSdk() {
+ // The SDK serializes transitionDefaultMinimumObjectSize to the
+ // x-amz-transition-default-minimum-object-size request header. PUT
+ // response should carry the same header.
+ PutBucketLifecycleConfigurationResponse put = s3.putBucketLifecycleConfiguration(req -> req
+ .bucket(BUCKET)
+ .lifecycleConfiguration(sampleConfig())
+ .transitionDefaultMinimumObjectSize(TransitionDefaultMinimumObjectSize.VARIES_BY_STORAGE_CLASS));
+ assertThat(put.transitionDefaultMinimumObjectSize())
+ .as("PUT response must echo the request size header")
+ .isEqualTo(TransitionDefaultMinimumObjectSize.VARIES_BY_STORAGE_CLASS);
+
+ // GET parses the header into the response field. This is the equality
+ // terraform-provider-aws polls on; null/empty here is what hangs the
+ // wait in issue #441.
+ GetBucketLifecycleConfigurationResponse get =
+ s3.getBucketLifecycleConfiguration(req -> req.bucket(BUCKET));
+ assertThat(get.transitionDefaultMinimumObjectSize())
+ .as("GET must parse the size header into the response field")
+ .isEqualTo(TransitionDefaultMinimumObjectSize.VARIES_BY_STORAGE_CLASS);
+ assertThat(get.rules()).hasSize(1);
+ assertThat(get.rules().get(0).id()).isEqualTo("expire-everything");
+ assertThat(get.rules().get(0).status()).isEqualTo(ExpirationStatus.ENABLED);
+ }
+
+ @Test
+ @Order(2)
+ @DisplayName("#441 PUT without size field defaults to ALL_STORAGE_CLASSES_128_K on GET")
+ void putWithoutSizeFieldDefaultsTo128KOnGet() {
+ // The SDK omits the request header when the field is null. Provider
+ // default (and AWS default) is ALL_STORAGE_CLASSES_128_K. This PUT
+ // overwrites the VARIES_BY_STORAGE_CLASS config left by @Order(1) — the
+ // header-less PUT must reset the stored value to the default, otherwise
+ // a stale VARIES leaks through and the provider's equality check fails.
+ s3.putBucketLifecycleConfiguration(req -> req
+ .bucket(BUCKET)
+ .lifecycleConfiguration(sampleConfig()));
+
+ GetBucketLifecycleConfigurationResponse get =
+ s3.getBucketLifecycleConfiguration(req -> req.bucket(BUCKET));
+ assertThat(get.transitionDefaultMinimumObjectSize())
+ .as("GET must default to ALL_STORAGE_CLASSES_128_K when PUT omits the header")
+ .isEqualTo(TransitionDefaultMinimumObjectSize.ALL_STORAGE_CLASSES_128_K);
+ }
+}
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 3edc0810f9..470fedc894 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
@@ -171,8 +171,12 @@ public class S3Controller {
return Response.ok().build();
}
if (hasQueryParam(uriInfo, "lifecycle")) {
- s3Service.putBucketLifecycle(bucket, new String(body, StandardCharsets.UTF_8));
- return Response.ok().build();
+ String requestedSize = httpHeaders.getHeaderString("x-amz-transition-default-minimum-object-size");
+ String storedSize = s3Service.putBucketLifecycle(bucket,
+ new String(body, StandardCharsets.UTF_8), requestedSize);
+ return Response.ok()
+ .header("x-amz-transition-default-minimum-object-size", storedSize)
+ .build();
}
if (hasQueryParam(uriInfo, "acl")) {
s3Service.putBucketAcl(bucket, new String(body, StandardCharsets.UTF_8));
@@ -310,7 +314,10 @@ public class S3Controller {
return Response.ok(s3Service.getBucketCors(bucket)).build();
}
if (hasQueryParam(uriInfo, "lifecycle")) {
- return Response.ok(s3Service.getBucketLifecycle(bucket)).build();
+ S3Service.LifecycleConfigurationResult lc = s3Service.getBucketLifecycle(bucket);
+ return Response.ok(lc.xml())
+ .header("x-amz-transition-default-minimum-object-size", lc.transitionDefaultMinimumObjectSize())
+ .build();
}
if (hasQueryParam(uriInfo, "acl")) {
return Response.ok(s3Service.getBucketAcl(bucket)).build();
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java
index c2684ef5eb..5694fbe296 100644
--- a/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java
+++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java
@@ -1357,26 +1357,40 @@ public class S3Service {
bucketStore.put(bucketName, bucket);
}
- public String getBucketLifecycle(String bucketName) {
+ public static final String DEFAULT_TRANSITION_DEFAULT_MIN_OBJECT_SIZE = "all_storage_classes_128K";
+
+ public record LifecycleConfigurationResult(String xml, String transitionDefaultMinimumObjectSize) {}
+
+ public LifecycleConfigurationResult getBucketLifecycle(String bucketName) {
Bucket bucket = bucketStore.get(bucketName)
.orElseThrow(() -> new AwsException("NoSuchBucket", "The specified bucket does not exist.", 404));
if (bucket.getLifecycleConfiguration() == null) {
throw new AwsException("NoSuchLifecycleConfiguration", "The lifecycle configuration does not exist", 404);
}
- return bucket.getLifecycleConfiguration();
+ String size = bucket.getTransitionDefaultMinimumObjectSize();
+ if (size == null) {
+ size = DEFAULT_TRANSITION_DEFAULT_MIN_OBJECT_SIZE;
+ }
+ return new LifecycleConfigurationResult(bucket.getLifecycleConfiguration(), size);
}
- public void putBucketLifecycle(String bucketName, String lifecycle) {
+ public String putBucketLifecycle(String bucketName, String lifecycle, String transitionDefaultMinimumObjectSize) {
Bucket bucket = bucketStore.get(bucketName)
.orElseThrow(() -> new AwsException("NoSuchBucket", "The specified bucket does not exist.", 404));
bucket.setLifecycleConfiguration(lifecycle);
+ String size = (transitionDefaultMinimumObjectSize == null || transitionDefaultMinimumObjectSize.isBlank())
+ ? DEFAULT_TRANSITION_DEFAULT_MIN_OBJECT_SIZE
+ : transitionDefaultMinimumObjectSize;
+ bucket.setTransitionDefaultMinimumObjectSize(size);
bucketStore.put(bucketName, bucket);
+ return size;
}
public void deleteBucketLifecycle(String bucketName) {
Bucket bucket = bucketStore.get(bucketName)
.orElseThrow(() -> new AwsException("NoSuchBucket", "The specified bucket does not exist.", 404));
bucket.setLifecycleConfiguration(null);
+ bucket.setTransitionDefaultMinimumObjectSize(null);
bucketStore.put(bucketName, bucket);
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/model/Bucket.java b/src/main/java/io/github/hectorvent/floci/services/s3/model/Bucket.java
index 89cb92c115..84574248ab 100644
--- a/src/main/java/io/github/hectorvent/floci/services/s3/model/Bucket.java
+++ b/src/main/java/io/github/hectorvent/floci/services/s3/model/Bucket.java
@@ -21,6 +21,7 @@ public class Bucket {
private String policy;
private String corsConfiguration;
private String lifecycleConfiguration;
+ private String transitionDefaultMinimumObjectSize; // x-amz-transition-default-minimum-object-size header value
private String acl; // XML representation or JSON stub
private String encryptionConfiguration; // XML string
private String publicAccessBlockConfiguration; // XML string
@@ -73,6 +74,11 @@ public class Bucket {
public String getLifecycleConfiguration() { return lifecycleConfiguration; }
public void setLifecycleConfiguration(String lifecycleConfiguration) { this.lifecycleConfiguration = lifecycleConfiguration; }
+ public String getTransitionDefaultMinimumObjectSize() { return transitionDefaultMinimumObjectSize; }
+ public void setTransitionDefaultMinimumObjectSize(String transitionDefaultMinimumObjectSize) {
+ this.transitionDefaultMinimumObjectSize = transitionDefaultMinimumObjectSize;
+ }
+
public String getAcl() { return acl; }
public void setAcl(String acl) { this.acl = acl; }
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3LifecycleIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3LifecycleIntegrationTest.java
index bec231d4fc..9aa908d5b1 100644
--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3LifecycleIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3LifecycleIntegrationTest.java
@@ -121,6 +121,91 @@ class S3LifecycleIntegrationTest {
.statusCode(204);
}
+ // ── x-amz-transition-default-minimum-object-size (issue #441) ────────────
+ // The terraform-provider-aws v6.x stability wait reads this header from
+ // the GET response, not the XML body. Without it, the wait times out.
+
+ private static final String DEFAULT_SIZE = "all_storage_classes_128K";
+ private static final String CUSTOM_SIZE = "varies_by_storage_class";
+ private static final String SIZE_HEADER = "x-amz-transition-default-minimum-object-size";
+
+ @Test
+ @Order(81)
+ void putWithoutHeaderEchoesDefault() {
+ given()
+ .contentType("application/xml")
+ .body(FILTER_PREFIX_EMPTY_XML)
+ .when()
+ .put("/" + BUCKET + "?lifecycle")
+ .then()
+ .statusCode(200)
+ .header(SIZE_HEADER, equalTo(DEFAULT_SIZE));
+ }
+
+ @Test
+ @Order(82)
+ void getReturnsDefaultHeaderWhenPutOmittedIt() {
+ given()
+ .when()
+ .get("/" + BUCKET + "?lifecycle")
+ .then()
+ .statusCode(200)
+ .header(SIZE_HEADER, equalTo(DEFAULT_SIZE));
+ }
+
+ @Test
+ @Order(83)
+ void putWithCustomHeaderEchoesIt() {
+ given()
+ .contentType("application/xml")
+ .header(SIZE_HEADER, CUSTOM_SIZE)
+ .body(FILTER_PREFIX_EMPTY_XML)
+ .when()
+ .put("/" + BUCKET + "?lifecycle")
+ .then()
+ .statusCode(200)
+ .header(SIZE_HEADER, equalTo(CUSTOM_SIZE));
+ }
+
+ @Test
+ @Order(84)
+ void getReturnsCustomHeaderRoundTrip() {
+ given()
+ .when()
+ .get("/" + BUCKET + "?lifecycle")
+ .then()
+ .statusCode(200)
+ .header(SIZE_HEADER, equalTo(CUSTOM_SIZE));
+ }
+
+ @Test
+ @Order(85)
+ void deleteThenPutWithoutHeaderClearsToDefault() {
+ // Wipe any stored header value via DELETE.
+ given()
+ .when()
+ .delete("/" + BUCKET + "?lifecycle")
+ .then()
+ .statusCode(204);
+
+ // Subsequent PUT without the header must default, not retain CUSTOM_SIZE.
+ given()
+ .contentType("application/xml")
+ .body(FILTER_PREFIX_EMPTY_XML)
+ .when()
+ .put("/" + BUCKET + "?lifecycle")
+ .then()
+ .statusCode(200)
+ .header(SIZE_HEADER, equalTo(DEFAULT_SIZE));
+
+ given()
+ .when()
+ .get("/" + BUCKET + "?lifecycle")
+ .then()
+ .statusCode(200)
+ .header(SIZE_HEADER, equalTo(DEFAULT_SIZE));
+ }
+
// ── No config yet: GET returns 404 ────────────────────────────────────────
@Test