Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(ec2): answer DescribeTransitGatewayConnects with an empty list (#3274)

Sam Fakhreddinef30ba77ac074
diff --git a/docs/services/ec2.md b/docs/services/ec2.md
index 08904b243b..fe7a417f5a 100644
--- a/docs/services/ec2.md
+++ b/docs/services/ec2.md
@@ -385,6 +385,7 @@ and `DescribeTransitGateways` include it.
| CreateTransitGatewayVpcAttachment | Attaches a VPC to a transit gateway through one subnet per availability zone. |
| DescribeTransitGatewayVpcAttachments | Lists or returns VPC attachments with their subnets and options. |
| DescribeTransitGatewayAttachments | Returns the same attachments in the resource-agnostic shape, including the route table association. |
+| DescribeTransitGatewayConnects | Always returns an empty list, since Connect attachments cannot be created yet; requested ids are still validated. |
| ModifyTransitGatewayVpcAttachment | Adds or removes attachment subnets and updates its options. |
| DeleteTransitGatewayVpcAttachment | Deletes a VPC attachment. |
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.java
index 62614711e4..5cfdd2e5c3 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
@@ -110,6 +110,7 @@ public class Ec2QueryHandler {
handleDescribeTransitGatewayVpcAttachments(params, region);
case "DescribeTransitGatewayAttachments" ->
handleDescribeTransitGatewayAttachments(params, region);
+ case "DescribeTransitGatewayConnects" -> handleDescribeTransitGatewayConnects(params, region);
case "ModifyTransitGatewayVpcAttachment" ->
handleModifyTransitGatewayVpcAttachment(params, region);
case "DeleteTransitGatewayVpcAttachment" ->
@@ -2181,6 +2182,18 @@ public class Ec2QueryHandler {
return xmlResponse(xml.build());
}
+ /** floci does not yet support creating Connect attachments, so this is always an empty list. */
+ private Response handleDescribeTransitGatewayConnects(MultivaluedMap<String, String> p, String region) {
+ service.describeTransitGatewayConnects(region, getList(p, "TransitGatewayAttachmentIds"), getFilters(p));
+ XmlBuilder xml = new XmlBuilder()
+ .start("DescribeTransitGatewayConnectsResponse", AwsNamespaces.EC2)
+ .elem("requestId", UUID.randomUUID().toString())
+ .start("transitGatewayConnectSet")
+ .end("transitGatewayConnectSet")
+ .end("DescribeTransitGatewayConnectsResponse");
+ return xmlResponse(xml.build());
+ }
+
private Response handleModifyTransitGatewayVpcAttachment(MultivaluedMap<String, String> p, String region) {
TransitGatewayVpcAttachment attachment = service.modifyTransitGatewayVpcAttachment(
region,
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.java
index c8f5016b55..d68fa02e41 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
@@ -1610,6 +1610,22 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
.collect(Collectors.toList());
}
+ /**
+ * floci does not yet support creating Connect attachments, so the Query handler always
+ * answers with an empty set, the same thing a real account with none would get back; this
+ * only validates the request (a dedicated Connect model can replace it later). Requested ids still
+ * validate the same way {@link #describeTransitGatewayVpcAttachments} validates VPC attachment
+ * ids, since Connect attachments share the same {@code tgw-attach-} id namespace.
+ */
+ public void describeTransitGatewayConnects(
+ String region, List<String> attachmentIds, Map<String, List<String>> filters) {
+ attachmentIds.forEach(Ec2Service::requireWellFormedAttachmentId);
+ if (!attachmentIds.isEmpty()) {
+ throw new AwsException("InvalidTransitGatewayConnectID.NotFound",
+ "Transit Gateway Connect " + attachmentIds.get(0) + " was deleted or does not exist.", 400);
+ }
+ }
+
public TransitGatewayVpcAttachment modifyTransitGatewayVpcAttachment(
String region, String attachmentId, List<String> addSubnetIds, List<String> removeSubnetIds,
TransitGatewayVpcAttachmentOptions changes) {
diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ServiceTest.java
index 2e04a1e8b4..181de19b5a 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ServiceTest.java
@@ -50,6 +50,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
@@ -2598,6 +2599,32 @@ class Ec2ServiceTest {
"a well-formed id that does not exist is a different failure");
}
+ /**
+ * floci does not yet support creating Connect attachments, so LZA's tgw-associations-and-
+ * propagations module, which describes them unconditionally alongside VPC attachments, needs
+ * this to at least answer with an empty account-wide list rather than an unrecognized-action
+ * error (LZA fidelity gap: AWSAccelerator-ToolkitProject build 29 failed with "Operation
+ * DescribeTransitGatewayConnects is not supported").
+ */
+ @Test
+ void describeTransitGatewayConnectsReturnsEmptyWhenNoneExist() {
+ Ec2Service service = prefixListService();
+
+ assertDoesNotThrow(() -> service.describeTransitGatewayConnects("us-east-1", List.of(), Map.of()));
+ }
+
+ @Test
+ void describeTransitGatewayConnectsRejectsAMalformedOrUnknownId() {
+ Ec2Service service = prefixListService();
+
+ assertEquals("InvalidTransitGatewayAttachmentID.Malformed", assertThrows(AwsException.class,
+ () -> service.describeTransitGatewayConnects("us-east-1", List.of("tgw-connect-nope"), Map.of()))
+ .getErrorCode());
+ assertEquals("InvalidTransitGatewayConnectID.NotFound", assertThrows(AwsException.class,
+ () -> service.describeTransitGatewayConnects("us-east-1",
+ List.of("tgw-attach-0123456789abcdef0"), Map.of())).getErrorCode());
+ }
+
/** The gateway's owner is its own field, sourced from the gateway rather than from the VPC. */
@Test
void anAttachmentRecordsBothOwnersSeparately() {
diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2TransitGatewayVpcAttachmentIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2TransitGatewayVpcAttachmentIntegrationTest.java
index 8d5820e1ed..eeabee754e 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2TransitGatewayVpcAttachmentIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2TransitGatewayVpcAttachmentIntegrationTest.java
@@ -205,4 +205,43 @@ class Ec2TransitGatewayVpcAttachmentIntegrationTest {
.then().statusCode(200)
.body("DeleteTransitGatewayResponse.transitGateway.state", equalTo("deleted"));
}
+
+ /**
+ * Connect attachments cannot be created yet, so the describe answers with the AWS-shaped
+ * empty collection: the EC2 namespace, a requestId, and an empty transitGatewayConnectSet.
+ */
+ @Test
+ @Order(7)
+ void describeTransitGatewayConnectsAnswersAnEmptySetOverTheQueryProtocol() {
+ String body = given()
+ .formParam("Action", "DescribeTransitGatewayConnects")
+ .header("Authorization", AUTH_HEADER)
+ .when().post("/")
+ .then().statusCode(200)
+ .body("DescribeTransitGatewayConnectsResponse.requestId", not(equalTo("")))
+ .extract().asString();
+
+ assertThat(body, containsString("<DescribeTransitGatewayConnectsResponse xmlns=\"http://ec2.amazonaws.com/doc/2016-11-15/\">"));
+ assertThat(body, containsString("<transitGatewayConnectSet></transitGatewayConnectSet>"));
+ }
+
+ @Test
+ @Order(8)
+ void describeTransitGatewayConnectsRejectsMalformedAndUnknownIdsOverTheQueryProtocol() {
+ given()
+ .formParam("Action", "DescribeTransitGatewayConnects")
+ .formParam("TransitGatewayAttachmentIds.1", "tgw-connect-nope")
+ .header("Authorization", AUTH_HEADER)
+ .when().post("/")
+ .then().statusCode(400)
+ .body("Response.Errors.Error.Code", equalTo("InvalidTransitGatewayAttachmentID.Malformed"));
+
+ given()
+ .formParam("Action", "DescribeTransitGatewayConnects")
+ .formParam("TransitGatewayAttachmentIds.1", "tgw-attach-0123456789abcdef0")
+ .header("Authorization", AUTH_HEADER)
+ .when().post("/")
+ .then().statusCode(400)
+ .body("Response.Errors.Error.Code", equalTo("InvalidTransitGatewayConnectID.NotFound"));
+ }
}