mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix: return NoSuchVersion error for non-existent versionId
When requesting an object with a versionId that doesn't exist, S3 returns NoSuchVersion, not NoSuchKey. Updated getObject to distinguish between a missing key and a missing version. Fixes https://github.com/hectorvent/floci/issues/33
This commit is contained in:
2 files changed
+14
-1
No files matched your search
@@ -248,7 +248,9 @@ public class S3Service {
|
||||
}
|
||||
|
||||
S3Object obj = objectStore.get(storeKey)
|
||||
.orElseThrow(() -> new AwsException("NoSuchKey", "The specified key does not exist.", 404));
|
||||
.orElseThrow(() -> versionId != null
|
||||
? new AwsException("NoSuchVersion", "The specified version does not exist.", 404)
|
||||
: new AwsException("NoSuchKey", "The specified key does not exist.", 404));
|
||||
|
||||
if (obj.isDeleteMarker()) {
|
||||
throw new AwsException("NoSuchKey", "The specified key does not exist.", 404);
|
||||
|
||||
@@ -155,6 +155,17 @@ class S3VersioningServiceTest {
|
||||
assertTrue(versions.stream().anyMatch(S3Object::isDeleteMarker));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getObjectWithNonExistentVersionIdThrowsNoSuchVersion() {
|
||||
s3Service.putBucketVersioning("versioned-bucket", "Enabled");
|
||||
s3Service.putObject("versioned-bucket", "test.txt",
|
||||
"data".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
s3Service.getObject("versioned-bucket", "test.txt", "fake-version-id"));
|
||||
assertEquals("NoSuchVersion", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listObjectsExcludesDeleteMarkers() {
|
||||
s3Service.putBucketVersioning("versioned-bucket", "Enabled");
|
||||
|
||||
Reference in new issue
Block a user