fix(s3): make the replaced version noncurrent on a write to a suspended bucket (#7143)

A write in a versioning-suspended bucket makes the version or delete
marker it replaces noncurrent, and deleting versionId=null makes the
newest of them current again, as on S3.
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-10-31 18:26:01 -04:00
1 parent 45b85405f7
commit 04558d9c1a
4 files changed
+79 -18

No files matched your search

@@ -832,4 +832,47 @@ class S3VersioningIntegrationTest {
.body(equalTo("older"));
}
@Test
@Order(30)
void aSuspendedWriteMakesTheVersionItReplacesNoncurrent() {
String bucket = "suspended-null-write";
given().when().put("/" + bucket).then().statusCode(200);
given().body("<VersioningConfiguration><Status>Enabled</Status></VersioningConfiguration>")
.when().put("/" + bucket + "?versioning").then().statusCode(200);
List<String> keys = List.of("put", "copy", "upload");
List<String> older = keys.stream()
.map(key -> given().body("older").when().put("/" + bucket + "/" + key)
.then().statusCode(200).extract().header("x-amz-version-id"))
.toList();
given().body("<VersioningConfiguration><Status>Suspended</Status></VersioningConfiguration>")
.when().put("/" + bucket + "?versioning").then().statusCode(200);
given().body("null").when().put("/" + bucket + "/put").then().statusCode(200);
given().header("x-amz-copy-source", "/" + bucket + "/put")
.when().put("/" + bucket + "/copy").then().statusCode(200);
String uploadId = given().when().post("/" + bucket + "/upload?uploads").then().statusCode(200)
.extract().xmlPath().getString("InitiateMultipartUploadResult.UploadId");
String partETag = given().body("null").when().put("/" + bucket + "/upload?uploadId=" + uploadId
+ "&partNumber=1").then().statusCode(200).extract().header("ETag");
given().contentType("application/xml")
.body("""
<CompleteMultipartUpload>
<Part><PartNumber>1</PartNumber><ETag>%s</ETag></Part>
</CompleteMultipartUpload>""".formatted(partETag))
.when().post("/" + bucket + "/upload?uploadId=" + uploadId).then().statusCode(200);
for (int i = 0; i < keys.size(); i++) {
given().queryParam("versions", "").queryParam("prefix", keys.get(i)).when().get("/" + bucket)
.then().statusCode(200)
.body("ListVersionsResult.Version.VersionId", contains("null", older.get(i)))
.body("ListVersionsResult.Version.IsLatest", contains("true", "false"));
}
given().queryParam("versionId", "null").when().delete("/" + bucket + "/put").then().statusCode(204)
.header("x-amz-version-id", "null");
given().when().get("/" + bucket + "/put").then().statusCode(200)
.header("x-amz-version-id", older.get(0))
.body(equalTo("older"));
}
}
@@ -154,6 +154,31 @@ class S3VersioningServiceTest {
assertEquals(List.of(current.getVersionId() + " latest"), versionLines("put"));
}
@Test
void aSuspendedPutMakesTheVersionOrDeleteMarkerItReplacesNoncurrent() {
s3Service.putBucketVersioning("versioned-bucket", "Enabled");
S3Object first = s3Service.putObject("versioned-bucket", "put",
"v1".getBytes(StandardCharsets.UTF_8), "text/plain", null);
S3Object second = s3Service.putObject("versioned-bucket", "put",
"v2".getBytes(StandardCharsets.UTF_8), "text/plain", null);
S3Object hidden = s3Service.putObject("versioned-bucket", "marker",
"v1".getBytes(StandardCharsets.UTF_8), "text/plain", null);
S3Object marker = s3Service.deleteObject("versioned-bucket", "marker");
s3Service.putBucketVersioning("versioned-bucket", "Suspended");
s3Service.putObject("versioned-bucket", "put", "null".getBytes(StandardCharsets.UTF_8), "text/plain", null);
s3Service.putObject("versioned-bucket", "marker", "null".getBytes(StandardCharsets.UTF_8), "text/plain", null);
assertEquals(List.of("null latest", second.getVersionId(), first.getVersionId()), versionLines("put"));
assertEquals(List.of("null latest", marker.getVersionId() + " marker", hidden.getVersionId()),
versionLines("marker"));
s3Service.deleteObject("versioned-bucket", "put", "null");
s3Service.deleteObject("versioned-bucket", "marker", "null");
assertEquals(List.of(second.getVersionId() + " latest", first.getVersionId()), versionLines("put"));
assertEquals(List.of(marker.getVersionId() + " marker latest", hidden.getVersionId()),
versionLines("marker"));
}
private List<String> versionLines(String key) {
return s3Service.listObjectVersions("versioned-bucket", key, 100, null).versions().stream()
.map(version -> (version.getVersionId() != null ? version.getVersionId() : "null")