feat(route53): implement UpdateHostedZoneComment (#3906)

* feat(route53): implement UpdateHostedZoneComment

The path carried GET and DELETE but no POST, so the action answered 405 and a
caller that renames or re-comments a zone could not proceed. Terraform's
aws_route53_zone sends it whenever the comment changes, which includes importing
an existing zone under a new configuration.

A request with no Comment clears the existing one, as AWS documents, rather than
leaving the previous value in place.

* fix(route53): reject a body that is not an UpdateHostedZoneCommentRequest

A missing Comment means "clear the comment", and XmlParser returns the default
for a body it cannot parse, so a truncated or wrong-root document cleared the
zone's comment and answered 200. Validate the root element first.

* fix(route53): resolve the zone through the caller-ownership lookup

UpdateHostedZoneComment resolved the zone with getHostedZone, which reads
pre-account-isolation data written before the store was account-scoped and
migrates it into whichever partition asked for it first. Use the same lookup
the VPC association actions use, so only the owning account can rewrite the
comment.
This commit is contained in:
Matthew Ingle authored and GitHub committed 2026-09-19 10:20:53 -04:00
1 parent df9535d7db
commit 037236daf8
4 files changed
+143

No files matched your search

@@ -537,4 +537,113 @@ class Route53IntegrationTest {
.body("GetAccountLimitResponse.Limit.Type", equalTo("MAX_HOSTED_ZONES_BY_OWNER"))
.body("GetAccountLimitResponse.Limit.Value", equalTo("500"));
}
@Test
@Order(22)
void updateHostedZoneComment_replacesTheCommentAndClearsItWhenOmitted() {
String ownZoneId = createZoneForCommentTest("comment-zone-1", "before the import");
given()
.contentType(XML)
.body("""
<?xml version="1.0" encoding="UTF-8"?>
<UpdateHostedZoneCommentRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
<Comment>after the import</Comment>
</UpdateHostedZoneCommentRequest>
""")
.when().post("/2013-04-01/hostedzone/" + ownZoneId)
.then()
.statusCode(200)
.contentType(XML)
.body("UpdateHostedZoneCommentResponse.HostedZone.Id", equalTo("/hostedzone/" + ownZoneId))
.body("UpdateHostedZoneCommentResponse.HostedZone.Config.Comment", equalTo("after the import"));
given()
.when().get("/2013-04-01/hostedzone/" + ownZoneId)
.then()
.statusCode(200)
.body("GetHostedZoneResponse.HostedZone.Config.Comment", equalTo("after the import"));
// AWS deletes the existing comment when the request carries none.
given()
.contentType(XML)
.body("""
<?xml version="1.0" encoding="UTF-8"?>
<UpdateHostedZoneCommentRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/"/>
""")
.when().post("/2013-04-01/hostedzone/" + ownZoneId)
.then()
.statusCode(200)
.body(not(containsString("<Comment>")));
// Cleanup
given().when().delete("/2013-04-01/hostedzone/" + ownZoneId).then().statusCode(200);
}
@Test
@Order(23)
void updateHostedZoneComment_unknownZoneIsNoSuchHostedZone() {
given()
.contentType(XML)
.body("""
<?xml version="1.0" encoding="UTF-8"?>
<UpdateHostedZoneCommentRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
<Comment>nope</Comment>
</UpdateHostedZoneCommentRequest>
""")
.when().post("/2013-04-01/hostedzone/ZNOPE000000000")
.then()
.statusCode(404)
.body(containsString("NoSuchHostedZone"));
}
@Test
@Order(24)
void updateHostedZoneComment_rejectsABodyThatIsNotAnUpdateRequest() {
String zoneId = createZoneForCommentTest("comment-zone-2", "keep me");
// A truncated document parses to no root, so it must not read as "no Comment given".
given()
.contentType(XML)
.body("<UpdateHostedZoneCommentRequest><Comment>gone</Comment>")
.when().post("/2013-04-01/hostedzone/" + zoneId)
.then()
.statusCode(400)
.body(containsString("InvalidInput"));
given()
.contentType(XML)
.body("<DeleteHostedZoneRequest/>")
.when().post("/2013-04-01/hostedzone/" + zoneId)
.then()
.statusCode(400)
.body(containsString("InvalidInput"));
given()
.when().get("/2013-04-01/hostedzone/" + zoneId)
.then()
.statusCode(200)
.body("GetHostedZoneResponse.HostedZone.Config.Comment", equalTo("keep me"));
// Cleanup
given().when().delete("/2013-04-01/hostedzone/" + zoneId).then().statusCode(200);
}
private String createZoneForCommentTest(String callerReference, String comment) {
String location = given()
.contentType(XML)
.body("""
<?xml version="1.0" encoding="UTF-8"?>
<CreateHostedZoneRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
<Name>comments.example.com</Name>
<CallerReference>%s</CallerReference>
<HostedZoneConfig>
<Comment>%s</Comment>
</HostedZoneConfig>
</CreateHostedZoneRequest>
""".formatted(callerReference, comment))
.when().post("/2013-04-01/hostedzone")
.then().statusCode(201).extract().header("Location");
return location.substring(location.lastIndexOf('/') + 1);
}
}