mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(rds): preserve network placement metadata (#1735)
* fix(rds): honor request region for subnet placement * fix(rds): persist DB instance VPC security groups * docs: sync service action tables * fix(rds): tidy region-aware query dispatch
This commit is contained in:
1 parent
10f799a2b7
commit
fe2008848f
9 files changed
+450
-106
No files matched your search
+64
-7
@@ -21,6 +21,8 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyList;
|
||||
import static org.mockito.ArgumentMatchers.anyMap;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -62,8 +64,12 @@ class RdsCfnProvisionerTest {
|
||||
}
|
||||
|
||||
private StackResource provision(String logicalId, String type, String json) {
|
||||
return provision(logicalId, type, json, "us-east-1");
|
||||
}
|
||||
|
||||
private StackResource provision(String logicalId, String type, String json, String region) {
|
||||
return provisioner.provision(logicalId, type, props(json), engine(),
|
||||
"us-east-1", "000000000000", "my-stack");
|
||||
region, "000000000000", "my-stack");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +79,8 @@ class RdsCfnProvisionerTest {
|
||||
when(instance.getEndpoint()).thenReturn(new DbEndpoint("mydb.local", 5432));
|
||||
when(instance.getDbInstanceArn()).thenReturn("arn:aws:rds:us-east-1:000000000000:db:mydb");
|
||||
when(rdsService.createDbInstance(any(), any(), any(), any(), any(), any(), any(),
|
||||
anyInt(), anyBoolean(), any(), any(), any())).thenReturn(instance);
|
||||
anyInt(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), anyBoolean(),
|
||||
any(), anyMap(), nullable(String.class))).thenReturn(instance);
|
||||
|
||||
StackResource r = provision("Db", "AWS::RDS::DBInstance", """
|
||||
{"DBInstanceIdentifier":"mydb","Engine":"postgres","EngineVersion":"16",
|
||||
@@ -88,7 +95,26 @@ class RdsCfnProvisionerTest {
|
||||
assertEquals("arn:aws:rds:us-east-1:000000000000:db:mydb", r.getAttributes().get("DBInstanceArn"));
|
||||
// CFN properties mapped to the create-method arguments; absent optionals are null.
|
||||
verify(rdsService).createDbInstance("mydb", "postgres", "16", "admin", "secret",
|
||||
"appdb", "db.t3.small", 50, false, null, null, null);
|
||||
"appdb", "db.t3.small", 50, false, null, null, null,
|
||||
null, false, false, null, Map.of(), "us-east-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void provisionsDbInstanceInStackRegion() {
|
||||
DbInstance instance = mock(DbInstance.class);
|
||||
when(instance.getDbInstanceIdentifier()).thenReturn("mydb");
|
||||
when(rdsService.createDbInstance(any(), any(), any(), any(), any(), any(), any(),
|
||||
anyInt(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), anyBoolean(),
|
||||
any(), anyMap(), nullable(String.class))).thenReturn(instance);
|
||||
|
||||
provision("Db", "AWS::RDS::DBInstance", """
|
||||
{"DBInstanceIdentifier":"mydb","Engine":"postgres","MasterUsername":"admin",
|
||||
"MasterUserPassword":"secret"}
|
||||
""", "us-west-2");
|
||||
|
||||
verify(rdsService).createDbInstance("mydb", "postgres", null, "admin", "secret",
|
||||
null, "db.t3.micro", 20, false, null, null, null,
|
||||
null, false, false, null, Map.of(), "us-west-2");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,7 +124,8 @@ class RdsCfnProvisionerTest {
|
||||
when(cluster.getEndpoint()).thenReturn(new DbEndpoint("mycluster.local", 5432));
|
||||
when(cluster.getReaderEndpoint()).thenReturn(new DbEndpoint("mycluster-ro.local", 5432));
|
||||
when(cluster.getDbClusterArn()).thenReturn("arn:aws:rds:us-east-1:000000000000:cluster:mycluster");
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any()))
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any()))
|
||||
.thenReturn(cluster);
|
||||
|
||||
StackResource r = provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
@@ -111,14 +138,30 @@ class RdsCfnProvisionerTest {
|
||||
assertEquals("mycluster-ro.local", r.getAttributes().get("ReadEndpoint.Address"));
|
||||
assertEquals("5432", r.getAttributes().get("Endpoint.Port"));
|
||||
verify(rdsService).createDbCluster("mycluster", "aurora-postgresql", "16.3",
|
||||
"admin", "secret", "appdb", false, null);
|
||||
"admin", "secret", "appdb", false, null, null, null, false, "us-east-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void provisionsDbClusterInStackRegion() {
|
||||
DbCluster cluster = mock(DbCluster.class);
|
||||
when(cluster.getDbClusterIdentifier()).thenReturn("mycluster");
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any()))
|
||||
.thenReturn(cluster);
|
||||
|
||||
provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
{"DBClusterIdentifier":"mycluster","Engine":"aurora-postgresql"}
|
||||
""", "us-west-2");
|
||||
|
||||
verify(rdsService).createDbCluster("mycluster", "aurora-postgresql", null,
|
||||
null, null, null, false, null, null, null, false, "us-west-2");
|
||||
}
|
||||
|
||||
@Test
|
||||
void provisionsDbSubnetGroupWithResolvedSubnetIds() {
|
||||
DbSubnetGroup group = mock(DbSubnetGroup.class);
|
||||
when(group.getDbSubnetGroupName()).thenReturn("my-subnet-group");
|
||||
when(rdsService.createDbSubnetGroup(any(), any(), anyList())).thenReturn(group);
|
||||
when(rdsService.createDbSubnetGroup(any(), any(), anyList(), any())).thenReturn(group);
|
||||
|
||||
StackResource r = provision("Sg", "AWS::RDS::DBSubnetGroup", """
|
||||
{"DBSubnetGroupName":"my-subnet-group","DBSubnetGroupDescription":"db subnets",
|
||||
@@ -128,7 +171,21 @@ class RdsCfnProvisionerTest {
|
||||
assertEquals("my-subnet-group", r.getPhysicalId());
|
||||
assertEquals("my-subnet-group", r.getAttributes().get("DBSubnetGroupName"));
|
||||
verify(rdsService).createDbSubnetGroup("my-subnet-group", "db subnets",
|
||||
List.of("subnet-a", "subnet-b"));
|
||||
List.of("subnet-a", "subnet-b"), "us-east-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void provisionsDbSubnetGroupInStackRegion() {
|
||||
DbSubnetGroup group = mock(DbSubnetGroup.class);
|
||||
when(group.getDbSubnetGroupName()).thenReturn("my-subnet-group");
|
||||
when(rdsService.createDbSubnetGroup(any(), any(), anyList(), any())).thenReturn(group);
|
||||
|
||||
provision("Sg", "AWS::RDS::DBSubnetGroup", """
|
||||
{"DBSubnetGroupName":"my-subnet-group","SubnetIds":["subnet-a"]}
|
||||
""", "us-west-2");
|
||||
|
||||
verify(rdsService).createDbSubnetGroup("my-subnet-group", "Managed by CloudFormation",
|
||||
List.of("subnet-a"), "us-west-2");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -38,7 +38,6 @@ class RdsQueryHandlerTest {
|
||||
when(config.services()).thenReturn(servicesConfig);
|
||||
when(servicesConfig.rds()).thenReturn(rdsConfig);
|
||||
when(config.defaultAvailabilityZone()).thenReturn("us-east-1a");
|
||||
when(service.resolveDbSubnetGroupView(nullable(String.class))).thenReturn(defaultSubnetGroup());
|
||||
handler = new RdsQueryHandler(service, config);
|
||||
}
|
||||
|
||||
@@ -126,7 +125,7 @@ class RdsQueryHandlerTest {
|
||||
void describeDbInstances_dbSubnetGroupUsesSubnetTag() {
|
||||
DbInstance instance = makeInstance("mydb");
|
||||
instance.setDbSubnetGroupName("custom-group");
|
||||
when(service.resolveDbSubnetGroupView("custom-group")).thenReturn(customSubnetGroup());
|
||||
when(service.getDbSubnetGroup("custom-group")).thenReturn(customSubnetGroup());
|
||||
when(service.listDbInstances(null)).thenReturn(List.of(instance));
|
||||
|
||||
Response response = handler.handle("DescribeDBInstances", params());
|
||||
@@ -216,7 +215,7 @@ class RdsQueryHandlerTest {
|
||||
when(service.createDbInstance(eq("mydb"), eq("postgres"), eq("16.3"),
|
||||
eq(null), eq(null), eq(null), eq("db.t3.micro"),
|
||||
eq(20), eq(false), eq(null), eq(null), eq(null), eq(null), eq(false), eq(false), eq(null),
|
||||
eq(java.util.Map.of("example:ClusterId", "cluster-a", "Name", "mydb"))))
|
||||
eq(java.util.Map.of("example:ClusterId", "cluster-a", "Name", "mydb")), eq(List.of()), isNull()))
|
||||
.thenReturn(instance);
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
@@ -230,7 +229,61 @@ class RdsQueryHandlerTest {
|
||||
|
||||
verify(service).createDbInstance("mydb", "postgres", "16.3",
|
||||
null, null, null, "db.t3.micro", 20, false, null, null, null, null, false, false, null,
|
||||
java.util.Map.of("example:ClusterId", "cluster-a", "Name", "mydb"));
|
||||
java.util.Map.of("example:ClusterId", "cluster-a", "Name", "mydb"), List.of(), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstance_passesVpcSecurityGroupsToServiceAndXml() {
|
||||
DbInstance instance = makeInstance("mydb");
|
||||
instance.setVpcSecurityGroupIds(List.of("sg-123", "sg-456"));
|
||||
when(service.createDbInstance(eq("mydb"), eq("postgres"), eq("16.3"),
|
||||
eq(null), eq(null), eq(null), eq("db.t3.micro"),
|
||||
eq(20), eq(false), eq(null), eq(null), eq(null), eq(null), eq(false), eq(false), eq(null),
|
||||
eq(java.util.Map.of()), eq(List.of("sg-123", "sg-456")), isNull()))
|
||||
.thenReturn(instance);
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("DBInstanceIdentifier", "mydb");
|
||||
p.add("Engine", "postgres");
|
||||
p.add("VpcSecurityGroupIds.VpcSecurityGroupId.1", "sg-123");
|
||||
p.add("VpcSecurityGroupIds.VpcSecurityGroupId.2", "sg-456");
|
||||
Response response = handler.handle("CreateDBInstance", p);
|
||||
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains("<VpcSecurityGroupId>sg-123</VpcSecurityGroupId>"));
|
||||
assertTrue(body.contains("<VpcSecurityGroupId>sg-456</VpcSecurityGroupId>"));
|
||||
verify(service).createDbInstance("mydb", "postgres", "16.3",
|
||||
null, null, null, "db.t3.micro", 20, false, null, null, null, null, false, false, null,
|
||||
java.util.Map.of(), List.of("sg-123", "sg-456"), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstanceRejectsBlankVpcSecurityGroupMembers() {
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("DBInstanceIdentifier", "mydb");
|
||||
p.add("Engine", "postgres");
|
||||
p.add("VpcSecurityGroupIds.VpcSecurityGroupId.1", " ");
|
||||
|
||||
Response response = handler.handle("CreateDBInstance", p);
|
||||
|
||||
assertEquals(400, response.getStatus());
|
||||
assertTrue(((String) response.getEntity()).contains("InvalidParameterValue"));
|
||||
verify(service, never()).createDbInstance(any(), any(), any(), any(), any(), any(), any(),
|
||||
anyInt(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), anyBoolean(),
|
||||
any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDbInstanceRejectsBlankVpcSecurityGroupMembers() {
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("DBInstanceIdentifier", "mydb");
|
||||
p.add("VpcSecurityGroupIds.VpcSecurityGroupId.1", "");
|
||||
|
||||
Response response = handler.handle("ModifyDBInstance", p);
|
||||
|
||||
assertEquals(400, response.getStatus());
|
||||
assertTrue(((String) response.getEntity()).contains("InvalidParameterValue"));
|
||||
verify(service, never()).modifyDbInstance(any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -306,7 +359,7 @@ class RdsQueryHandlerTest {
|
||||
when(service.createDbInstance(eq("mydb"), eq("postgres"), eq("16.3"),
|
||||
eq("admin"), eq("secret"), eq("dbname"), eq("db.t3.micro"),
|
||||
eq(20), eq(false), eq(null), eq(null), eq(null), eq(null), eq(false), eq(false),
|
||||
eq(null), eq(java.util.Map.of())))
|
||||
eq(null), eq(java.util.Map.of()), eq(List.of()), isNull()))
|
||||
.thenReturn(instance);
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
@@ -320,7 +373,7 @@ class RdsQueryHandlerTest {
|
||||
|
||||
verify(service).createDbInstance("mydb", "postgres", "16.3",
|
||||
"admin", "secret", "dbname", "db.t3.micro", 20, false, null, null, null, null, false, false,
|
||||
null, java.util.Map.of());
|
||||
null, java.util.Map.of(), List.of(), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -332,7 +385,7 @@ class RdsQueryHandlerTest {
|
||||
when(service.createDbInstance(eq("mydb"), eq("postgres"), eq("16.3"),
|
||||
eq("admin"), eq(null), eq("dbname"), eq("db.t3.micro"),
|
||||
eq(20), eq(false), eq(null), eq(null), eq(null), eq(null), eq(false), eq(true),
|
||||
eq("kms-key-1"), eq(java.util.Map.of())))
|
||||
eq("kms-key-1"), eq(java.util.Map.of()), eq(List.of()), isNull()))
|
||||
.thenReturn(instance);
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
@@ -351,19 +404,20 @@ class RdsQueryHandlerTest {
|
||||
assertTrue(body.contains("<KmsKeyId>kms-key-1</KmsKeyId>"));
|
||||
verify(service).createDbInstance("mydb", "postgres", "16.3",
|
||||
"admin", null, "dbname", "db.t3.micro", 20, false, null, null, null, null, false, true,
|
||||
"kms-key-1", java.util.Map.of());
|
||||
"kms-key-1", java.util.Map.of(), List.of(), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstance_withPlacementInputsShouldReflectRequestedPlacement() {
|
||||
DbInstance instance = makeInstance("mydb");
|
||||
instance.setDbInstanceArn("arn:aws:rds:us-east-1:123456789012:db:mydb");
|
||||
instance.setDbSubnetGroupName("default");
|
||||
instance.setAvailabilityZone("ap-northeast-1a");
|
||||
instance.setMultiAz(true);
|
||||
when(service.createDbInstance(eq("mydb"), eq("postgres"), eq("16.3"),
|
||||
eq("admin"), eq("secret"), eq("dbname"), eq("db.t3.micro"),
|
||||
eq(20), eq(false), eq(null), eq("default"), eq(null), eq("ap-northeast-1a"), eq(true),
|
||||
eq(false), eq(null), eq(java.util.Map.of())))
|
||||
eq(false), eq(null), eq(java.util.Map.of()), eq(List.of()), isNull()))
|
||||
.thenReturn(instance);
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
@@ -391,7 +445,7 @@ class RdsQueryHandlerTest {
|
||||
when(service.createDbInstance(eq("mydb"), eq("postgres"), eq("16.3"),
|
||||
eq("admin"), eq("secret"), eq("dbname"), eq("db.t3.micro"),
|
||||
eq(20), eq(false), eq(null), eq("missing-subnet-group"), eq(null), eq(null), eq(false),
|
||||
eq(false), eq(null), eq(java.util.Map.of())))
|
||||
eq(false), eq(null), eq(java.util.Map.of()), eq(List.of()), isNull()))
|
||||
.thenThrow(new AwsException("DBSubnetGroupNotFoundFault",
|
||||
"DB subnet group missing-subnet-group not found.", 404));
|
||||
|
||||
@@ -411,7 +465,7 @@ class RdsQueryHandlerTest {
|
||||
|
||||
@Test
|
||||
void createDbSubnetGroup_passesSubnetMembersToService() {
|
||||
when(service.createDbSubnetGroup("sample-db-subnets", "test", List.of("subnet-aaa", "subnet-bbb")))
|
||||
when(service.createDbSubnetGroup("sample-db-subnets", "test", List.of("subnet-aaa", "subnet-bbb"), null))
|
||||
.thenReturn(new DbSubnetGroup(
|
||||
"sample-db-subnets", "test", "vpc-123", List.of("subnet-aaa", "subnet-bbb"),
|
||||
Map.of("subnet-aaa", "us-east-1a", "subnet-bbb", "us-east-1b")));
|
||||
@@ -423,7 +477,7 @@ class RdsQueryHandlerTest {
|
||||
p.add("SubnetIds.SubnetIdentifier.2", "subnet-bbb");
|
||||
Response response = handler.handle("CreateDBSubnetGroup", p);
|
||||
|
||||
verify(service).createDbSubnetGroup("sample-db-subnets", "test", List.of("subnet-aaa", "subnet-bbb"));
|
||||
verify(service).createDbSubnetGroup("sample-db-subnets", "test", List.of("subnet-aaa", "subnet-bbb"), null);
|
||||
String body = (String) response.getEntity();
|
||||
assertEquals(200, response.getStatus());
|
||||
assertTrue(body.contains("<DBSubnetGroupName>sample-db-subnets</DBSubnetGroupName>"));
|
||||
@@ -433,9 +487,28 @@ class RdsQueryHandlerTest {
|
||||
assertTrue(body.contains("<SubnetIdentifier>subnet-bbb</SubnetIdentifier>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbSubnetGroupPassesRequestRegionToService() {
|
||||
when(service.createDbSubnetGroup("sample-db-subnets", "test", List.of("subnet-aaa", "subnet-bbb"), "us-west-2"))
|
||||
.thenReturn(new DbSubnetGroup(
|
||||
"sample-db-subnets", "test", "vpc-123", List.of("subnet-aaa", "subnet-bbb"),
|
||||
Map.of("subnet-aaa", "us-west-2a", "subnet-bbb", "us-west-2b")));
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("DBSubnetGroupName", "sample-db-subnets");
|
||||
p.add("DBSubnetGroupDescription", "test");
|
||||
p.add("SubnetIds.SubnetIdentifier.1", "subnet-aaa");
|
||||
p.add("SubnetIds.SubnetIdentifier.2", "subnet-bbb");
|
||||
|
||||
Response response = handler.handle("CreateDBSubnetGroup", p, "us-west-2");
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
verify(service).createDbSubnetGroup("sample-db-subnets", "test", List.of("subnet-aaa", "subnet-bbb"), "us-west-2");
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDbSubnetGroup_passesSubnetMembersToService() {
|
||||
when(service.modifyDbSubnetGroup("sample-db-subnets", List.of("subnet-new-a", "subnet-new-b")))
|
||||
when(service.modifyDbSubnetGroup("sample-db-subnets", List.of("subnet-new-a", "subnet-new-b"), null))
|
||||
.thenReturn(new DbSubnetGroup(
|
||||
"sample-db-subnets", "test", "vpc-123", List.of("subnet-new-a", "subnet-new-b"),
|
||||
Map.of("subnet-new-a", "us-east-1a", "subnet-new-b", "us-east-1b")));
|
||||
@@ -446,7 +519,7 @@ class RdsQueryHandlerTest {
|
||||
p.add("SubnetIds.SubnetIdentifier.2", "subnet-new-b");
|
||||
Response response = handler.handle("ModifyDBSubnetGroup", p);
|
||||
|
||||
verify(service).modifyDbSubnetGroup("sample-db-subnets", List.of("subnet-new-a", "subnet-new-b"));
|
||||
verify(service).modifyDbSubnetGroup("sample-db-subnets", List.of("subnet-new-a", "subnet-new-b"), null);
|
||||
String body = (String) response.getEntity();
|
||||
assertEquals(200, response.getStatus());
|
||||
assertTrue(body.contains("<DBSubnetGroupName>sample-db-subnets</DBSubnetGroupName>"));
|
||||
@@ -464,7 +537,7 @@ class RdsQueryHandlerTest {
|
||||
when(service.createDbInstance(eq("mydb"), eq("oracle"), eq("1.0"),
|
||||
eq(null), eq(null), eq(null), eq("db.t3.micro"),
|
||||
eq(20), eq(false), eq(null), eq(null), eq(null), eq(null), eq(false), eq(false),
|
||||
eq(null), eq(java.util.Map.of())))
|
||||
eq(null), eq(java.util.Map.of()), eq(List.of()), isNull()))
|
||||
.thenThrow(new AwsException("InvalidParameterValue",
|
||||
"Unsupported engine: oracle. Supported: postgres, mysql, mariadb.", 400));
|
||||
|
||||
@@ -615,7 +688,7 @@ class RdsQueryHandlerTest {
|
||||
group.setVpcId("vpc-12345678");
|
||||
group.setSubnetIds(List.of("subnet-a", "subnet-b"));
|
||||
group.setSubnetAvailabilityZones(Map.of("subnet-a", "us-east-1a", "subnet-b", "us-east-1b"));
|
||||
when(service.createDbSubnetGroup("my-subnet-group", "test subnet group", List.of("subnet-a", "subnet-b")))
|
||||
when(service.createDbSubnetGroup("my-subnet-group", "test subnet group", List.of("subnet-a", "subnet-b"), null))
|
||||
.thenReturn(group);
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
@@ -639,7 +712,7 @@ class RdsQueryHandlerTest {
|
||||
DbSubnetGroup group = new DbSubnetGroup();
|
||||
group.setDbSubnetGroupName("default");
|
||||
group.setDbSubnetGroupArn("arn:aws:rds:us-east-1:123456789012:subgrp:default");
|
||||
when(service.listDbSubnetGroups(null)).thenReturn(List.of(group));
|
||||
when(service.listDbSubnetGroups(null, null)).thenReturn(List.of(group));
|
||||
|
||||
Response response = handler.handle("DescribeDBSubnetGroups", params());
|
||||
|
||||
@@ -684,6 +757,19 @@ class RdsQueryHandlerTest {
|
||||
assertFalse(body.contains("<Marker>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeDbSubnetGroupsPassesSignedRegionToService() {
|
||||
DbSubnetGroup group = new DbSubnetGroup();
|
||||
group.setDbSubnetGroupName("default");
|
||||
group.setDbSubnetGroupArn("arn:aws:rds:us-west-2:123456789012:subgrp:default");
|
||||
when(service.listDbSubnetGroups(null, "us-west-2")).thenReturn(List.of(group));
|
||||
|
||||
Response response = handler.handle("DescribeDBSubnetGroups", params(), "us-west-2");
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
verify(service).listDbSubnetGroups(null, "us-west-2");
|
||||
}
|
||||
|
||||
// ──────────────────────────── Helpers ────────────────────────────
|
||||
|
||||
private static MultivaluedMap<String, String> params() {
|
||||
|
||||
@@ -101,6 +101,22 @@ class RdsServiceTest {
|
||||
assertEquals("arn:aws:rds:us-east-1:123456789012:db:mydb", instance.getDbInstanceArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAndModifyDbInstancePersistVpcSecurityGroups() {
|
||||
DbInstance instance = rdsService.createDbInstance("mydb", "postgres", "13",
|
||||
"admin", "password", "dbname", "db.t3.micro",
|
||||
20, false, null, null, null, null, false, false, null,
|
||||
Map.of(), List.of("sg-created"));
|
||||
|
||||
assertEquals(List.of("sg-created"), instance.getVpcSecurityGroupIds());
|
||||
|
||||
DbInstance modified = rdsService.modifyDbInstance("mydb", null, null, null,
|
||||
List.of("sg-updated-a", "sg-updated-b"));
|
||||
|
||||
assertEquals(List.of("sg-updated-a", "sg-updated-b"), modified.getVpcSecurityGroupIds());
|
||||
assertEquals(List.of("sg-updated-a", "sg-updated-b"), rdsService.getDbInstance("mydb").getVpcSecurityGroupIds());
|
||||
}
|
||||
|
||||
@Test
|
||||
void postgresImageUsesRequestedEngineVersionAndDefaultFlavor() {
|
||||
assertEquals("postgres:18.1-alpine",
|
||||
@@ -595,6 +611,21 @@ class RdsServiceTest {
|
||||
assertEquals("arn:aws:rds:us-east-1:123456789012:subgrp:my-subnet-group", group.getDbSubnetGroupArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbSubnetGroupUsesSuppliedRegionForSubnetLookup() {
|
||||
List<String> subnetIds = List.of("subnet-west-a", "subnet-west-b");
|
||||
when(ec2Service.describeSubnets(eq("us-west-2"), eq(subnetIds), eq(Map.of())))
|
||||
.thenReturn(List.of(
|
||||
subnet("subnet-west-a", "vpc-west", "us-west-2a"),
|
||||
subnet("subnet-west-b", "vpc-west", "us-west-2b")));
|
||||
|
||||
DbSubnetGroup group = rdsService.createDbSubnetGroup("west-subnets", "desc", subnetIds, "us-west-2");
|
||||
|
||||
assertEquals("vpc-west", group.getVpcId());
|
||||
assertEquals("arn:aws:rds:us-west-2:123456789012:subgrp:west-subnets", group.getDbSubnetGroupArn());
|
||||
verify(ec2Service).describeSubnets(eq("us-west-2"), eq(subnetIds), eq(Map.of()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbSubnetGroupRequiresSubnetIdsWithMissingParameter() {
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
@@ -654,6 +685,36 @@ class RdsServiceTest {
|
||||
assertEquals("arn:aws:rds:us-east-1:123456789012:subgrp:default", group.getDbSubnetGroupArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveDbSubnetGroupViewUsesSuppliedRegionForDefaultGroup() {
|
||||
when(ec2Service.describeSubnets(eq("us-west-2"), anyList(), any()))
|
||||
.thenReturn(List.of(
|
||||
subnet("subnet-west-a", "vpc-west", "us-west-2a"),
|
||||
subnet("subnet-west-b", "vpc-west", "us-west-2b")));
|
||||
|
||||
DbSubnetGroup group = rdsService.resolveDbSubnetGroupView(null, "us-west-2");
|
||||
|
||||
assertEquals("default", group.getDbSubnetGroupName());
|
||||
assertEquals("vpc-west", group.getVpcId());
|
||||
assertEquals("arn:aws:rds:us-west-2:123456789012:subgrp:default", group.getDbSubnetGroupArn());
|
||||
assertEquals(Map.of("subnet-west-a", "us-west-2a", "subnet-west-b", "us-west-2b"),
|
||||
group.getSubnetAvailabilityZones());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getDbSubnetGroupUsesSuppliedRegionForDefaultGroup() {
|
||||
when(ec2Service.describeSubnets(eq("us-west-2"), anyList(), any()))
|
||||
.thenReturn(List.of(
|
||||
subnet("subnet-west-a", "vpc-west", "us-west-2a"),
|
||||
subnet("subnet-west-b", "vpc-west", "us-west-2b")));
|
||||
|
||||
DbSubnetGroup group = rdsService.getDbSubnetGroup("default", "us-west-2");
|
||||
|
||||
assertEquals("default", group.getDbSubnetGroupName());
|
||||
assertEquals("vpc-west", group.getVpcId());
|
||||
assertEquals("arn:aws:rds:us-west-2:123456789012:subgrp:default", group.getDbSubnetGroupArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDbClusterParameterGroupAppliesParameters() {
|
||||
rdsService.createDbClusterParameterGroup("cpg1", "aurora-postgresql16", "desc");
|
||||
@@ -799,16 +860,16 @@ class RdsServiceTest {
|
||||
}
|
||||
|
||||
private static List<Subnet> defaultSubnets() {
|
||||
Subnet subnetA = new Subnet();
|
||||
subnetA.setSubnetId("subnet-default-a");
|
||||
subnetA.setVpcId("vpc-default");
|
||||
subnetA.setAvailabilityZone("us-east-1a");
|
||||
return List.of(
|
||||
subnet("subnet-default-a", "vpc-default", "us-east-1a"),
|
||||
subnet("subnet-default-b", "vpc-default", "us-east-1b"));
|
||||
}
|
||||
|
||||
Subnet subnetB = new Subnet();
|
||||
subnetB.setSubnetId("subnet-default-b");
|
||||
subnetB.setVpcId("vpc-default");
|
||||
subnetB.setAvailabilityZone("us-east-1b");
|
||||
|
||||
return List.of(subnetA, subnetB);
|
||||
private static Subnet subnet(String subnetId, String vpcId, String availabilityZone) {
|
||||
Subnet subnet = new Subnet();
|
||||
subnet.setSubnetId(subnetId);
|
||||
subnet.setVpcId(vpcId);
|
||||
subnet.setAvailabilityZone(availabilityZone);
|
||||
return subnet;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user