Skip to content

armgit / floci

Public Imported from GitHub
0

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

fix(rds): fault with DBInstanceNotFound/DBClusterNotFoundFault for missing identifiers in Describe* (#1740)

Oliver Andrews02288abc114e
diff --git a/compatibility-tests/sdk-test-go/tests/rds_test.go b/compatibility-tests/sdk-test-go/tests/rds_test.go
index 5849b0c344..43f400b03a 100644
--- a/compatibility-tests/sdk-test-go/tests/rds_test.go
+++ b/compatibility-tests/sdk-test-go/tests/rds_test.go
@@ -11,6 +11,7 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/rds"
+ "github.com/aws/aws-sdk-go-v2/service/rds/types"
_ "github.com/lib/pq"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -106,7 +107,9 @@ func TestRDSInstance(t *testing.T) {
assert.Equal(t, 1, result)
})
- // Fix #567: deleting an instance must remove it from the describe list.
+ // Fix #567: deleting an instance must remove it from the describe list. Real AWS
+ // faults DBInstanceNotFound when describing a deleted instance by identifier —
+ // this is what lets the DBInstanceDeleted waiter complete.
t.Run("DeleteDBInstance", func(t *testing.T) {
_, err := svc.DeleteDBInstance(ctx, &rds.DeleteDBInstanceInput{
DBInstanceIdentifier: aws.String(instanceId),
@@ -114,11 +117,12 @@ func TestRDSInstance(t *testing.T) {
})
require.NoError(t, err)
- out, err := svc.DescribeDBInstances(ctx, &rds.DescribeDBInstancesInput{
+ _, err = svc.DescribeDBInstances(ctx, &rds.DescribeDBInstancesInput{
DBInstanceIdentifier: aws.String(instanceId),
})
- require.NoError(t, err)
- assert.Empty(t, out.DBInstances, "deleted instance must not appear in describe")
+ var notFound *types.DBInstanceNotFoundFault
+ require.ErrorAs(t, err, &notFound,
+ "describe of a deleted instance must fault DBInstanceNotFound")
})
}
@@ -167,7 +171,9 @@ func TestRDSCluster(t *testing.T) {
"DBCluster.DBSubnetGroup must be a non-nil string (shape: String in AWS service model)")
})
- // Fix #567: deleting a cluster must remove it from the describe list.
+ // Fix #567: deleting a cluster must remove it from the describe list. Real AWS
+ // faults DBClusterNotFoundFault when describing a deleted cluster by identifier —
+ // this is what lets the DBClusterDeleted waiter complete.
t.Run("DeleteDBCluster", func(t *testing.T) {
_, err := svc.DeleteDBCluster(ctx, &rds.DeleteDBClusterInput{
DBClusterIdentifier: aws.String(clusterId),
@@ -175,11 +181,12 @@ func TestRDSCluster(t *testing.T) {
})
require.NoError(t, err)
- out, err := svc.DescribeDBClusters(ctx, &rds.DescribeDBClustersInput{
+ _, err = svc.DescribeDBClusters(ctx, &rds.DescribeDBClustersInput{
DBClusterIdentifier: aws.String(clusterId),
})
- require.NoError(t, err)
- assert.Empty(t, out.DBClusters, "deleted cluster must not appear in describe")
+ var notFound *types.DBClusterNotFoundFault
+ require.ErrorAs(t, err, &notFound,
+ "describe of a deleted cluster must fault DBClusterNotFoundFault")
})
}
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsJdbcCompatTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsJdbcCompatTest.java
index 324ee10b5e..46cea3523b 100644
--- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsJdbcCompatTest.java
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsJdbcCompatTest.java
@@ -15,9 +15,9 @@ import software.amazon.awssdk.services.rds.RdsClient;
import software.amazon.awssdk.services.rds.model.CreateDbInstanceRequest;
import software.amazon.awssdk.services.rds.model.CreateDbInstanceResponse;
import software.amazon.awssdk.services.rds.model.DBInstance;
+import software.amazon.awssdk.services.rds.model.DbInstanceNotFoundException;
import software.amazon.awssdk.services.rds.model.DeleteDbInstanceRequest;
import software.amazon.awssdk.services.rds.model.DescribeDbInstancesRequest;
-import software.amazon.awssdk.services.rds.model.DescribeDbInstancesResponse;
import software.amazon.awssdk.services.rds.model.GenerateAuthenticationTokenRequest;
import software.amazon.awssdk.services.rds.model.ModifyDbInstanceRequest;
@@ -306,10 +306,13 @@ class RdsJdbcCompatTest {
.build());
instanceCreated = false;
- DescribeDbInstancesResponse afterDelete = rds.describeDBInstances(DescribeDbInstancesRequest.builder()
- .dbInstanceIdentifier(instanceId)
- .build());
- assertThat(afterDelete.dbInstances()).isEmpty();
+ // Real AWS faults DBInstanceNotFound when describing a deleted instance by
+ // identifier — this is what lets the DBInstanceDeleted waiter complete.
+ String deletedId = instanceId;
+ assertThatThrownBy(() -> rds.describeDBInstances(DescribeDbInstancesRequest.builder()
+ .dbInstanceIdentifier(deletedId)
+ .build()))
+ .isInstanceOf(DbInstanceNotFoundException.class);
String replacementId = TestFixtures.uniqueName("rds-pg");
CreateDbInstanceResponse replacement = rds.createDBInstance(CreateDbInstanceRequest.builder()
diff --git a/src/main/java/io/github/hectorvent/floci/services/docdb/DocDbQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/docdb/DocDbQueryHandler.java
index 13ae93b732..85e936c5ea 100644
--- a/src/main/java/io/github/hectorvent/floci/services/docdb/DocDbQueryHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/docdb/DocDbQueryHandler.java
@@ -75,14 +75,17 @@ public class DocDbQueryHandler {
}
private Response handleDescribeDbClusters(MultivaluedMap<String, String> params) {
- String filterId = params.getFirst("DBClusterIdentifier");
+ String identifier = params.getFirst("DBClusterIdentifier");
+ String filterId = identifier;
if (filterId == null || filterId.isBlank()) {
filterId = extractFilterValue(params, "db-cluster-id");
}
- // When a specific cluster ID is requested, AWS returns 404 if not found
- if (filterId != null && !filterId.isBlank()) {
- service.getDbCluster(filterId); // throws DBClusterNotFoundFault if absent
+ // AWS parity: the DBClusterIdentifier parameter faults with
+ // DBClusterNotFoundFault when no cluster matches, while the
+ // db-cluster-id Filters form returns an empty list.
+ if (identifier != null && !identifier.isBlank()) {
+ service.getDbCluster(identifier); // throws DBClusterNotFoundFault if absent
}
Collection<DocDbCluster> result = service.listDbClusters(filterId);
@@ -154,13 +157,17 @@ public class DocDbQueryHandler {
}
private Response handleDescribeDbInstances(MultivaluedMap<String, String> params) {
- String filterId = params.getFirst("DBInstanceIdentifier");
+ String identifier = params.getFirst("DBInstanceIdentifier");
+ String filterId = identifier;
if (filterId == null || filterId.isBlank()) {
filterId = extractFilterValue(params, "db-instance-id");
}
- if (filterId != null && !filterId.isBlank()) {
- service.getDbInstance(filterId); // throws DBInstanceNotFound if absent
+ // AWS parity: the DBInstanceIdentifier parameter faults with
+ // DBInstanceNotFound when no instance matches, while the
+ // db-instance-id Filters form returns an empty list.
+ if (identifier != null && !identifier.isBlank()) {
+ service.getDbInstance(identifier); // throws DBInstanceNotFound if absent
}
Collection<DocDbInstance> result = service.listDbInstances(filterId);
diff --git a/src/main/java/io/github/hectorvent/floci/services/docdb/DocDbService.java b/src/main/java/io/github/hectorvent/floci/services/docdb/DocDbService.java
index 82ede0b73b..cf2462af24 100644
--- a/src/main/java/io/github/hectorvent/floci/services/docdb/DocDbService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/docdb/DocDbService.java
@@ -116,6 +116,15 @@ public class DocDbService {
public Collection<DocDbCluster> listDbClusters(String filterId) {
if (filterId != null && !filterId.isBlank()) {
+ // The db-cluster-id filter accepts ARNs as well as identifiers. Match the
+ // full ARN against each cluster's stored ARN rather than reducing it to
+ // the bare identifier, so a cross-account or cross-region ARN does not
+ // resolve a same-named local cluster.
+ if (filterId.startsWith("arn:")) {
+ return clusters.scan(k -> true).stream()
+ .filter(c -> filterId.equalsIgnoreCase(c.getDbClusterArn()))
+ .toList();
+ }
return clusters.scan(k -> k.equalsIgnoreCase(filterId));
}
return clusters.scan(k -> true);
@@ -200,6 +209,13 @@ public class DocDbService {
public Collection<DocDbInstance> listDbInstances(String filterId) {
if (filterId != null && !filterId.isBlank()) {
+ // The db-instance-id filter accepts ARNs as well as identifiers; see
+ // listDbClusters for why the match is against the stored ARN.
+ if (filterId.startsWith("arn:")) {
+ return instances.scan(k -> true).stream()
+ .filter(i -> filterId.equalsIgnoreCase(i.getDbInstanceArn()))
+ .toList();
+ }
return instances.scan(k -> k.equalsIgnoreCase(filterId));
}
return instances.scan(k -> true);
diff --git a/src/main/java/io/github/hectorvent/floci/services/neptune/NeptuneQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/neptune/NeptuneQueryHandler.java
index 4eed595fa5..6250673c64 100644
--- a/src/main/java/io/github/hectorvent/floci/services/neptune/NeptuneQueryHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/neptune/NeptuneQueryHandler.java
@@ -69,14 +69,17 @@ public class NeptuneQueryHandler {
}
private Response handleDescribeDbClusters(MultivaluedMap<String, String> params) {
- String filterId = params.getFirst("DBClusterIdentifier");
+ String identifier = params.getFirst("DBClusterIdentifier");
+ String filterId = identifier;
if (filterId == null || filterId.isBlank()) {
filterId = extractFilterValue(params, "db-cluster-id");
}
- // When a specific cluster ID is requested, AWS returns 404 if not found
- if (filterId != null && !filterId.isBlank()) {
- service.getDbCluster(filterId); // throws DBClusterNotFoundFault if absent
+ // AWS parity: the DBClusterIdentifier parameter faults with
+ // DBClusterNotFoundFault when no cluster matches, while the
+ // db-cluster-id Filters form returns an empty list.
+ if (identifier != null && !identifier.isBlank()) {
+ service.getDbCluster(identifier); // throws DBClusterNotFoundFault if absent
}
Collection<NeptuneCluster> result = service.listDbClusters(filterId);
@@ -140,13 +143,17 @@ public class NeptuneQueryHandler {
}
private Response handleDescribeDbInstances(MultivaluedMap<String, String> params) {
- String filterId = params.getFirst("DBInstanceIdentifier");
+ String identifier = params.getFirst("DBInstanceIdentifier");
+ String filterId = identifier;
if (filterId == null || filterId.isBlank()) {
filterId = extractFilterValue(params, "db-instance-id");
}
- if (filterId != null && !filterId.isBlank()) {
- service.getDbInstance(filterId); // throws DBInstanceNotFound if absent
+ // AWS parity: the DBInstanceIdentifier parameter faults with
+ // DBInstanceNotFound when no instance matches, while the
+ // db-instance-id Filters form returns an empty list.
+ if (identifier != null && !identifier.isBlank()) {
+ service.getDbInstance(identifier); // throws DBInstanceNotFound if absent
}
Collection<NeptuneInstance> result = service.listDbInstances(filterId);
diff --git a/src/main/java/io/github/hectorvent/floci/services/neptune/NeptuneService.java b/src/main/java/io/github/hectorvent/floci/services/neptune/NeptuneService.java
index 765f0823c4..a3bdf7088a 100644
--- a/src/main/java/io/github/hectorvent/floci/services/neptune/NeptuneService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/neptune/NeptuneService.java
@@ -173,6 +173,15 @@ public class NeptuneService {
public Collection<NeptuneCluster> listDbClusters(String filterId) {
if (filterId != null && !filterId.isBlank()) {
+ // The db-cluster-id filter accepts ARNs as well as identifiers. Match the
+ // full ARN against each cluster's stored ARN rather than reducing it to
+ // the bare identifier, so a cross-account or cross-region ARN does not
+ // resolve a same-named local cluster.
+ if (filterId.startsWith("arn:")) {
+ return clusters.scan(k -> true).stream()
+ .filter(c -> filterId.equalsIgnoreCase(c.getDbClusterArn()))
+ .toList();
+ }
return clusters.scan(k -> k.equalsIgnoreCase(filterId));
}
return clusters.scan(k -> true);
@@ -260,6 +269,13 @@ public class NeptuneService {
public Collection<NeptuneInstance> listDbInstances(String filterId) {
if (filterId != null && !filterId.isBlank()) {
+ // The db-instance-id filter accepts ARNs as well as identifiers; see
+ // listDbClusters for why the match is against the stored ARN.
+ if (filterId.startsWith("arn:")) {
+ return instances.scan(k -> true).stream()
+ .filter(i -> filterId.equalsIgnoreCase(i.getDbInstanceArn()))
+ .toList();
+ }
return instances.scan(k -> k.equalsIgnoreCase(filterId));
}
return instances.scan(k -> true);
diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java
index 21507f7f4f..27ae091a14 100644
--- a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java
@@ -138,12 +138,20 @@ public class RdsQueryHandler {
}
private Response handleDescribeDbInstances(MultivaluedMap<String, String> params) {
- String filterId = params.getFirst("DBInstanceIdentifier");
+ String identifier = params.getFirst("DBInstanceIdentifier");
+ String filterId = identifier;
if (filterId == null || filterId.isBlank()) {
filterId = extractRdsFilterValue(params, "db-instance-id");
}
try {
Collection<DbInstance> result = service.listDbInstances(filterId);
+ // AWS parity: the DBInstanceIdentifier PARAMETER faults with
+ // DBInstanceNotFound when no instance matches, while the
+ // db-instance-id Filters form returns an empty list.
+ if (identifier != null && !identifier.isBlank() && result.isEmpty()) {
+ throw new AwsException("DBInstanceNotFound",
+ "DBInstance " + identifier + " not found.", 404);
+ }
XmlBuilder xml = new XmlBuilder().start("DBInstances");
for (DbInstance i : result) {
xml.start("DBInstance").raw(dbInstanceInnerXml(i)).end("DBInstance");
@@ -357,12 +365,20 @@ public class RdsQueryHandler {
}
private Response handleDescribeDbClusters(MultivaluedMap<String, String> params) {
- String filterId = params.getFirst("DBClusterIdentifier");
+ String identifier = params.getFirst("DBClusterIdentifier");
+ String filterId = identifier;
if (filterId == null || filterId.isBlank()) {
filterId = extractRdsFilterValue(params, "db-cluster-id");
}
try {
Collection<DbCluster> result = service.listDbClusters(filterId);
+ // AWS parity: the DBClusterIdentifier PARAMETER faults with
+ // DBClusterNotFoundFault when no cluster matches, while the
+ // db-cluster-id Filters form returns an empty list.
+ if (identifier != null && !identifier.isBlank() && result.isEmpty()) {
+ throw new AwsException("DBClusterNotFoundFault",
+ "DBCluster " + identifier + " not found.", 404);
+ }
XmlBuilder xml = new XmlBuilder().start("DBClusters");
for (DbCluster c : result) {
xml.start("DBCluster").raw(dbClusterInnerXml(c)).end("DBCluster");
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 a2ed77be7b..53f38a7893 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
@@ -523,6 +523,15 @@ public class RdsService implements Resettable {
public Collection<DbInstance> listDbInstances(String filterId) {
if (filterId != null && !filterId.isBlank()) {
+ // DBInstanceIdentifier also accepts an ARN per the AWS model. Match the
+ // full ARN against each instance's stored ARN rather than reducing it to
+ // the bare identifier, so a cross-account or cross-region ARN does not
+ // resolve a same-named local instance.
+ if (filterId.startsWith("arn:")) {
+ return instances.scan(k -> true).stream()
+ .filter(i -> filterId.equalsIgnoreCase(i.getDbInstanceArn()))
+ .toList();
+ }
return instances.scan(k -> k.equalsIgnoreCase(filterId));
}
return instances.scan(k -> true);
@@ -747,6 +756,15 @@ public class RdsService implements Resettable {
public Collection<DbCluster> listDbClusters(String filterId) {
if (filterId != null && !filterId.isBlank()) {
+ // DBClusterIdentifier also accepts an ARN per the AWS model. Match the
+ // full ARN against each cluster's stored ARN rather than reducing it to
+ // the bare identifier, so a cross-account or cross-region ARN does not
+ // resolve a same-named local cluster.
+ if (filterId.startsWith("arn:")) {
+ return clusters.scan(k -> true).stream()
+ .filter(c -> filterId.equalsIgnoreCase(c.getDbClusterArn()))
+ .toList();
+ }
return clusters.scan(k -> k.equalsIgnoreCase(filterId));
}
return clusters.scan(k -> true);
diff --git a/src/test/java/io/github/hectorvent/floci/services/docdb/DocDbIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/docdb/DocDbIntegrationTest.java
index 831f4db4a6..18d13e1ee4 100644
--- a/src/test/java/io/github/hectorvent/floci/services/docdb/DocDbIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/docdb/DocDbIntegrationTest.java
@@ -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")));
+ }
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/docdb/DocDbServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/docdb/DocDbServiceTest.java
index 02d5870657..afd2692c9a 100644
--- a/src/test/java/io/github/hectorvent/floci/services/docdb/DocDbServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/docdb/DocDbServiceTest.java
@@ -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);
diff --git a/src/test/java/io/github/hectorvent/floci/services/neptune/NeptuneIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/neptune/NeptuneIntegrationTest.java
index b9098c756a..ae64b706f1 100644
--- a/src/test/java/io/github/hectorvent/floci/services/neptune/NeptuneIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/neptune/NeptuneIntegrationTest.java
@@ -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")));
+ }
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/neptune/NeptuneServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/neptune/NeptuneServiceTest.java
index 4dc0b2ac3a..18c87b9fb3 100644
--- a/src/test/java/io/github/hectorvent/floci/services/neptune/NeptuneServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/neptune/NeptuneServiceTest.java
@@ -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.
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 ec484ba433..06f383b747 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
@@ -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() {
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 7e2cc3ca2c..1720e86641 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
@@ -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",