Skip to content

armgit / floci

Public Imported from GitHub
0

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

fix(ec2): return groupSet from DescribeInstanceAttribute (#1709)

Hector Ventura8b39ead1a46e
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/Ec2InstanceResponseShapeTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/Ec2InstanceResponseShapeTest.java
index d09880c12e..6efd50d482 100644
--- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/Ec2InstanceResponseShapeTest.java
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/Ec2InstanceResponseShapeTest.java
@@ -299,6 +299,44 @@ class Ec2InstanceResponseShapeTest {
.isTrue();
}
+ // ── Security groups (issue #1644) ────────────────────────────────────────
+
+ @Test
+ @Order(17)
+ @DisplayName("instance and primary ENI expose security groups")
+ void securityGroupsOnInstanceAndEni() {
+ assertThat(instance.securityGroups())
+ .as("instance securityGroups must not be empty")
+ .isNotEmpty();
+ assertThat(instance.securityGroups().get(0).groupId()).isNotBlank();
+ assertThat(instance.securityGroups().get(0).groupName()).isNotBlank();
+
+ InstanceNetworkInterface primaryEni = instance.networkInterfaces().get(0);
+ assertThat(primaryEni.groups())
+ .as("primary ENI groups must not be empty")
+ .isNotEmpty();
+ assertThat(primaryEni.groups().get(0).groupId()).isNotBlank();
+ }
+
+ @Test
+ @Order(18)
+ @DisplayName("DescribeInstanceAttribute groupSet returns Groups (Ansible ec2_instance path)")
+ void describeInstanceAttributeGroupSet() {
+ DescribeInstanceAttributeResponse attr = ec2.describeInstanceAttribute(
+ DescribeInstanceAttributeRequest.builder()
+ .instanceId(instanceId)
+ .attribute(InstanceAttributeName.GROUP_SET)
+ .build());
+
+ assertThat(attr.instanceId()).isEqualTo(instanceId);
+ assertThat(attr.groups())
+ .as("groupSet attribute must return the instance security groups"
+ + " — amazon.aws ec2_instance reads value['Groups'] from this call")
+ .isNotEmpty();
+ assertThat(attr.groups().get(0).groupId()).isNotBlank();
+ assertThat(attr.groups().get(0).groupName()).isNotBlank();
+ }
+
// ── TerminateInstances state transitions ─────────────────────────────────
@Test
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 45eccde689..dc0d01032f 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
@@ -601,6 +601,15 @@ public class Ec2QueryHandler {
xml.start("disableApiStop").elem("value", String.valueOf(inst.isDisableApiStop())).end("disableApiStop");
} else if ("disableApiTermination".equals(attribute)) {
xml.start("disableApiTermination").elem("value", String.valueOf(inst.isDisableApiTermination())).end("disableApiTermination");
+ } else if ("groupSet".equals(attribute)) {
+ xml.start("groupSet");
+ for (GroupIdentifier gi : inst.getSecurityGroups()) {
+ xml.start("item")
+ .elem("groupId", gi.getGroupId())
+ .elem("groupName", gi.getGroupName())
+ .end("item");
+ }
+ xml.end("groupSet");
}
xml.end("DescribeInstanceAttributeResponse");
return xmlResponse(xml.build());
diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java
index 64eb4b1d97..31680e1e77 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2IntegrationTest.java
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.ec2;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.emptyOrNullString;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.greaterThan;
@@ -1330,6 +1331,23 @@ class Ec2IntegrationTest {
equalTo("running"));
}
+ @Test
+ @Order(87)
+ void describeInstanceAttributeGroupSet() {
+ given()
+ .formParam("Action", "DescribeInstanceAttribute")
+ .formParam("InstanceId", instanceId)
+ .formParam("Attribute", "groupSet")
+ .header("Authorization", AUTH_HEADER)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("DescribeInstanceAttributeResponse.instanceId", equalTo(instanceId))
+ .body("DescribeInstanceAttributeResponse.groupSet.item.groupId", equalTo(securityGroupId))
+ .body("DescribeInstanceAttributeResponse.groupSet.item.groupName", not(emptyOrNullString()));
+ }
+
@Test
@Order(82)
void describeInstancesHasNetworkInterfaceAttachTime() {
@@ -1435,7 +1453,7 @@ class Ec2IntegrationTest {
}
@Test
- @Order(87)
+ @Order(88)
void describeInstancesByFilter() {
given()
.formParam("Action", "DescribeInstances")