Light, fluffy, and always free - The AWS Local Emulator alternative
fix(ec2): honor dry run for replace route (#4300)
Aniket Shukla55f9ff5a8bbc
diff --git a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.javaindex 22ef5306df..58de4c4050 100644--- a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java+++ b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java@@ -3651,7 +3651,8 @@ public class Ec2QueryHandler {}gwId = LOCAL_GATEWAY_ID;}- service.replaceRoute(region, rtId, dest, destIpv6, destPrefixList, gwId, natGwId, pcxId);+ service.replaceRoute(region, rtId, dest, destIpv6, destPrefixList, gwId, natGwId, pcxId,+ Boolean.parseBoolean(p.getFirst("DryRun")));return booleanResponse("ReplaceRoute");}diff --git a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.java b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.javaindex dacdef5648..e177267478 100644--- a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.java+++ b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.java@@ -7196,6 +7196,14 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {public void replaceRoute(String region, String routeTableId, String destinationCidrBlock,String destinationIpv6CidrBlock, String destinationPrefixListId,String gatewayId, String natGatewayId, String vpcPeeringConnectionId) {+ replaceRoute(region, routeTableId, destinationCidrBlock, destinationIpv6CidrBlock,+ destinationPrefixListId, gatewayId, natGatewayId, vpcPeeringConnectionId, false);+ }++ public void replaceRoute(String region, String routeTableId, String destinationCidrBlock,+ String destinationIpv6CidrBlock, String destinationPrefixListId,+ String gatewayId, String natGatewayId, String vpcPeeringConnectionId,+ boolean dryRun) {requireExactlyOneDestination("ReplaceRoute", destinationCidrBlock, destinationIpv6CidrBlock,destinationPrefixListId);// AWS takes exactly one target. Rejecting both-or-neither also keeps the targets this@@ -7225,6 +7233,11 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {destinationPrefixListId)+ " does not exist", 400));+ if (dryRun) {+ throw new AwsException("DryRunOperation",+ "Request would have succeeded, but DryRun flag is set.", 412);+ }+// The target the request does not name is cleared rather than carried over from the// route being replaced.Route replacement = new Route(canonicalDestinationCidrBlock, hasGateway ? gatewayId : null, existing.getOrigin());diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ReplaceRouteIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ReplaceRouteIntegrationTest.javaindex fe5f9455fc..378fbc4a19 100644--- a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ReplaceRouteIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ReplaceRouteIntegrationTest.java@@ -337,4 +337,51 @@ class Ec2ReplaceRouteIntegrationTest {.statusCode(400).body("Response.Errors.Error.Code", equalTo("InvalidRouteTableID.NotFound"));}++ @Test+ @Order(12)+ void dryRunValidReplacementReportsSuccessWithoutChangingTheRoute() {+ given()+ .formParam("Action", "ReplaceRoute")+ .formParam("RouteTableId", routeTableId)+ .formParam("DestinationCidrBlock", DEFAULT_ROUTE)+ .formParam("NatGatewayId", NAT_GATEWAY)+ .formParam("DryRun", "true")+ .header("Authorization", AUTH_HEADER)+ .when()+ .post("/")+ .then()+ .statusCode(412)+ .body("Response.Errors.Error.Code", equalTo("DryRunOperation"));++ String table = given()+ .formParam("Action", "DescribeRouteTables")+ .formParam("RouteTableId.1", routeTableId)+ .header("Authorization", AUTH_HEADER)+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body(DEFAULT_ROUTE_NODE + ".gatewayId", equalTo(INTERNET_GATEWAY))+ .extract().asString();++ assertThat(table, not(containsString(NAT_GATEWAY)));+ }++ @Test+ @Order(13)+ void dryRunStillRejectsAnUnknownDestination() {+ given()+ .formParam("Action", "ReplaceRoute")+ .formParam("RouteTableId", routeTableId)+ .formParam("DestinationCidrBlock", UNROUTED_CIDR)+ .formParam("NatGatewayId", NAT_GATEWAY)+ .formParam("DryRun", "true")+ .header("Authorization", AUTH_HEADER)+ .when()+ .post("/")+ .then()+ .statusCode(400)+ .body("Response.Errors.Error.Code", equalTo("InvalidRoute.NotFound"));+ }}