fix(s3): name the key and version in NoSuchVersion errors (#7155)

* fix(s3): name the key and version in NoSuchVersion errors

Every NoSuchVersion error names the key and the version id, and an
annotation request for a missing version answers NoSuchVersion
instead of NoSuchKey, as on S3.

* test(s3): check annotation put and delete and a missing key for NoSuchVersion
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-10-31 20:53:31 -04:00
1 parent c865784540
commit 48b19f76f3
5 files changed
+74 -16

No files matched your search

@@ -0,0 +1,57 @@
package io.github.hectorvent.floci.services.s3;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
import org.junit.jupiter.api.Test;
import java.util.List;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
@QuarkusTest
class S3NoSuchVersionIntegrationTest {
private static final String BUCKET = "no-such-version-names-it";
private static final String KEY = "dir/k.txt";
private static final String PATH = "/" + BUCKET + "/" + KEY;
@Test
void noSuchVersionNamesTheKeyAndTheVersion() {
given().when().put("/" + BUCKET).then().statusCode(200);
given().body("<VersioningConfiguration><Status>Enabled</Status></VersioningConfiguration>")
.when().put("/" + BUCKET + "?versioning").then().statusCode(200);
String gone = given().body("1").when().put(PATH).then().statusCode(200).extract().header("x-amz-version-id");
given().body("2").when().put(PATH).then().statusCode(200);
given().when().delete(PATH + "?versionId=" + gone).then().statusCode(204);
for (String key : List.of(KEY, "missing")) {
String path = "/" + BUCKET + "/" + key;
for (String versionId : List.of(gone, "null")) {
String version = "versionId=" + versionId;
missing(given().when().get(path + "?" + version), key, versionId);
missing(given().when().get(path + "?acl&" + version), key, versionId);
missing(given().header("x-amz-object-attributes", "ETag").when().get(path + "?attributes&" + version),
key, versionId);
missing(given().body("<Tagging><TagSet></TagSet></Tagging>").when().put(path + "?tagging&" + version),
key, versionId);
missing(given().when().delete(path + "?tagging&" + version), key, versionId);
missing(given().when().get(path + "?annotation&annotationName=labels&" + version), key, versionId);
missing(given().when().get(path + "?annotation&" + version), key, versionId);
missing(given().body("x").when().put(path + "?annotation&annotationName=labels&" + version),
key, versionId);
missing(given().when().delete(path + "?annotation&annotationName=labels&" + version), key, versionId);
missing(given().header("x-amz-copy-source", path + "?" + version).when().put("/" + BUCKET + "/copy"),
key, versionId);
// GetObjectTagging names the key with its bucket.
missing(given().when().get(path + "?tagging&" + version), BUCKET + "/" + key, versionId);
}
}
}
private static void missing(Response response, String key, String versionId) {
response.then().statusCode(404)
.body("Error.Code", equalTo("NoSuchVersion"))
.body("Error.Key", equalTo(key))
.body("Error.VersionId", equalTo(versionId));
}
}
@@ -234,7 +234,7 @@ class S3ServiceAnnotationsTest {
putAnnotation("version-bound", "payload");
String versionId = s3Service.getObject(BUCKET, "docs/readme.txt", null).getVersionId();
s3Service.deleteObject(BUCKET, "docs/readme.txt", versionId);
assertThrowsAws("NoSuchKey", () ->
assertThrowsAws("NoSuchVersion", () ->
s3Service.getObjectAnnotation(BUCKET, "docs/readme.txt", "version-bound", versionId));
}
@@ -627,8 +627,7 @@ class S3VersioningIntegrationTest {
given().queryParam("versionId", "null").header("x-amz-acl", "private")
.when().put(added + "?acl").then().statusCode(404).body(noSuchVersion);
given().queryParam("versionId", "null").queryParam("annotationName", "labels").body("x")
.when().put(added + "?annotation").then().statusCode(404)
.body(containsString("<Code>NoSuchKey</Code>"));
.when().put(added + "?annotation").then().statusCode(404).body(noSuchVersion);
given().header("x-amz-copy-source", "/" + bucket + "/new?versionId=null")
.when().put("/" + bucket + "/copy-of-new").then().statusCode(404).body(noSuchVersion);
given().when().get(added).then().statusCode(200).body(equalTo("new"));