mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
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:
1 parent
c865784540
commit
48b19f76f3
5 files changed
+74
-16
No files matched your search
@@ -3752,11 +3752,12 @@ public class S3Controller {
|
||||
// S3 InvalidArgument responses carry ArgumentName and ArgumentValue so the SDK can
|
||||
// surface which input was rejected, and EntityTooSmall and EntityTooLarge the proposed and
|
||||
// allowed sizes. Multipart size errors also identify the rejected part, MethodNotAllowed
|
||||
// the method and the kind of resource that refused it, and NoSuchKey the key.
|
||||
// the method and the kind of resource that refused it, and NoSuchKey and NoSuchVersion
|
||||
// the key and version that are missing.
|
||||
// They travel through AwsException.extendedData.
|
||||
if (e.getExtendedData() != null) {
|
||||
for (String field : List.of("Key", "Method", "ResourceType", "ProposedSize", "MinSizeAllowed",
|
||||
"MaxSizeAllowed", "PartNumber", "ETag")) {
|
||||
for (String field : List.of("Key", "VersionId", "Method", "ResourceType", "ProposedSize",
|
||||
"MinSizeAllowed", "MaxSizeAllowed", "PartNumber", "ETag")) {
|
||||
Object value = e.getExtendedData().get(field);
|
||||
if (value != null) {
|
||||
xmlBuilder.elem(field, value.toString());
|
||||
|
||||
@@ -1923,8 +1923,7 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
String accountId = ownedBucket.account();
|
||||
for (int attempt = 0; attempt < 10_000; attempt++) {
|
||||
StoredVersion stored = findStoredVersionForAccount(accountId, bucketName, key, "null")
|
||||
.orElseThrow(() -> new AwsException(
|
||||
"NoSuchVersion", "The specified version does not exist.", 404));
|
||||
.orElseThrow(() -> noSuchVersion(key, "null"));
|
||||
if (stored.object().isDeleteMarker()) {
|
||||
throw new S3DeleteMarkerException(stored.object());
|
||||
}
|
||||
@@ -2221,9 +2220,7 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
"The specified bucket does not exist.", 404));
|
||||
|
||||
S3Object object = findStoredObject(ownedBucket, bucketName, key, versionId)
|
||||
.orElseThrow(() -> versionId != null
|
||||
? new AwsException("NoSuchVersion", "The specified version does not exist.", 404)
|
||||
: noSuchKey(key));
|
||||
.orElseThrow(() -> versionId != null ? noSuchVersion(key, versionId) : noSuchKey(key));
|
||||
if (object.isDeleteMarker()) {
|
||||
throw new S3DeleteMarkerException(object);
|
||||
}
|
||||
@@ -2234,6 +2231,11 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
return new AwsException("NoSuchKey", "The specified key does not exist.", 404, Map.of("Key", key));
|
||||
}
|
||||
|
||||
private static AwsException noSuchVersion(String key, String versionId) {
|
||||
return new AwsException("NoSuchVersion", "The specified version does not exist.", 404,
|
||||
Map.of("Key", key, "VersionId", versionId));
|
||||
}
|
||||
|
||||
/** The stored version {@code versionId} names, the current one when it is null, delete markers included. */
|
||||
private Optional<S3Object> findStoredObject(AccountAwareStorageBackend.OwnedEntry<Bucket> ownedBucket,
|
||||
String bucketName, String key, String versionId) {
|
||||
@@ -3372,12 +3374,11 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
AccountAwareStorageBackend.OwnedEntry<Bucket> ownedBucket = resolveBucketEntry(bucketName)
|
||||
.orElseThrow(() -> new AwsException("NoSuchBucket",
|
||||
"The specified bucket does not exist.", 404));
|
||||
// GetObjectTagging names the key with its bucket.
|
||||
String namedKey = "GET".equals(method) ? bucketName + "/" + key : key;
|
||||
S3Object object = findStoredVersionForAccount(ownedBucket.account(), bucketName, key, versionId)
|
||||
.map(StoredVersion::object)
|
||||
.orElseThrow(() -> versionId != null
|
||||
? new AwsException("NoSuchVersion", "The specified version does not exist.", 404)
|
||||
// GetObjectTagging names the key with its bucket.
|
||||
: noSuchKey("GET".equals(method) ? bucketName + "/" + key : key));
|
||||
.orElseThrow(() -> versionId != null ? noSuchVersion(namedKey, versionId) : noSuchKey(namedKey));
|
||||
if (object.isDeleteMarker()) {
|
||||
throw new AwsException("MethodNotAllowed",
|
||||
"The specified method is not allowed against this resource.", 405,
|
||||
@@ -3629,7 +3630,7 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
private S3Object resolveParentObject(String bucketName, String key, String versionId) {
|
||||
S3Object object = findStoredVersion(bucketName, key, versionId)
|
||||
.map(StoredVersion::object)
|
||||
.orElseThrow(() -> noSuchKey(key));
|
||||
.orElseThrow(() -> versionId != null ? noSuchVersion(key, versionId) : noSuchKey(key));
|
||||
if (object.isDeleteMarker()) {
|
||||
throw noSuchKey(key);
|
||||
}
|
||||
|
||||
+57
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -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"));
|
||||
|
||||
Reference in new issue
Block a user