Light, fluffy, and always free - The AWS Local Emulator alternative
fix(s3): DeleteObjects honours empty key list (#2201)
Krishnan Mahadevan15d6ce8429ad
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.javaindex e5cfd05437..af1c0405e5 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@@ -1237,6 +1237,10 @@ public class S3Controller {private Response handleDeleteObjects(String bucket, byte[] body) {String xml = new String(body, StandardCharsets.UTF_8);List<String> keys = XmlParser.extractAll(xml, "Key");+ if (keys.isEmpty()) {+ throw new AwsException("MalformedXML",+ "The XML you provided was not well-formed.", 400);+ }boolean quiet = XmlParser.containsValue(xml, "Quiet", "true");S3Service.DeleteObjectsResult result = s3Service.deleteObjects(bucket, keys);diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3DeleteObjectsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3DeleteObjectsIntegrationTest.javanew file mode 100644index 0000000000..589e729e83--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3DeleteObjectsIntegrationTest.java@@ -0,0 +1,74 @@+package io.github.hectorvent.floci.services.s3;++import io.quarkus.test.junit.QuarkusTest;+import org.junit.jupiter.api.Test;++import java.util.UUID;++import static io.restassured.RestAssured.given;+import static org.hamcrest.Matchers.containsString;++@QuarkusTest+class S3DeleteObjectsIntegrationTest {++ @Test+ void deleteObjects_emptyKeyList_returnsMalformedXml() {+ String bucket = createBucket();++ given()+ .contentType("application/xml")+ .body("<Delete><Quiet>true</Quiet></Delete>")+ .when()+ .post("/" + bucket + "?delete")+ .then()+ .statusCode(400)+ .body(containsString("<Code>MalformedXML</Code>"));+ }++ @Test+ void deleteObjects_withKeys_deletesAndReportsResult() {+ String bucket = createBucket();+ putObject(bucket, "keep.txt");+ putObject(bucket, "remove.txt");++ given()+ .contentType("application/xml")+ .body("<Delete><Object><Key>remove.txt</Key></Object></Delete>")+ .when()+ .post("/" + bucket + "?delete")+ .then()+ .statusCode(200)+ .body(containsString("<Key>remove.txt</Key>"));++ given()+ .when()+ .get("/" + bucket + "/remove.txt")+ .then()+ .statusCode(404);++ given()+ .when()+ .get("/" + bucket + "/keep.txt")+ .then()+ .statusCode(200);+ }++ private static String createBucket() {+ String bucket = "delete-objects-" + UUID.randomUUID().toString().substring(0, 8);+ given()+ .when()+ .put("/" + bucket)+ .then()+ .statusCode(200);+ return bucket;+ }++ private static void putObject(String bucket, String key) {+ given()+ .body("content")+ .when()+ .put("/" + bucket + "/" + key)+ .then()+ .statusCode(200);+ }+}