mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
* fix(s3): emit x-amz-transition-default-minimum-object-size on lifecycle GET/PUT (#441) terraform-provider-aws v6.x added a stability wait that compares TransitionDefaultMinimumObjectSize between PUT input and GET output. The AWS SDK v2 reads that field only from the x-amz-transition-default-minimum-object-size response header, never from the XML body. Floci stored lifecycle XML verbatim and never set the header, so the SDK parsed it as null/empty, never matched the provider default (all_storage_classes_128K), and the wait timed out after 3 minutes. Persist the value on the Bucket model, read it from the PUT request header (defaulting to all_storage_classes_128K), and emit it on both PUT and GET responses. DELETE clears it for symmetry. Coverage: - REST Assured tests for default/custom/round-trip/delete-clears. - AWS Java SDK v2 round-trip in S3LifecycleSdkIntegrationTest, the level the existing #492 body-only fix did not exercise. Issue #441 was auto-closed by #492 without a real fix; reopens the underlying defect. * test(s3): move SDK lifecycle round-trip to compatibility-tests - Move S3LifecycleSdkIntegrationTest to compatibility-tests/sdk-test-java as S3LifecycleTest, adapted to use TestFixtures.s3Client() and AssertJ to match the existing compat suite. - Drop the test-scope software.amazon.awssdk:s3 dependency from the main pom.xml; the in-tree JUnit tests do not need an SDK client. - Addresses review feedback on PR #615.
This commit is contained in:
5 files changed
+238
-6
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user