From 2d250ccf3cfc2fb1370cedd2ccba1e1c9102cfc8 Mon Sep 17 00:00:00 2001 From: Marius Volkhart Date: Sat, 11 Jul 2026 16:18:41 -0400 Subject: [PATCH] fix(s3): handle DeleteBucketReplication instead of deleting the whole bucket (#1837) DELETE /{bucket}?replication fell through the sub-resource switch (which handled tagging/website/policy/cors/lifecycle/encryption/publicAccessBlock/ownershipControls but not replication) to the unqualified DeleteBucket, silently destroying the entire bucket and returning 204. Real S3 DeleteBucketReplication removes only the replication configuration and returns 204; a sub-resource-qualified DELETE never deletes the bucket: https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteBucketReplication.html Floci does not model replication, so DeleteBucketReplication is a no-op 204 -- handled explicitly so it cannot reach the bucket-delete fall-through. Closes #1835 --- .../floci/services/s3/S3Controller.java | 6 ++ .../s3/S3ReplicationIntegrationTest.java | 86 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 src/test/java/io/github/hectorvent/floci/services/s3/S3ReplicationIntegrationTest.java 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 891cf2c8bc..3b1a1c75ce 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 @@ -314,6 +314,12 @@ public class S3Controller { s3Service.deleteBucketOwnershipControls(bucket); return Response.noContent().build(); } + if (hasQueryParam(uriInfo, "replication")) { + // Floci does not model bucket replication; DeleteBucketReplication is a + // no-op that always returns 204, matching real S3. Crucially it must be + // handled here so it does NOT fall through to deleting the whole bucket. + return Response.noContent().build(); + } s3Service.deleteBucket(bucket); return Response.noContent().build(); } catch (AwsException e) { diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3ReplicationIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3ReplicationIntegrationTest.java new file mode 100644 index 0000000000..ca277ac17b --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3ReplicationIntegrationTest.java @@ -0,0 +1,86 @@ +package io.github.hectorvent.floci.services.s3; + +import io.quarkus.test.junit.QuarkusTest; +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 static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.containsString; + +@QuarkusTest +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +class S3ReplicationIntegrationTest { + + private static final String BUCKET = "replication-int-test"; + + @Test + @Order(1) + void createBucket() { + given() + .when() + .put("/" + BUCKET) + .then() + .statusCode(200); + } + + /** + * Regression test for the bucket-destroying bug where {@code DELETE /{bucket}?replication} + * (DeleteBucketReplication) was not handled and fell through to the unqualified + * {@code DeleteBucket}, silently deleting the entire bucket. Real S3 removes only the + * replication configuration and returns 204. + */ + @Test + @Order(2) + void deleteReplicationDoesNotDeleteBucket() { + given() + .when() + .delete("/" + BUCKET + "?replication") + .then() + .statusCode(204); + } + + @Test + @Order(3) + void bucketStillExistsAfterReplicationDelete() { + // A sub-resource-qualified DELETE must never remove the bucket itself. + given() + .when() + .get("/" + BUCKET + "?versioning") + .then() + .statusCode(200); + } + + @Test + @Order(4) + void putVersioningAfterReplicationDeleteSucceeds() { + given() + .body(""" + + Enabled + + """) + .when() + .put("/" + BUCKET + "?versioning") + .then() + .statusCode(200); + } + + @Test + @Order(5) + void unqualifiedDeleteStillRemovesBucket() { + given() + .when() + .delete("/" + BUCKET) + .then() + .statusCode(204); + // Bucket is gone now: a sub-resource GET should report NoSuchBucket. + given() + .when() + .get("/" + BUCKET + "?versioning") + .then() + .statusCode(404) + .body(containsString("NoSuchBucket")); + } +}