From 037236daf8abb8678dbfac3efdfb43bc1982d551 Mon Sep 17 00:00:00 2001 From: Matthew Ingle Date: Sat, 19 Sep 2026 15:20:53 +0100 Subject: [PATCH] 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. --- docs/services/route53.md | 1 + .../services/route53/Route53Controller.java | 22 ++++ .../services/route53/Route53Service.java | 11 ++ .../route53/Route53IntegrationTest.java | 109 ++++++++++++++++++ 4 files changed, 143 insertions(+) diff --git a/docs/services/route53.md b/docs/services/route53.md index 3eac9c549d..04046e76c2 100644 --- a/docs/services/route53.md +++ b/docs/services/route53.md @@ -9,6 +9,7 @@ Route53 management-plane emulation. Supports hosted zones, resource record sets, | --- | --- | | `CreateHostedZone` | `POST /2013-04-01/hostedzone`. A `` element in the request creates a private zone and records the first VPC association. | | `GetHostedZone` | `GET /2013-04-01/hostedzone/{Id}`. Private zones include their `` list. | +| `UpdateHostedZoneComment` | `POST /2013-04-01/hostedzone/{Id}` | | `DeleteHostedZone` | `DELETE /2013-04-01/hostedzone/{Id}` | | `ListHostedZones` | `GET /2013-04-01/hostedzone` | | `ListHostedZonesByName` | `GET /2013-04-01/hostedzonesbyname` | diff --git a/src/main/java/io/github/hectorvent/floci/services/route53/Route53Controller.java b/src/main/java/io/github/hectorvent/floci/services/route53/Route53Controller.java index ae120172a2..43a4eb4a66 100644 --- a/src/main/java/io/github/hectorvent/floci/services/route53/Route53Controller.java +++ b/src/main/java/io/github/hectorvent/floci/services/route53/Route53Controller.java @@ -122,6 +122,28 @@ public class Route53Controller { } } + @POST + @Path("/hostedzone/{Id}") + public Response updateHostedZoneComment(@PathParam("Id") String id, String body) { + try { + if (body != null && !body.isBlank() + && !"UpdateHostedZoneCommentRequest".equals(XmlParser.rootElementName(body))) { + throw new AwsException("InvalidInput", + "The request body must be an UpdateHostedZoneCommentRequest document.", 400); + } + String comment = XmlParser.extractFirst(body, "Comment", null); + HostedZone zone = service.updateHostedZoneComment(id, comment); + String xml = new XmlBuilder() + .start("UpdateHostedZoneCommentResponse", NS) + .raw(xmlHostedZone(zone)) + .end("UpdateHostedZoneCommentResponse") + .build(); + return Response.ok(xml, XML).build(); + } catch (AwsException e) { + return xmlErrorResponse(e); + } + } + @DELETE @Path("/hostedzone/{Id}") public Response deleteHostedZone(@PathParam("Id") String id) { diff --git a/src/main/java/io/github/hectorvent/floci/services/route53/Route53Service.java b/src/main/java/io/github/hectorvent/floci/services/route53/Route53Service.java index db5b2f2a41..d589fc2fca 100644 --- a/src/main/java/io/github/hectorvent/floci/services/route53/Route53Service.java +++ b/src/main/java/io/github/hectorvent/floci/services/route53/Route53Service.java @@ -137,6 +137,17 @@ public class Route53Service { return newChange(null); } + /** + * The comment is cleared when the request carries none, which is what AWS does rather than + * leaving the previous comment in place. + */ + public synchronized HostedZone updateHostedZoneComment(String id, String comment) { + HostedZone zone = getHostedZoneOwnedByCaller(id); + zone.setComment(comment); + zoneStore.put(id, zone); + return zone; + } + public List listHostedZones(String marker, int maxItems) { List all = new ArrayList<>(zoneStore.scan(k -> true)); all.sort((a, b) -> a.getName().compareTo(b.getName())); diff --git a/src/test/java/io/github/hectorvent/floci/services/route53/Route53IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/route53/Route53IntegrationTest.java index e7c3ad83c0..411f921fbd 100644 --- a/src/test/java/io/github/hectorvent/floci/services/route53/Route53IntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/route53/Route53IntegrationTest.java @@ -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(""" + + + after the import + + """) + .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(""" + + + """) + .when().post("/2013-04-01/hostedzone/" + ownZoneId) + .then() + .statusCode(200) + .body(not(containsString(""))); + + // Cleanup + given().when().delete("/2013-04-01/hostedzone/" + ownZoneId).then().statusCode(200); + } + + @Test + @Order(23) + void updateHostedZoneComment_unknownZoneIsNoSuchHostedZone() { + given() + .contentType(XML) + .body(""" + + + nope + + """) + .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("gone") + .when().post("/2013-04-01/hostedzone/" + zoneId) + .then() + .statusCode(400) + .body(containsString("InvalidInput")); + + given() + .contentType(XML) + .body("") + .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(""" + + + comments.example.com + %s + + %s + + + """.formatted(callerReference, comment)) + .when().post("/2013-04-01/hostedzone") + .then().statusCode(201).extract().header("Location"); + return location.substring(location.lastIndexOf('/') + 1); + } }