Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(s3): return copy destination version id (#3669)

Aniket Shukla7d58be1d4f04
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.java
index a9f258e404..98c9df7d7b 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
@@ -2661,6 +2661,9 @@ public class S3Controller {
if (copy.getSseKmsKeyId() != null) {
response.header("x-amz-server-side-encryption-aws-kms-key-id", copy.getSseKmsKeyId());
}
+ if (copy.getVersionId() != null) {
+ response.header("x-amz-version-id", copy.getVersionId());
+ }
appendSseCustomerHeaders(response, copy);
return response.build();
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3CopyObjectVersionedIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3CopyObjectVersionedIntegrationTest.java
index fbe1b8ade5..ff19a43be7 100644
--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3CopyObjectVersionedIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3CopyObjectVersionedIntegrationTest.java
@@ -22,6 +22,8 @@ class S3CopyObjectVersionedIntegrationTest {
private static final String BUCKET = "copy-version-repro-it";
/** First object version id (after v1 upload, while still latest). */
private static String v1VersionId;
+ /** Version created by copying v1 back over the key. */
+ private static String copiedVersionId;
@Test
@Order(1)
@@ -78,19 +80,23 @@ class S3CopyObjectVersionedIntegrationTest {
@Test
@Order(6)
void copyObjectFromV1RestoresV1AsLatest() {
- given()
+ copiedVersionId = given()
.header("x-amz-copy-source", "/" + BUCKET + "/key?versionId=" + v1VersionId)
.when()
.put("/" + BUCKET + "/key")
.then()
.statusCode(200)
- .body(containsString("CopyObjectResult"));
+ .body(containsString("CopyObjectResult"))
+ .header("x-amz-version-id", notNullValue())
+ .extract()
+ .header("x-amz-version-id");
given()
.when()
.get("/" + BUCKET + "/key")
.then()
.statusCode(200)
+ .header("x-amz-version-id", equalTo(copiedVersionId))
.body(equalTo("v1"));
}
}