mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(ec2): type a security group rule's tags as security-group-rule (#2272)
* fix(ec2): type a security group rule's tags as security-group-rule inferResourceType had no sgr- case, so DescribeTags reported a rule's tags as resourceType "unknown" and a resource-type filter never matched them. The tags themselves were already correct: createTags stores them and updateResourceTags mirrors them onto the rule, so only the aggregation surface was wrong. Closes #2270 * fix(ec2): brace inferResourceType and tag the group in its test Bracing only the new arm would have left it the single braced line among thirteen, so the whole method is braced rather than just the addition. The test tagged only the rule, so the security-group assertion read an empty result and fell back to the expected value through orElse, passing without exercising the sg- classification at all. Tag the group too and assert on the result directly; removing the sg- arm now fails the test. --------- Co-authored-by: Michal Schreiber <michal.schreiber@benefitsystems.pl>
This commit is contained in:
1 parent
58129108bf
commit
4058dfae00
2 files changed
+73
-12
No files matched your search
@@ -2728,18 +2728,45 @@ public class Ec2Service implements ContainerTeardown {
|
||||
}
|
||||
|
||||
private String inferResourceType(String resourceId) {
|
||||
if (resourceId.startsWith("i-")) return "instance";
|
||||
if (resourceId.startsWith("vpc-")) return "vpc";
|
||||
if (resourceId.startsWith("subnet-")) return "subnet";
|
||||
if (resourceId.startsWith("sg-")) return "security-group";
|
||||
if (resourceId.startsWith("igw-")) return "internet-gateway";
|
||||
if (resourceId.startsWith("rtb-")) return "route-table";
|
||||
if (resourceId.startsWith("key-")) return "key-pair";
|
||||
if (resourceId.startsWith("eipalloc-")) return "elastic-ip";
|
||||
if (resourceId.startsWith("lt-")) return "launch-template";
|
||||
if (resourceId.startsWith("vpce-")) return "vpc-endpoint";
|
||||
if (resourceId.startsWith("nat-")) return "natgateway";
|
||||
if (resourceId.startsWith("pl-")) return "prefix-list";
|
||||
if (resourceId.startsWith("i-")) {
|
||||
return "instance";
|
||||
}
|
||||
if (resourceId.startsWith("vpc-")) {
|
||||
return "vpc";
|
||||
}
|
||||
if (resourceId.startsWith("subnet-")) {
|
||||
return "subnet";
|
||||
}
|
||||
if (resourceId.startsWith("sgr-")) {
|
||||
return "security-group-rule";
|
||||
}
|
||||
if (resourceId.startsWith("sg-")) {
|
||||
return "security-group";
|
||||
}
|
||||
if (resourceId.startsWith("igw-")) {
|
||||
return "internet-gateway";
|
||||
}
|
||||
if (resourceId.startsWith("rtb-")) {
|
||||
return "route-table";
|
||||
}
|
||||
if (resourceId.startsWith("key-")) {
|
||||
return "key-pair";
|
||||
}
|
||||
if (resourceId.startsWith("eipalloc-")) {
|
||||
return "elastic-ip";
|
||||
}
|
||||
if (resourceId.startsWith("lt-")) {
|
||||
return "launch-template";
|
||||
}
|
||||
if (resourceId.startsWith("vpce-")) {
|
||||
return "vpc-endpoint";
|
||||
}
|
||||
if (resourceId.startsWith("nat-")) {
|
||||
return "natgateway";
|
||||
}
|
||||
if (resourceId.startsWith("pl-")) {
|
||||
return "prefix-list";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ import io.github.hectorvent.floci.services.ec2.model.Image;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Instance;
|
||||
import io.github.hectorvent.floci.services.ec2.model.LaunchTemplate;
|
||||
import io.github.hectorvent.floci.services.ec2.model.ManagedPrefixList;
|
||||
import io.github.hectorvent.floci.services.ec2.model.IpPermission;
|
||||
import io.github.hectorvent.floci.services.ec2.model.IpRange;
|
||||
import io.github.hectorvent.floci.services.ec2.model.PrefixListEntry;
|
||||
import io.github.hectorvent.floci.services.ec2.model.NetworkInterface;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Reservation;
|
||||
@@ -1067,6 +1069,38 @@ class Ec2ServiceTest {
|
||||
.getFirst().getTags().isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* A rule's tags already reach the store and the rule itself; only DescribeTags mistyped them,
|
||||
* so a resource-type filter never matched.
|
||||
*/
|
||||
@Test
|
||||
void tagsOnASecurityGroupRuleAreTypedAsSecurityGroupRule() {
|
||||
Ec2Service service = prefixListService();
|
||||
String groupId = service.createSecurityGroup("us-east-1", "db", "db", null).getGroupId();
|
||||
IpPermission perm = new IpPermission();
|
||||
perm.setIpProtocol("tcp");
|
||||
perm.setFromPort(443);
|
||||
perm.setToPort(443);
|
||||
perm.getIpRanges().add(new IpRange("10.0.0.0/8", null));
|
||||
String ruleId = service.authorizeSecurityGroupIngress("us-east-1", groupId, List.of(perm))
|
||||
.getFirst().getSecurityGroupRuleId();
|
||||
|
||||
service.createTags("us-east-1", List.of(ruleId), List.of(new Tag("env", "prod")));
|
||||
|
||||
assertEquals("security-group-rule", service.describeTags("us-east-1",
|
||||
Map.of("resource-id", List.of(ruleId))).getFirst().get("resourceType"));
|
||||
assertEquals(1, service.describeTags("us-east-1",
|
||||
Map.of("resource-type", List.of("security-group-rule"))).size());
|
||||
|
||||
// Tag the group as well, so the sg- classification is genuinely exercised rather than
|
||||
// read off an empty result.
|
||||
service.createTags("us-east-1", List.of(groupId), List.of(new Tag("env", "prod")));
|
||||
assertEquals("security-group", service.describeTags("us-east-1",
|
||||
Map.of("resource-id", List.of(groupId))).getFirst().get("resourceType"));
|
||||
assertEquals(1, service.describeTags("us-east-1",
|
||||
Map.of("resource-type", List.of("security-group"))).size());
|
||||
}
|
||||
|
||||
private static EmulatorConfig mockConfig(boolean ec2Mock) {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
EmulatorConfig.ServicesConfig services = mock(EmulatorConfig.ServicesConfig.class);
|
||||
|
||||
Reference in new issue
Block a user