Skip to content

armgit / floci

Public Imported from GitHub
0

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

fix(s3): handle DeleteBucketReplication instead of deleting the whole bucket (#1837)

Marius Volkhart2d250ccf3cfc
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("""
+ <VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
+ <Status>Enabled</Status>
+ </VersioningConfiguration>
+ """)
+ .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"));
+ }
+}