mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
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:
1 parent
df9535d7db
commit
037236daf8
4 files changed
+143
No files matched your search
@@ -9,6 +9,7 @@ Route53 management-plane emulation. Supports hosted zones, resource record sets,
|
||||
| --- | --- |
|
||||
| `CreateHostedZone` | `POST /2013-04-01/hostedzone`. A `<VPC>` 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 `<VPCs>` 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` |
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<HostedZone> listHostedZones(String marker, int maxItems) {
|
||||
List<HostedZone> all = new ArrayList<>(zoneStore.scan(k -> true));
|
||||
all.sort((a, b) -> a.getName().compareTo(b.getName()));
|
||||
|
||||
+109
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user