mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(s3): parse copy-source versionId for CopyObject and part copy iss… (#751)
* fix(s3): parse copy-source versionId for CopyObject and part copy issue-748 * fix(s3): support versionId in CopyObject and UploadPartCopy sources - issue-748 * fix(s3): added new line at the end of class S3Controller - issue-748
This commit is contained in:
1 parent
2bed9ec3ad
commit
ce2012de45
5 files changed
+364
-48
No files matched your search
+96
@@ -0,0 +1,96 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
/**
|
||||
* Mirrors the AWS CLI flow: versioned bucket, two puts, CopyObject with
|
||||
* {@code x-amz-copy-source: /bucket/key?versionId=} to restore an older version as the latest.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
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;
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createBucket() {
|
||||
given().when().put("/" + BUCKET).then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void enableVersioning() {
|
||||
String xml = "<VersioningConfiguration><Status>Enabled</Status></VersioningConfiguration>";
|
||||
given().body(xml).when().put("/" + BUCKET + "?versioning").then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void uploadVersion1AndCaptureVersionId() {
|
||||
v1VersionId = given()
|
||||
.contentType("text/plain")
|
||||
.body("v1")
|
||||
.when()
|
||||
.put("/" + BUCKET + "/key")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-version-id", notNullValue())
|
||||
.extract()
|
||||
.header("x-amz-version-id");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void uploadVersion2() {
|
||||
given()
|
||||
.contentType("text/plain")
|
||||
.body("v2")
|
||||
.when()
|
||||
.put("/" + BUCKET + "/key")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-version-id", notNullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void latestIsVersion2BeforeCopy() {
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET + "/key")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(equalTo("v2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void copyObjectFromV1RestoresV1AsLatest() {
|
||||
given()
|
||||
.header("x-amz-copy-source", "/" + BUCKET + "/key?versionId=" + v1VersionId)
|
||||
.when()
|
||||
.put("/" + BUCKET + "/key")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("CopyObjectResult"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET + "/key")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(equalTo("v1"));
|
||||
}
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
/**
|
||||
* UploadPartCopy with {@code x-amz-copy-source} including {@code ?versionId=...} reads the matching
|
||||
* object version bytes (same contract as CopyObject).
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class S3UploadPartCopyVersionedIntegrationTest {
|
||||
|
||||
private static final String BUCKET = "upload-part-copy-ver-it";
|
||||
private static final String SRC_KEY = "versioned-mp-source.txt";
|
||||
private static final String DEST_KEY = "versioned-mp-dest.bin";
|
||||
private static String sourceV1VersionId;
|
||||
private static String uploadId;
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createBucketAndVersioning() {
|
||||
given().when().put("/" + BUCKET).then().statusCode(200);
|
||||
|
||||
String xml = "<VersioningConfiguration><Status>Enabled</Status></VersioningConfiguration>";
|
||||
given().body(xml).when().put("/" + BUCKET + "?versioning").then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void putSourceVersion1CaptureVersionId() {
|
||||
sourceV1VersionId = given()
|
||||
.contentType("text/plain")
|
||||
.body("version-one-body")
|
||||
.when()
|
||||
.put("/" + BUCKET + "/" + SRC_KEY)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-version-id", notNullValue())
|
||||
.extract()
|
||||
.header("x-amz-version-id");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void overwriteSourceVersion2() {
|
||||
given()
|
||||
.contentType("text/plain")
|
||||
.body("version-two-body")
|
||||
.when()
|
||||
.put("/" + BUCKET + "/" + SRC_KEY)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-version-id", notNullValue());
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET + "/" + SRC_KEY)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(equalTo("version-two-body"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void initiateMultipartDest() {
|
||||
uploadId = given()
|
||||
.when()
|
||||
.post("/" + BUCKET + "/" + DEST_KEY + "?uploads")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<UploadId>"))
|
||||
.extract()
|
||||
.xmlPath()
|
||||
.getString("InitiateMultipartUploadResult.UploadId");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void uploadPartCopyUsesOlderVersion() {
|
||||
given()
|
||||
.header("x-amz-copy-source", "/" + BUCKET + "/" + SRC_KEY + "?versionId=" + sourceV1VersionId)
|
||||
.when()
|
||||
.put("/" + BUCKET + "/" + DEST_KEY + "?uploadId=" + uploadId + "&partNumber=1")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<CopyPartResult"))
|
||||
.body(containsString("<ETag>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void completeAndVerifyBodyFromVersion1() {
|
||||
String completeXml = """
|
||||
<CompleteMultipartUpload>
|
||||
<Part><PartNumber>1</PartNumber><ETag>placeholder</ETag></Part>
|
||||
</CompleteMultipartUpload>""";
|
||||
|
||||
given()
|
||||
.contentType("application/xml")
|
||||
.body(completeXml)
|
||||
.when()
|
||||
.post("/" + BUCKET + "/" + DEST_KEY + "?uploadId=" + uploadId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<CompleteMultipartUploadResult"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET + "/" + DEST_KEY)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(equalTo("version-one-body"));
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.s3.model.CopyObjectOptions;
|
||||
import io.github.hectorvent.floci.services.s3.model.S3Object;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -168,6 +169,22 @@ class S3VersioningServiceTest {
|
||||
assertEquals("NoSuchVersion", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void copyObjectFromOlderVersionRestoresThatContentAsLatest() {
|
||||
s3Service.putBucketVersioning("versioned-bucket", "Enabled");
|
||||
S3Object v1 = s3Service.putObject("versioned-bucket", "key",
|
||||
"v1".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
s3Service.putObject("versioned-bucket", "key",
|
||||
"v2".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
|
||||
assertEquals("v2", new String(s3Service.getObject("versioned-bucket", "key").getData()));
|
||||
|
||||
s3Service.copyObject("versioned-bucket", "key", "versioned-bucket", "key",
|
||||
v1.getVersionId(), new CopyObjectOptions());
|
||||
|
||||
assertEquals("v1", new String(s3Service.getObject("versioned-bucket", "key").getData()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void versionedFileUsesS3dataSuffixOnDisk() {
|
||||
S3Service diskService = new S3Service(new InMemoryStorage<>(), new InMemoryStorage<>(), tempDir, false);
|
||||
|
||||
Reference in new issue
Block a user