mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -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
@@ -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, ¬Found,
|
||||
"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, ¬Found,
|
||||
"describe of a deleted cluster must fault DBClusterNotFoundFault")
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+8
-5
@@ -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()
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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