Skip to content

armgit / floci

Public Imported from GitHub
0

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

fix(rds): return DBSubnetGroupNotFoundFault for missing DescribeDBSubnetGroups name (#1870)

Leandro-ft1ba15f0ce7b4
diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java
index fd2c5ea532..eb9f046069 100644
--- a/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java
@@ -803,7 +803,10 @@ public class RdsService implements Resettable {
groups.add(buildDefaultSubnetGroup(effectiveRegion(region)));
}
if (filterName != null && !filterName.isBlank()) {
- subnetGroups.get(filterName).ifPresent(groups::add);
+ if (!"default".equalsIgnoreCase(filterName)) {
+ // Specific name: AWS DescribeDBSubnetGroups faults when absent (not empty 200).
+ groups.add(resolveDbSubnetGroupView(filterName, region));
+ }
return groups;
}
groups.addAll(subnetGroups.scan(k -> true));
diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java
index 13b127086b..ec484ba433 100644
--- a/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java
@@ -770,6 +770,21 @@ class RdsQueryHandlerTest {
verify(service).listDbSubnetGroups(null, "us-west-2");
}
+ @Test
+ void describeDbSubnetGroups_missingNameReturnsNotFoundFault() {
+ when(service.listDbSubnetGroups("does-not-exist", null))
+ .thenThrow(new AwsException("DBSubnetGroupNotFoundFault",
+ "DB subnet group does-not-exist not found.", 404));
+
+ MultivaluedMap<String, String> p = params();
+ p.add("DBSubnetGroupName", "does-not-exist");
+
+ Response response = handler.handle("DescribeDBSubnetGroups", p);
+
+ assertEquals(404, response.getStatus());
+ assertTrue(((String) response.getEntity()).contains("DBSubnetGroupNotFoundFault"));
+ }
+
// ──────────────────────────── Helpers ────────────────────────────
private static MultivaluedMap<String, String> params() {
diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java
index 544202de8a..02df455e56 100644
--- a/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java
@@ -293,7 +293,25 @@ class RdsServiceTest {
assertEquals(1, rdsService.listDbSubnetGroups("sample-db-subnets").size());
rdsService.deleteDbSubnetGroup("sample-db-subnets");
- assertTrue(rdsService.listDbSubnetGroups("sample-db-subnets").isEmpty());
+ AwsException missing = assertThrows(AwsException.class,
+ () -> rdsService.listDbSubnetGroups("sample-db-subnets"));
+ assertEquals("DBSubnetGroupNotFoundFault", missing.getErrorCode());
+ assertEquals(404, missing.getHttpStatus());
+ }
+
+ @Test
+ void listDbSubnetGroupsFaultsForMissingName() {
+ AwsException missing = assertThrows(AwsException.class,
+ () -> rdsService.listDbSubnetGroups("does-not-exist"));
+ assertEquals("DBSubnetGroupNotFoundFault", missing.getErrorCode());
+ assertEquals(404, missing.getHttpStatus());
+ }
+
+ @Test
+ void listDbSubnetGroupsStillResolvesSyntheticDefault() {
+ Collection<DbSubnetGroup> groups = rdsService.listDbSubnetGroups("default");
+ assertEquals(1, groups.size());
+ assertEquals("default", groups.iterator().next().getDbSubnetGroupName());
}
@Test