fix: return 400 MalformedXML for unparseable PutObjectRetention RetainUntilDate (#1631)

PutObjectRetention crashed with an uncaught DateTimeParseException when
RetainUntilDate could not be parsed, leaking as an HTTP 500 HTML page.
Wrap the Instant.parse call and throw an AwsException mapped to HTTP 400
MalformedXML, matching real AWS S3 behavior.

Fixes #1614
This commit is contained in:
Matt Van Horn authored and GitHub committed 2026-07-22 08:58:12 -04:00
1 parent ac8a3d7c82
commit 526a62317f
2 files changed
+82 -2

No files matched your search

@@ -122,10 +122,83 @@ class S3ObjectLockIntegrationTest {
.body(containsString("<Days>30</Days>"));
}
// --- PutObjectRetention RetainUntilDate parsing ---
private static final String RETENTION_KEY = "retained-object.txt";
@Test
@Order(10)
void putObjectForRetention() {
given()
.body("hello")
.when()
.put("/" + LOCK_BUCKET + "/" + RETENTION_KEY)
.then()
.statusCode(200);
}
@Test
@Order(11)
void putObjectRetentionWithValidIsoDateReturns200() {
String body = """
<?xml version="1.0" encoding="UTF-8"?>
<Retention xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Mode>GOVERNANCE</Mode>
<RetainUntilDate>2030-01-01T00:00:00Z</RetainUntilDate>
</Retention>
""";
given()
.body(body)
.when()
.put("/" + LOCK_BUCKET + "/" + RETENTION_KEY + "?retention")
.then()
.statusCode(200);
}
@Test
@Order(12)
void putObjectRetentionWithEpochSecondsReturns400MalformedXml() {
String body = """
<?xml version="1.0" encoding="UTF-8"?>
<Retention xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Mode>GOVERNANCE</Mode>
<RetainUntilDate>1577836800</RetainUntilDate>
</Retention>
""";
given()
.body(body)
.when()
.put("/" + LOCK_BUCKET + "/" + RETENTION_KEY + "?retention")
.then()
.statusCode(400)
.body(containsString("MalformedXML"))
.body(not(containsString("Internal Server Error")));
}
@Test
@Order(13)
void putObjectRetentionWithGarbageDateReturns400MalformedXml() {
String body = """
<?xml version="1.0" encoding="UTF-8"?>
<Retention xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Mode>GOVERNANCE</Mode>
<RetainUntilDate>notadate</RetainUntilDate>
</Retention>
""";
given()
.body(body)
.when()
.put("/" + LOCK_BUCKET + "/" + RETENTION_KEY + "?retention")
.then()
.statusCode(400)
.body(containsString("MalformedXML"))
.body(not(containsString("Internal Server Error")));
}
// --- non-existent bucket ---
@Test
@Order(9)
@Order(14)
void nonExistentBucketReturnsNoSuchBucket() {
given()
.when()