mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(s3): name delete markers in GET and HEAD errors and the key in NoSuchKey (#7149)
* fix(s3): answer a GET or HEAD that reaches a delete marker as S3 does A read of a key whose current version is a delete marker sends the marker's headers with the 404, and a versionId that names a delete marker is 405 MethodNotAllowed, as on S3. * fix(s3): name the key in NoSuchKey errors Every NoSuchKey error names the key in a Key element, and GetObjectTagging names it with its bucket, as on S3.
This commit is contained in:
1 parent
f77d032818
commit
0f94440442
6 files changed
+233
-15
No files matched your search
+110
@@ -0,0 +1,110 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
@QuarkusTest
|
||||
class S3DeleteMarkerReadIntegrationTest {
|
||||
private static final DateTimeFormatter HTTP_DATE = DateTimeFormatter
|
||||
.ofPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US)
|
||||
.withZone(ZoneOffset.UTC);
|
||||
|
||||
@Test
|
||||
void aReadOfTheCurrentDeleteMarkerIsAMissingKeyThatNamesTheMarker() {
|
||||
String bucket = createBucket("marker-read-current", "Enabled");
|
||||
given().body("data").when().put("/" + bucket + "/key").then().statusCode(200);
|
||||
String marker = deleteKey(bucket);
|
||||
|
||||
for (String method : List.of("GET", "HEAD")) {
|
||||
given().when().request(method, "/" + bucket + "/key").then().statusCode(404)
|
||||
.header("x-amz-delete-marker", "true")
|
||||
.header("x-amz-version-id", marker)
|
||||
.header("Last-Modified", nullValue())
|
||||
.header("Allow", nullValue());
|
||||
}
|
||||
given().header("Range", "bytes=0-0").when().get("/" + bucket + "/key").then().statusCode(404)
|
||||
.header("x-amz-delete-marker", "true")
|
||||
.header("x-amz-version-id", marker)
|
||||
.body("Error.Key", equalTo("key"));
|
||||
given().header("If-Match", "\"stale\"").when().get("/" + bucket + "/key").then().statusCode(404)
|
||||
.header("x-amz-delete-marker", "true")
|
||||
.header("x-amz-version-id", marker);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aReadThatNamesADeleteMarkerIsRefused() {
|
||||
String bucket = createBucket("marker-read-named", "Enabled");
|
||||
given().body("data").when().put("/" + bucket + "/key").then().statusCode(200);
|
||||
String marker = deleteKey(bucket);
|
||||
String lastModified = markerLastModified(bucket);
|
||||
|
||||
assertRefused(bucket, marker, lastModified);
|
||||
given().body("again").when().put("/" + bucket + "/key").then().statusCode(200);
|
||||
assertRefused(bucket, marker, lastModified);
|
||||
}
|
||||
|
||||
@Test
|
||||
void theNullDeleteMarkerOfASuspendedBucketIsNamedNull() {
|
||||
String bucket = createBucket("marker-read-null", "Suspended");
|
||||
given().body("data").when().put("/" + bucket + "/key").then().statusCode(200);
|
||||
deleteKey(bucket);
|
||||
|
||||
given().when().get("/" + bucket + "/key").then().statusCode(404)
|
||||
.header("x-amz-delete-marker", "true")
|
||||
.header("x-amz-version-id", "null");
|
||||
assertRefused(bucket, "null", markerLastModified(bucket));
|
||||
}
|
||||
|
||||
private static void assertRefused(String bucket, String versionId, String lastModified) {
|
||||
String path = "/" + bucket + "/key?versionId=" + versionId;
|
||||
given().when().get(path).then().statusCode(405)
|
||||
.header("x-amz-delete-marker", "true")
|
||||
.header("x-amz-version-id", versionId)
|
||||
.header("Last-Modified", lastModified)
|
||||
.header("Allow", "DELETE")
|
||||
.body(allOf(containsString("<Code>MethodNotAllowed</Code>"),
|
||||
containsString("<Method>GET</Method>"),
|
||||
containsString("<ResourceType>DeleteMarker</ResourceType>"),
|
||||
not(containsString("<Key>"))));
|
||||
given().when().head(path).then().statusCode(405)
|
||||
.header("x-amz-delete-marker", "true")
|
||||
.header("x-amz-version-id", versionId)
|
||||
.header("Last-Modified", lastModified)
|
||||
.header("Allow", "DELETE");
|
||||
given().when().get(path + "&partNumber=1").then().statusCode(405)
|
||||
.header("x-amz-version-id", versionId);
|
||||
}
|
||||
|
||||
private static String createBucket(String bucket, String versioning) {
|
||||
given().when().put("/" + bucket).then().statusCode(200);
|
||||
given().body("<VersioningConfiguration><Status>" + versioning + "</Status></VersioningConfiguration>")
|
||||
.when().put("/" + bucket + "?versioning").then().statusCode(200);
|
||||
return bucket;
|
||||
}
|
||||
|
||||
private static String deleteKey(String bucket) {
|
||||
return given().when().delete("/" + bucket + "/key").then().statusCode(204)
|
||||
.header("x-amz-delete-marker", "true")
|
||||
.extract().header("x-amz-version-id");
|
||||
}
|
||||
|
||||
private static String markerLastModified(String bucket) {
|
||||
String listed = given().queryParam("versions", "").queryParam("prefix", "key").when().get("/" + bucket)
|
||||
.then().statusCode(200)
|
||||
.extract().xmlPath().getString("ListVersionsResult.DeleteMarker.LastModified");
|
||||
return HTTP_DATE.format(Instant.parse(listed));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class S3NoSuchKeyIntegrationTest {
|
||||
private static final String BUCKET = "no-such-key-names-the-key";
|
||||
private static final String KEY = "dir/missing.txt";
|
||||
private static final String PATH = "/" + BUCKET + "/" + KEY;
|
||||
|
||||
@Test
|
||||
void noSuchKeyNamesTheKey() {
|
||||
given().when().put("/" + BUCKET).then().statusCode(200);
|
||||
|
||||
given().when().get(PATH).then().statusCode(404)
|
||||
.body("Error.Code", equalTo("NoSuchKey"))
|
||||
.body("Error.Key", equalTo(KEY));
|
||||
given().when().get(PATH + "?acl").then().statusCode(404).body("Error.Key", equalTo(KEY));
|
||||
given().header("x-amz-object-attributes", "ETag").when().get(PATH + "?attributes")
|
||||
.then().statusCode(404).body("Error.Key", equalTo(KEY));
|
||||
given().body("<Tagging><TagSet></TagSet></Tagging>").when().put(PATH + "?tagging")
|
||||
.then().statusCode(404).body("Error.Key", equalTo(KEY));
|
||||
given().when().delete(PATH + "?tagging").then().statusCode(404).body("Error.Key", equalTo(KEY));
|
||||
given().when().get(PATH + "?annotation&annotationName=labels")
|
||||
.then().statusCode(404).body("Error.Key", equalTo(KEY));
|
||||
given().header("If-Match", "*").when().delete(PATH).then().statusCode(404).body("Error.Key", equalTo(KEY));
|
||||
given().header("x-amz-copy-source", PATH).when().put("/" + BUCKET + "/copy")
|
||||
.then().statusCode(404).body("Error.Key", equalTo(KEY));
|
||||
// GetObjectTagging names the key with its bucket.
|
||||
given().when().get(PATH + "?tagging").then().statusCode(404).body("Error.Key", equalTo(BUCKET + "/" + KEY));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user