mirror of
https://github.com/floci-io/floci.git
synced 2026-12-02 01:43:02 -05:00
fix(s3): validate FULL_OBJECT checksum on CompleteMultipartUpload (#1980)
* fix(s3): validate FULL_OBJECT checksum on CompleteMultipartUpload * fix(s3): align FULL_OBJECT checksum validation with AWS's CRC-only support - Reject SHA1/SHA256 combined with ChecksumType=FULL_OBJECT on multipart completion with InvalidRequest, since AWS only supports full-object checksums for CRC32/CRC32C/CRC64NVME (SHA is composite-only). - Report ChecksumType=FULL_OBJECT instead of COMPOSITE once a requested full-object checksum has been validated. - Abort the multipart upload left dangling by the mismatched-checksum test, and add regression coverage for both fixes above.
This commit is contained in:
1 parent
fa9ed9100e
commit
d039780e3a
4 files changed
+214
-9
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.github.hectorvent.floci.services.s3.model.S3Checksum;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
@@ -559,6 +560,176 @@ class S3MultipartIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
void completeMultipartUploadRejectsMismatchedFullObjectChecksum() {
|
||||
String key = "checksum-mismatch-multipart.bin";
|
||||
String newUploadId = given()
|
||||
.header("x-amz-checksum-algorithm", "CRC32")
|
||||
.when()
|
||||
.post("/" + BUCKET + "/" + key + "?uploads")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().xmlPath().getString("InitiateMultipartUploadResult.UploadId");
|
||||
|
||||
given()
|
||||
.body("Part1Data-Hello")
|
||||
.when()
|
||||
.put("/" + BUCKET + "/" + key + "?uploadId=" + newUploadId + "&partNumber=1")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
String completeXml = """
|
||||
<CompleteMultipartUpload>
|
||||
<Part><PartNumber>1</PartNumber><ETag>etag1</ETag></Part>
|
||||
</CompleteMultipartUpload>""";
|
||||
|
||||
given()
|
||||
.contentType("application/xml")
|
||||
.header("x-amz-checksum-type", "FULL_OBJECT")
|
||||
.header("x-amz-checksum-crc32", "AAAAAA==")
|
||||
.body(completeXml)
|
||||
.when()
|
||||
.post("/" + BUCKET + "/" + key + "?uploadId=" + newUploadId)
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("BadDigest"));
|
||||
|
||||
// The checksum mismatch rejects completion before the upload is consumed, so abort it explicitly.
|
||||
given()
|
||||
.when()
|
||||
.delete("/" + BUCKET + "/" + key + "?uploadId=" + newUploadId)
|
||||
.then()
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(21)
|
||||
void completeMultipartUploadAcceptsMatchingFullObjectChecksum() {
|
||||
String key = "checksum-match-multipart.bin";
|
||||
String data = "Part1Data-Hello";
|
||||
String correctCrc32 = S3Checksum.crc32Base64(data.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
String newUploadId = given()
|
||||
.header("x-amz-checksum-algorithm", "CRC32")
|
||||
.when()
|
||||
.post("/" + BUCKET + "/" + key + "?uploads")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().xmlPath().getString("InitiateMultipartUploadResult.UploadId");
|
||||
|
||||
given()
|
||||
.body(data)
|
||||
.when()
|
||||
.put("/" + BUCKET + "/" + key + "?uploadId=" + newUploadId + "&partNumber=1")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
String completeXml = """
|
||||
<CompleteMultipartUpload>
|
||||
<Part><PartNumber>1</PartNumber><ETag>etag1</ETag></Part>
|
||||
</CompleteMultipartUpload>""";
|
||||
|
||||
given()
|
||||
.contentType("application/xml")
|
||||
.header("x-amz-checksum-type", "FULL_OBJECT")
|
||||
.header("x-amz-checksum-crc32", correctCrc32)
|
||||
.body(completeXml)
|
||||
.when()
|
||||
.post("/" + BUCKET + "/" + key + "?uploadId=" + newUploadId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<CompleteMultipartUploadResult"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(22)
|
||||
void completeMultipartUploadRejectsFullObjectShaChecksum() {
|
||||
String key = "checksum-sha-full-object-multipart.bin";
|
||||
String newUploadId = given()
|
||||
.header("x-amz-checksum-algorithm", "SHA256")
|
||||
.when()
|
||||
.post("/" + BUCKET + "/" + key + "?uploads")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().xmlPath().getString("InitiateMultipartUploadResult.UploadId");
|
||||
|
||||
given()
|
||||
.body("Part1Data-Hello")
|
||||
.when()
|
||||
.put("/" + BUCKET + "/" + key + "?uploadId=" + newUploadId + "&partNumber=1")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
String completeXml = """
|
||||
<CompleteMultipartUpload>
|
||||
<Part><PartNumber>1</PartNumber><ETag>etag1</ETag></Part>
|
||||
</CompleteMultipartUpload>""";
|
||||
|
||||
given()
|
||||
.contentType("application/xml")
|
||||
.header("x-amz-checksum-type", "FULL_OBJECT")
|
||||
.header("x-amz-checksum-sha256", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")
|
||||
.body(completeXml)
|
||||
.when()
|
||||
.post("/" + BUCKET + "/" + key + "?uploadId=" + newUploadId)
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("InvalidRequest"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.delete("/" + BUCKET + "/" + key + "?uploadId=" + newUploadId)
|
||||
.then()
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(23)
|
||||
void completeMultipartUploadReportsFullObjectChecksumType() {
|
||||
String key = "checksum-type-multipart.bin";
|
||||
String data = "Part1Data-Hello";
|
||||
String correctCrc32 = S3Checksum.crc32Base64(data.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
String newUploadId = given()
|
||||
.header("x-amz-checksum-algorithm", "CRC32")
|
||||
.when()
|
||||
.post("/" + BUCKET + "/" + key + "?uploads")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().xmlPath().getString("InitiateMultipartUploadResult.UploadId");
|
||||
|
||||
given()
|
||||
.body(data)
|
||||
.when()
|
||||
.put("/" + BUCKET + "/" + key + "?uploadId=" + newUploadId + "&partNumber=1")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
String completeXml = """
|
||||
<CompleteMultipartUpload>
|
||||
<Part><PartNumber>1</PartNumber><ETag>etag1</ETag></Part>
|
||||
</CompleteMultipartUpload>""";
|
||||
|
||||
given()
|
||||
.contentType("application/xml")
|
||||
.header("x-amz-checksum-type", "FULL_OBJECT")
|
||||
.header("x-amz-checksum-crc32", correctCrc32)
|
||||
.body(completeXml)
|
||||
.when()
|
||||
.post("/" + BUCKET + "/" + key + "?uploadId=" + newUploadId)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("x-amz-object-attributes", "Checksum")
|
||||
.when()
|
||||
.get("/" + BUCKET + "/" + key + "?attributes")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<ChecksumType>FULL_OBJECT</ChecksumType>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(24)
|
||||
void cleanUp() {
|
||||
given().when().delete("/" + BUCKET + "/" + KEY).then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET + "/tagged-multipart.bin").then().statusCode(204);
|
||||
@@ -566,6 +737,8 @@ class S3MultipartIntegrationTest {
|
||||
given().when().delete("/" + BUCKET + "/copy-dest.bin").then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET + "/sse-c-multipart.bin").then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET + "/sse-c-source-for-copy.bin").then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET + "/checksum-match-multipart.bin").then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET + "/checksum-type-multipart.bin").then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET).then().statusCode(204);
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ class S3MultipartServiceTest {
|
||||
s3Service.uploadPart("test-bucket", "file.bin", upload.getUploadId(), 2, "part2".getBytes());
|
||||
|
||||
S3Object result = s3Service.completeMultipartUpload("test-bucket", "file.bin",
|
||||
upload.getUploadId(), List.of(1, 2));
|
||||
upload.getUploadId(), List.of(1, 2), null, null);
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals("text/plain", result.getContentType());
|
||||
@@ -101,7 +101,7 @@ class S3MultipartServiceTest {
|
||||
Map.of("token", "abc-123", "teamId", "42"));
|
||||
s3Service.uploadPart("test-bucket", "tagged.bin", upload.getUploadId(), 1, "part1".getBytes());
|
||||
|
||||
s3Service.completeMultipartUpload("test-bucket", "tagged.bin", upload.getUploadId(), List.of(1));
|
||||
s3Service.completeMultipartUpload("test-bucket", "tagged.bin", upload.getUploadId(), List.of(1), null, null);
|
||||
|
||||
Map<String, String> tags = s3Service.getObjectTagging("test-bucket", "tagged.bin");
|
||||
assertEquals(2, tags.size());
|
||||
@@ -114,7 +114,7 @@ class S3MultipartServiceTest {
|
||||
MultipartUpload upload = s3Service.initiateMultipartUpload("test-bucket", "untagged.bin", null);
|
||||
s3Service.uploadPart("test-bucket", "untagged.bin", upload.getUploadId(), 1, "part1".getBytes());
|
||||
|
||||
s3Service.completeMultipartUpload("test-bucket", "untagged.bin", upload.getUploadId(), List.of(1));
|
||||
s3Service.completeMultipartUpload("test-bucket", "untagged.bin", upload.getUploadId(), List.of(1), null, null);
|
||||
|
||||
assertTrue(s3Service.getObjectTagging("test-bucket", "untagged.bin").isEmpty());
|
||||
}
|
||||
@@ -126,7 +126,7 @@ class S3MultipartServiceTest {
|
||||
|
||||
assertThrows(AwsException.class, () ->
|
||||
s3Service.completeMultipartUpload("test-bucket", "file.bin",
|
||||
upload.getUploadId(), List.of(1, 2)));
|
||||
upload.getUploadId(), List.of(1, 2), null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -163,7 +163,7 @@ class S3MultipartServiceTest {
|
||||
s3Service.uploadPart("test-bucket", "versioned.bin", upload.getUploadId(), 1, "data".getBytes());
|
||||
|
||||
S3Object result = s3Service.completeMultipartUpload("test-bucket", "versioned.bin",
|
||||
upload.getUploadId(), List.of(1));
|
||||
upload.getUploadId(), List.of(1), null, null);
|
||||
|
||||
assertNotNull(result.getVersionId(), "Versioned bucket should produce a versionId");
|
||||
}
|
||||
@@ -172,7 +172,7 @@ class S3MultipartServiceTest {
|
||||
void completeMultipartUploadCleansUp() {
|
||||
MultipartUpload upload = s3Service.initiateMultipartUpload("test-bucket", "file.bin", null);
|
||||
s3Service.uploadPart("test-bucket", "file.bin", upload.getUploadId(), 1, "data".getBytes());
|
||||
s3Service.completeMultipartUpload("test-bucket", "file.bin", upload.getUploadId(), List.of(1));
|
||||
s3Service.completeMultipartUpload("test-bucket", "file.bin", upload.getUploadId(), List.of(1), null, null);
|
||||
|
||||
// Should no longer be in active uploads
|
||||
List<MultipartUpload> uploads = s3Service.listMultipartUploads("test-bucket");
|
||||
@@ -184,7 +184,7 @@ class S3MultipartServiceTest {
|
||||
MultipartUpload upload = s3Service.initiateMultipartUpload("test-bucket", "parts.bin", "application/octet-stream");
|
||||
s3Service.uploadPart("test-bucket", "parts.bin", upload.getUploadId(), 1, "abc".getBytes(StandardCharsets.UTF_8));
|
||||
s3Service.uploadPart("test-bucket", "parts.bin", upload.getUploadId(), 2, "def".getBytes(StandardCharsets.UTF_8));
|
||||
s3Service.completeMultipartUpload("test-bucket", "parts.bin", upload.getUploadId(), List.of(1, 2));
|
||||
s3Service.completeMultipartUpload("test-bucket", "parts.bin", upload.getUploadId(), List.of(1, 2), null, null);
|
||||
|
||||
GetObjectAttributesResult attributes = s3Service.getObjectAttributes("test-bucket", "parts.bin", null,
|
||||
Set.of(ObjectAttributeName.OBJECT_PARTS, ObjectAttributeName.CHECKSUM),
|
||||
|
||||
Reference in new issue
Block a user