Light, fluffy, and always free - The AWS Local Emulator alternative
fix(s3): return x-amz-version-id from presigned POST (#2608)
Ricky Rattlesnake066e6c904b4c
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.javaindex 0b89eb5b16..2393efd5be 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@@ -2711,10 +2711,13 @@ public class S3Controller {.elem("ETag", obj.getETag()).end("PostResponse").build();- return Response.status(204)+ var response = Response.status(204).header("ETag", obj.getETag())- .header("Location", bucket + "/" + key)- .build();+ .header("Location", bucket + "/" + key);+ if (obj.getVersionId() != null) {+ response.header("x-amz-version-id", obj.getVersionId());+ }+ return response.build();}private void validatePolicyConditions(String policyBase64, String bucket,diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3PresignedPostIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3PresignedPostIntegrationTest.javaindex b9d4663ff4..3d15dfc774 100644--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3PresignedPostIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3PresignedPostIntegrationTest.java@@ -21,6 +21,7 @@ import static org.hamcrest.Matchers.*;class S3PresignedPostIntegrationTest {private static final String BUCKET = "presigned-post-bucket";+ private static final String VERSIONED_BUCKET = "presigned-post-versioned-bucket";private static final DateTimeFormatter AMZ_DATE_FORMAT =DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'").withZone(ZoneOffset.UTC);@@ -672,4 +673,51 @@ class S3PresignedPostIntegrationTest {}""".formatted(expiration, bucket, keyPrefix, contentTypePrefix, minSize, maxSize);}++ @Test+ @Order(110)+ void presignedPostReturnsVersionIdOnAVersionedBucket() {+ given()+ .when()+ .put("/" + VERSIONED_BUCKET)+ .then()+ .statusCode(200);++ given()+ .body("<VersioningConfiguration><Status>Enabled</Status></VersioningConfiguration>")+ .when()+ .put("/" + VERSIONED_BUCKET + "?versioning")+ .then()+ .statusCode(200);++ String key = "uploads/versioned.txt";+ String contentType = "text/plain";+ String policy = buildPolicy(VERSIONED_BUCKET, key, contentType, 0, 10485760);+ String policyBase64 = Base64.getEncoder().encodeToString(policy.getBytes(StandardCharsets.UTF_8));++ String versionId =+ given()+ .multiPart("key", key)+ .multiPart("Content-Type", contentType)+ .multiPart("policy", policyBase64)+ .multiPart("x-amz-algorithm", "AWS4-HMAC-SHA256")+ .multiPart("x-amz-date", AMZ_DATE_FORMAT.format(Instant.now()))+ .multiPart("file", "versioned.txt",+ "Hello from a versioned presigned POST!".getBytes(StandardCharsets.UTF_8), contentType)+ .when()+ .post("/" + VERSIONED_BUCKET)+ .then()+ .statusCode(204)+ .extract()+ .header("x-amz-version-id");++ assertThat(versionId, is(notNullValue()));++ given()+ .when()+ .head("/" + VERSIONED_BUCKET + "/" + key)+ .then()+ .statusCode(200)+ .header("x-amz-version-id", is(versionId));+ }}