mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(rds): fault with DBInstanceNotFound/DBClusterNotFoundFault for missing identifiers in Describe* (#1740)
* fix(rds): fault with DBInstanceNotFound/DBClusterNotFoundFault for missing identifiers in Describe* DescribeDBInstances/DescribeDBClusters returned an empty 200 when the identifier parameter matched nothing; real AWS faults for the parameter form and returns an empty list only for the Filters form. Track whether the identifier came from the parameter and fault when it matched nothing, with error codes, messages, and 404 status matching live AWS. * fix(rds,docdb,neptune): ARN identifiers and Filters-form parity for Describe* Review follow-ups: - RDS, DocDB, and Neptune list methods accept an ARN (the identifier parameter and the db-instance-id/db-cluster-id filters both allow ARNs per the AWS model). The ARN is matched against each resource's stored ARN, so a cross-account or cross-region ARN does not resolve a same-named local resource. - DocDbQueryHandler and NeptuneQueryHandler fault only for the identifier parameter, not the Filters form, which returns an empty list (mirror of the RDS fix). * test(rds): expect NotFound faults after delete in SDK compat tests The Go and Java compat suites asserted the old emulator behavior — an empty 200 when describing a deleted instance/cluster by identifier. Real AWS faults DBInstanceNotFound/DBClusterNotFoundFault there, which is what the deletion waiters key on, and the emulator now does the same.
This commit is contained in:
1 parent
d943e09a73
commit
02288abc11
14 files changed
+357
-34
No files matched your search
@@ -334,4 +334,40 @@ class DocDbIntegrationTest {
|
||||
.statusCode(200)
|
||||
.body(containsString(RDS_SCOPE_CLUSTER_ID));
|
||||
}
|
||||
|
||||
// The db-cluster-id / db-instance-id Filters form returns an empty list for a
|
||||
// missing id, unlike the DBClusterIdentifier / DBInstanceIdentifier parameter
|
||||
// which faults with 404. Mirrors AWS and the RDS behaviour.
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
void describeClustersByFilterReturnsEmptyForMissing() {
|
||||
given()
|
||||
.header("Authorization", AUTH)
|
||||
.contentType(FORM)
|
||||
.formParam("Action", "DescribeDBClusters")
|
||||
.formParam("Filters.Filter.1.Name", "db-cluster-id")
|
||||
.formParam("Filters.Filter.1.Values.Value.1", "nonexistent-cluster")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<DBClusters"))
|
||||
.body(not(containsString("DBClusterNotFoundFault")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(21)
|
||||
void describeInstancesByFilterReturnsEmptyForMissing() {
|
||||
given()
|
||||
.header("Authorization", AUTH)
|
||||
.contentType(FORM)
|
||||
.formParam("Action", "DescribeDBInstances")
|
||||
.formParam("Filters.Filter.1.Name", "db-instance-id")
|
||||
.formParam("Filters.Filter.1.Values.Value.1", "nonexistent-instance")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<DBInstances"))
|
||||
.body(not(containsString("DBInstanceNotFound")));
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,33 @@ class DocDbServiceTest {
|
||||
assertEquals(27017, instance.getPort());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listDbClustersMatchesByArnButNotForeignArn() {
|
||||
DocDbCluster cluster = docDbService.createDbCluster(
|
||||
"mock-cluster", null, "admin", "secret", false);
|
||||
|
||||
String arn = cluster.getDbClusterArn();
|
||||
assertEquals(1, docDbService.listDbClusters(arn).size());
|
||||
assertTrue(docDbService.listDbClusters(arn.replace("000000000000", "999999999999")).isEmpty(),
|
||||
"cross-account ARN must not match");
|
||||
assertTrue(docDbService.listDbClusters(arn.replace("us-east-1", "eu-west-1")).isEmpty(),
|
||||
"cross-region ARN must not match");
|
||||
}
|
||||
|
||||
@Test
|
||||
void listDbInstancesMatchesByArnButNotForeignArn() {
|
||||
docDbService.createDbCluster("mock-cluster", null, "admin", "secret", false);
|
||||
DocDbInstance instance = docDbService.createDbInstance(
|
||||
"mock-instance", "mock-cluster", "db.r5.large", null, false);
|
||||
|
||||
String arn = instance.getDbInstanceArn();
|
||||
assertEquals(1, docDbService.listDbInstances(arn).size());
|
||||
assertTrue(docDbService.listDbInstances(arn.replace("000000000000", "999999999999")).isEmpty(),
|
||||
"cross-account ARN must not match");
|
||||
assertTrue(docDbService.listDbInstances(arn.replace("us-east-1", "eu-west-1")).isEmpty(),
|
||||
"cross-region ARN must not match");
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteClusterInMockModeSkipsContainerStop() {
|
||||
docDbService.createDbCluster("mock-cluster", null, "admin", "secret", false);
|
||||
|
||||
@@ -263,4 +263,40 @@ class NeptuneIntegrationTest {
|
||||
.statusCode(400)
|
||||
.body(containsString("UnsupportedOperation"));
|
||||
}
|
||||
|
||||
// The db-cluster-id / db-instance-id Filters form returns an empty list for a
|
||||
// missing id, unlike the DBClusterIdentifier / DBInstanceIdentifier parameter
|
||||
// which faults with 404. Mirrors AWS and the RDS behaviour.
|
||||
|
||||
@Test
|
||||
@Order(17)
|
||||
void describeClustersByFilterReturnsEmptyForMissing() {
|
||||
given()
|
||||
.header("Authorization", AUTH)
|
||||
.contentType(FORM)
|
||||
.formParam("Action", "DescribeDBClusters")
|
||||
.formParam("Filters.Filter.1.Name", "db-cluster-id")
|
||||
.formParam("Filters.Filter.1.Values.Value.1", "nonexistent-cluster")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<DBClusters"))
|
||||
.body(not(containsString("DBClusterNotFoundFault")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(18)
|
||||
void describeInstancesByFilterReturnsEmptyForMissing() {
|
||||
given()
|
||||
.header("Authorization", AUTH)
|
||||
.contentType(FORM)
|
||||
.formParam("Action", "DescribeDBInstances")
|
||||
.formParam("Filters.Filter.1.Name", "db-instance-id")
|
||||
.formParam("Filters.Filter.1.Values.Value.1", "nonexistent-instance")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<DBInstances"))
|
||||
.body(not(containsString("DBInstanceNotFound")));
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import io.github.hectorvent.floci.services.neptune.container.NeptuneContainerHan
|
||||
import io.github.hectorvent.floci.services.neptune.container.NeptuneContainerManager;
|
||||
import io.github.hectorvent.floci.services.neptune.model.NeptuneCluster;
|
||||
import io.github.hectorvent.floci.services.neptune.model.NeptuneDbType;
|
||||
import io.github.hectorvent.floci.services.neptune.model.NeptuneInstance;
|
||||
import io.github.hectorvent.floci.services.neptune.proxy.NeptuneProxyManager;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -17,6 +18,7 @@ import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
@@ -41,7 +43,7 @@ class NeptuneServiceTest {
|
||||
proxyManager = mock(NeptuneProxyManager.class);
|
||||
StorageFactory storageFactory = mock(StorageFactory.class);
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
RegionResolver regionResolver = mock(RegionResolver.class);
|
||||
RegionResolver regionResolver = new RegionResolver("us-east-1", "000000000000");
|
||||
|
||||
EmulatorConfig.ServicesConfig servicesConfig = mock(EmulatorConfig.ServicesConfig.class);
|
||||
neptuneConfig = mock(EmulatorConfig.NeptuneServiceConfig.class);
|
||||
@@ -54,10 +56,6 @@ class NeptuneServiceTest {
|
||||
when(neptuneConfig.defaultNeo4jImage()).thenReturn("neo4j:5");
|
||||
when(config.hostname()).thenReturn(Optional.of("localhost"));
|
||||
|
||||
when(regionResolver.getDefaultRegion()).thenReturn("us-east-1");
|
||||
when(regionResolver.buildArn(anyString(), anyString(), anyString()))
|
||||
.thenReturn("arn:aws:neptune:us-east-1:000000000000:cluster:c");
|
||||
|
||||
when(storageFactory.create(anyString(), anyString(), any()))
|
||||
.thenAnswer(inv -> new InMemoryStorage<>());
|
||||
when(containerManager.start(anyString(), anyString(), any(NeptuneDbType.class)))
|
||||
@@ -143,6 +141,32 @@ class NeptuneServiceTest {
|
||||
"Port from the failed create must be released so the next cluster reuses it");
|
||||
}
|
||||
|
||||
@Test
|
||||
void listDbClustersMatchesByArnButNotForeignArn() {
|
||||
NeptuneCluster cluster = service.createDbCluster("my-cluster", "1.3.2.1", false);
|
||||
|
||||
String arn = cluster.getDbClusterArn();
|
||||
assertEquals(1, service.listDbClusters(arn).size());
|
||||
assertTrue(service.listDbClusters(arn.replace("000000000000", "999999999999")).isEmpty(),
|
||||
"cross-account ARN must not match");
|
||||
assertTrue(service.listDbClusters(arn.replace("us-east-1", "eu-west-1")).isEmpty(),
|
||||
"cross-region ARN must not match");
|
||||
}
|
||||
|
||||
@Test
|
||||
void listDbInstancesMatchesByArnButNotForeignArn() {
|
||||
service.createDbCluster("my-cluster", "1.3.2.1", false);
|
||||
NeptuneInstance instance = service.createDbInstance(
|
||||
"my-instance", "my-cluster", "db.r5.large", null, false);
|
||||
|
||||
String arn = instance.getDbInstanceArn();
|
||||
assertEquals(1, service.listDbInstances(arn).size());
|
||||
assertTrue(service.listDbInstances(arn.replace("000000000000", "999999999999")).isEmpty(),
|
||||
"cross-account ARN must not match");
|
||||
assertTrue(service.listDbInstances(arn.replace("us-east-1", "eu-west-1")).isEmpty(),
|
||||
"cross-region ARN must not match");
|
||||
}
|
||||
|
||||
@Test
|
||||
void exhaustedProxyPortRangeThrowsMappableCapacityFault() {
|
||||
// Shrink the range to one port so the second create exhausts it.
|
||||
|
||||
@@ -785,6 +785,72 @@ class RdsQueryHandlerTest {
|
||||
assertTrue(((String) response.getEntity()).contains("DBSubnetGroupNotFoundFault"));
|
||||
}
|
||||
|
||||
// ─────────────── NotFound faults for missing identifiers (AWS parity) ───────────────
|
||||
|
||||
@Test
|
||||
void describeDbInstances_missingIdentifierFaultsWithDbInstanceNotFound() {
|
||||
when(service.listDbInstances("missing")).thenReturn(List.of());
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("DBInstanceIdentifier", "missing");
|
||||
Response response = handler.handle("DescribeDBInstances", p);
|
||||
|
||||
assertEquals(404, response.getStatus());
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains("<Code>DBInstanceNotFound</Code>"),
|
||||
"Expected DBInstanceNotFound error code, got: " + body);
|
||||
assertTrue(body.contains("DBInstance missing not found."),
|
||||
"Expected AWS-style message, got: " + body);
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeDbInstances_filtersFormReturnsEmptyListForMissing() {
|
||||
when(service.listDbInstances("missing")).thenReturn(List.of());
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("Filters.Filter.1.Name", "db-instance-id");
|
||||
p.add("Filters.Filter.1.Values.Value.1", "missing");
|
||||
Response response = handler.handle("DescribeDBInstances", p);
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains("<DBInstances>"),
|
||||
"Filters form must return an empty list, not fault: " + body);
|
||||
assertFalse(body.contains("DBInstanceNotFound"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeDbClusters_missingIdentifierFaultsWithDbClusterNotFoundFault() {
|
||||
when(service.listDbClusters("missing")).thenReturn(List.of());
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("DBClusterIdentifier", "missing");
|
||||
Response response = handler.handle("DescribeDBClusters", p);
|
||||
|
||||
assertEquals(404, response.getStatus());
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains("<Code>DBClusterNotFoundFault</Code>"),
|
||||
"Expected DBClusterNotFoundFault error code, got: " + body);
|
||||
assertTrue(body.contains("DBCluster missing not found."),
|
||||
"Expected AWS-style message, got: " + body);
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeDbClusters_filtersFormReturnsEmptyListForMissing() {
|
||||
when(service.listDbClusters("missing")).thenReturn(List.of());
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("Filters.Filter.1.Name", "db-cluster-id");
|
||||
p.add("Filters.Filter.1.Values.Value.1", "missing");
|
||||
Response response = handler.handle("DescribeDBClusters", p);
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains("<DBClusters>"),
|
||||
"Filters form must return an empty list, not fault: " + body);
|
||||
assertFalse(body.contains("DBClusterNotFoundFault"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── Helpers ────────────────────────────
|
||||
|
||||
private static MultivaluedMap<String, String> params() {
|
||||
|
||||
@@ -270,6 +270,50 @@ class RdsServiceTest {
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listDbInstancesMatchesByArn() {
|
||||
DbInstance created = rdsService.createDbInstance("mydb", "postgres", "13",
|
||||
"admin", "password", "dbname", "db.t3.micro",
|
||||
20, false, null, null, null, null, false);
|
||||
|
||||
Collection<DbInstance> result = rdsService.listDbInstances(created.getDbInstanceArn());
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("mydb", result.iterator().next().getDbInstanceIdentifier());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listDbClustersMatchesByArn() {
|
||||
DbCluster created = rdsService.createDbCluster("cluster1", "aurora-postgresql", "16.3",
|
||||
"admin", "password", "dbname", false, null);
|
||||
|
||||
Collection<DbCluster> result = rdsService.listDbClusters(created.getDbClusterArn());
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("cluster1", result.iterator().next().getDbClusterIdentifier());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listDbInstancesDoesNotMatchForeignArn() {
|
||||
rdsService.createDbInstance("mydb", "postgres", "13",
|
||||
"admin", "password", "dbname", "db.t3.micro",
|
||||
20, false, null, null, null, null, false);
|
||||
|
||||
assertTrue(rdsService.listDbInstances(
|
||||
"arn:aws:rds:us-east-1:999999999999:db:mydb").isEmpty(), "cross-account ARN must not match");
|
||||
assertTrue(rdsService.listDbInstances(
|
||||
"arn:aws:rds:eu-west-1:123456789012:db:mydb").isEmpty(), "cross-region ARN must not match");
|
||||
}
|
||||
|
||||
@Test
|
||||
void listDbClustersDoesNotMatchForeignArn() {
|
||||
rdsService.createDbCluster("cluster1", "aurora-postgresql", "16.3",
|
||||
"admin", "password", "dbname", false, null);
|
||||
|
||||
assertTrue(rdsService.listDbClusters(
|
||||
"arn:aws:rds:us-east-1:999999999999:cluster:cluster1").isEmpty(), "cross-account ARN must not match");
|
||||
assertTrue(rdsService.listDbClusters(
|
||||
"arn:aws:rds:eu-west-1:123456789012:cluster:cluster1").isEmpty(), "cross-region ARN must not match");
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDbInstanceBlankPasswordDoesNotOverwriteExistingPassword() {
|
||||
rdsService.createDbInstance("mydb", "postgres", "13",
|
||||
|
||||
Reference in new issue
Block a user