fix(s3): omit checksum headers from GetObject/HeadObject unless x-amz-checksum-mode: ENABLED (#1633)

* fix(s3): omit checksum headers from GetObject/HeadObject unless x-amz-checksum-mode: ENABLED

Real AWS only returns x-amz-checksum-* headers on GetObject and HeadObject
responses when the client sends x-amz-checksum-mode: ENABLED. Without that
header, returning the checksum causes the PHP AWS SDK to attempt checksum
validation on a non-seekable streaming response body, throwing
"Stream is not seekable" and making fopen fail.

Closes #1632

* refactor(s3): drop dead appendObjectHeaders overloads, dedupe test @Order

Addresses Greptile review on PR #1633:

- Remove the now-unreachable 2-arg and 3-arg appendObjectHeaders overloads.
  All real callers pass includeChecksum explicitly to the 4-arg version, so the
  3-arg overload's hard-coded `true` was a footgun that could silently re-emit
  checksum headers. Also drops the now-orphaned ResponseHeaderOverrides.NONE.
- Move getObjectWithChecksumModeReturnsChecksum / headObjectWithChecksumMode...
  to the end of the 5-22 test block with unique @Order(23)/@Order(24), so they
  no longer share @Order(5)/@Order(7) with getObject/headObject.

All 117 S3IntegrationTest cases pass.

* fix(s3): include checksum in empty-object suffix-range response when requested

The empty-object suffix-range path returns a full 200 via fullObjectResponse
instead of a 206, so it must honor x-amz-checksum-mode: ENABLED like any
other full-object response. It previously hardcoded includeChecksum=false,
omitting the checksum even when the client asked for it.

Also extends the existing suffix-range test to assert the checksum is
omitted without the header, and adds a new test covering the
x-amz-checksum-mode: ENABLED case.

* fix(s3): resolve rebase-onto-main test conflicts for checksum-mode gate

Sends x-amz-checksum-mode: ENABLED on the GetObject verification calls
that require checksum headers in the response (copyObject,
copyObjectWithoutChecksumOverride, copyObjectPreservesNonDefaultChecksum),
consistent with the behavioral fix in this branch. Adds
getObjectWithChecksumModeReturnsChecksum and
headObjectWithChecksumModeReturnsChecksum as self-contained tests with
unique, non-colliding @Order values.

---------

Co-authored-by: Mihai Blidaru <mihai.blidaru@lynxfctech.com>
This commit is contained in:
Mihai BlidaruandMihai Blidaru authored and GitHub committed 2026-07-10 23:12:43 -05:00
1 parent cd7370c730
commit 48f310b63f
2 files changed
+106 -19

No files matched your search

@@ -87,7 +87,7 @@ class S3IntegrationTest {
.header("Content-Length", notNullValue())
.header("x-amz-meta-owner", equalTo("team-a"))
.header("x-amz-storage-class", equalTo("STANDARD_IA"))
.header("x-amz-checksum-crc64nvme", notNullValue())
.header("x-amz-checksum-crc64nvme", nullValue())
.body(equalTo("Hello World from S3!"));
}
@@ -118,7 +118,7 @@ class S3IntegrationTest {
.header("Content-Length", notNullValue())
.header("x-amz-meta-owner", equalTo("team-a"))
.header("x-amz-storage-class", equalTo("STANDARD_IA"))
.header("x-amz-checksum-crc64nvme", notNullValue());
.header("x-amz-checksum-crc64nvme", nullValue());
}
@Test
@@ -204,6 +204,7 @@ class S3IntegrationTest {
// Verify the copy
given()
.header("x-amz-checksum-mode", "ENABLED")
.when()
.get("/test-bucket/greeting-copy.txt")
.then()
@@ -241,6 +242,7 @@ class S3IntegrationTest {
// Verify the copy inherits the source checksum (CRC64NVME)
given()
.header("x-amz-checksum-mode", "ENABLED")
.when()
.get("/test-bucket/greeting-copy-no-override.txt")
.then()
@@ -274,6 +276,7 @@ class S3IntegrationTest {
// Verify the source object has a SHA256 checksum
given()
.header("x-amz-checksum-mode", "ENABLED")
.when()
.get("/test-bucket/sha256-source.txt")
.then()
@@ -293,6 +296,7 @@ class S3IntegrationTest {
// Verify the copy preserves the source's SHA256 checksum
given()
.header("x-amz-checksum-mode", "ENABLED")
.when()
.get("/test-bucket/sha256-copy.txt")
.then()
@@ -532,6 +536,62 @@ class S3IntegrationTest {
given().delete("/large-object-bucket");
}
@Test
@Order(118)
void getObjectWithChecksumModeReturnsChecksum() {
given()
.when()
.put("/checksum-mode-bucket")
.then()
.statusCode(200);
given()
.body("Hello World from S3!")
.when()
.put("/checksum-mode-bucket/greeting.txt")
.then()
.statusCode(200);
given()
.header("x-amz-checksum-mode", "ENABLED")
.when()
.get("/checksum-mode-bucket/greeting.txt")
.then()
.statusCode(200)
.header("x-amz-checksum-crc64nvme", notNullValue());
given().delete("/checksum-mode-bucket/greeting.txt");
given().delete("/checksum-mode-bucket");
}
@Test
@Order(119)
void headObjectWithChecksumModeReturnsChecksum() {
given()
.when()
.put("/checksum-mode-head-bucket")
.then()
.statusCode(200);
given()
.body("Hello World from S3!")
.when()
.put("/checksum-mode-head-bucket/greeting.txt")
.then()
.statusCode(200);
given()
.header("x-amz-checksum-mode", "ENABLED")
.when()
.head("/checksum-mode-head-bucket/greeting.txt")
.then()
.statusCode(200)
.header("x-amz-checksum-crc64nvme", notNullValue());
given().delete("/checksum-mode-head-bucket/greeting.txt");
given().delete("/checksum-mode-head-bucket");
}
@Test
@Order(27)
void getObjectWithFullRange() {
@@ -694,6 +754,7 @@ class S3IntegrationTest {
.header("Content-Length", equalTo("0"))
.header("Accept-Ranges", equalTo("bytes"))
.header("x-amz-meta-kind", equalTo("empty"))
.header("x-amz-checksum-crc64nvme", nullValue())
.body(equalTo(""));
given()
@@ -703,6 +764,36 @@ class S3IntegrationTest {
.statusCode(204);
}
@Test
@Order(207)
void getObjectWithSuffixRangeForEmptyObjectAndChecksumModeIncludesChecksum() {
// The empty-object suffix-range path returns via fullObjectResponse (a full 200, not
// a 206), so it must honor x-amz-checksum-mode like any other full-object response.
given()
.header("x-amz-meta-kind", "empty")
.body(new byte[0])
.when()
.put("/test-bucket/empty-checksum.txt")
.then()
.statusCode(200);
given()
.header("Range", "bytes=-13")
.header("x-amz-checksum-mode", "ENABLED")
.when()
.get("/test-bucket/empty-checksum.txt")
.then()
.statusCode(200)
.header("Content-Length", equalTo("0"))
.header("x-amz-checksum-crc64nvme", notNullValue());
given()
.when()
.delete("/test-bucket/empty-checksum.txt")
.then()
.statusCode(204);
}
@Test
@Order(39)
void getObjectRangeStreamsExactBytesFromLargeObject() {