mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 14:30:28 -05:00
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
This commit is contained in:
1 parent
3ec4dc65f2
commit
2d250ccf3c
2 files changed
+92
No files matched your search
@@ -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) {
|
||||
|
||||
+86
@@ -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"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user