mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(rds): add option group CRUD (#2352)
Adds CreateOptionGroup, DescribeOptionGroups, ModifyOptionGroup and DeleteOptionGroup, mirroring the DB parameter group actions. DB instances now accept OptionGroupName and report OptionGroupMemberships, so a group still attached to an instance faults on delete. Fixes #2304 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
1 parent
1461a10de7
commit
3374bfeb04
10 files changed
+1865
-21
No files matched your search
@@ -12,11 +12,14 @@ import io.github.hectorvent.floci.services.rds.model.DbProxyAuth;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxyTarget;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxyTargetGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbSubnetGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.OptionGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.OptionGroupOption;
|
||||
import jakarta.ws.rs.core.MultivaluedHashMap;
|
||||
import jakarta.ws.rs.core.MultivaluedMap;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -207,7 +210,7 @@ class RdsQueryHandlerTest {
|
||||
when(service.listDbInstances(null, "us-west-2")).thenReturn(List.of());
|
||||
when(service.getDbInstance("mydb", "us-west-2")).thenReturn(instance);
|
||||
when(service.modifyDbInstance(
|
||||
eq("mydb"), isNull(), isNull(), isNull(), anyList(), eq("us-west-2")))
|
||||
eq("mydb"), isNull(), isNull(), isNull(), anyList(), isNull(), eq("us-west-2")))
|
||||
.thenReturn(instance);
|
||||
when(service.rebootDbInstance("mydb", "us-west-2")).thenReturn(instance);
|
||||
when(service.listDbClusters(null, "us-west-2")).thenReturn(List.of());
|
||||
@@ -232,7 +235,7 @@ class RdsQueryHandlerTest {
|
||||
verify(service).getDbInstance("mydb", "us-west-2");
|
||||
verify(service).deleteDbInstance("mydb", "us-west-2");
|
||||
verify(service).modifyDbInstance(
|
||||
eq("mydb"), isNull(), isNull(), isNull(), anyList(), eq("us-west-2"));
|
||||
eq("mydb"), isNull(), isNull(), isNull(), anyList(), isNull(), eq("us-west-2"));
|
||||
verify(service).rebootDbInstance("mydb", "us-west-2");
|
||||
verify(service).listDbClusters(null, "us-west-2");
|
||||
verify(service).getDbCluster("mycluster", "us-west-2");
|
||||
@@ -345,7 +348,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(List.of()), isNull()))
|
||||
eq(java.util.Map.of("example:ClusterId", "cluster-a", "Name", "mydb")), eq(List.of()), isNull(), isNull()))
|
||||
.thenReturn(instance);
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
@@ -359,7 +362,7 @@ 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"), List.of(), null);
|
||||
java.util.Map.of("example:ClusterId", "cluster-a", "Name", "mydb"), List.of(), null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -369,7 +372,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()), eq(List.of("sg-123", "sg-456")), isNull()))
|
||||
eq(java.util.Map.of()), eq(List.of("sg-123", "sg-456")), isNull(), isNull()))
|
||||
.thenReturn(instance);
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
@@ -384,7 +387,7 @@ class RdsQueryHandlerTest {
|
||||
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);
|
||||
java.util.Map.of(), List.of("sg-123", "sg-456"), null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -400,7 +403,7 @@ class RdsQueryHandlerTest {
|
||||
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());
|
||||
any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -414,7 +417,7 @@ class RdsQueryHandlerTest {
|
||||
assertEquals(400, response.getStatus());
|
||||
assertTrue(((String) response.getEntity()).contains("InvalidParameterValue"));
|
||||
verify(service, never()).modifyDbInstance(
|
||||
any(), any(), any(), any(), any(), any());
|
||||
any(), any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -500,7 +503,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(List.of()), isNull()))
|
||||
eq(null), eq(java.util.Map.of()), eq(List.of()), isNull(), isNull()))
|
||||
.thenReturn(instance);
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
@@ -514,7 +517,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(), List.of(), null);
|
||||
null, java.util.Map.of(), List.of(), null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -526,7 +529,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(List.of()), isNull()))
|
||||
eq("kms-key-1"), eq(java.util.Map.of()), eq(List.of()), isNull(), isNull()))
|
||||
.thenReturn(instance);
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
@@ -545,7 +548,7 @@ 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(), List.of(), null);
|
||||
"kms-key-1", java.util.Map.of(), List.of(), null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -558,7 +561,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("default"), eq(null), eq("ap-northeast-1a"), eq(true),
|
||||
eq(false), eq(null), eq(java.util.Map.of()), eq(List.of()), isNull()))
|
||||
eq(false), eq(null), eq(java.util.Map.of()), eq(List.of()), isNull(), isNull()))
|
||||
.thenReturn(instance);
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
@@ -586,7 +589,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(List.of()), isNull()))
|
||||
eq(false), eq(null), eq(java.util.Map.of()), eq(List.of()), isNull(), isNull()))
|
||||
.thenThrow(new AwsException("DBSubnetGroupNotFoundFault",
|
||||
"DB subnet group missing-subnet-group not found.", 404));
|
||||
|
||||
@@ -678,7 +681,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(List.of()), isNull()))
|
||||
eq(null), eq(java.util.Map.of()), eq(List.of()), isNull(), isNull()))
|
||||
.thenThrow(new AwsException("InvalidParameterValue",
|
||||
"Unsupported engine: oracle. Supported: postgres, mysql, mariadb.", 400));
|
||||
|
||||
@@ -1504,8 +1507,330 @@ class RdsQueryHandlerTest {
|
||||
assertFalse(body.contains("DBClusterNotFoundFault"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── Option groups ────────────────────────────
|
||||
|
||||
@Test
|
||||
void createOptionGroup_returnsOptionGroupShape() {
|
||||
when(service.createOptionGroup("og1", "mysql", "8.0", "my og", Map.of(), null))
|
||||
.thenReturn(makeOptionGroup("og1"));
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("OptionGroupName", "og1");
|
||||
p.add("EngineName", "mysql");
|
||||
p.add("MajorEngineVersion", "8.0");
|
||||
p.add("OptionGroupDescription", "my og");
|
||||
Response response = handler.handle("CreateOptionGroup", p);
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains("<CreateOptionGroupResult>"), body);
|
||||
assertTrue(body.contains("<OptionGroup>"), body);
|
||||
assertTrue(body.contains("<OptionGroupName>og1</OptionGroupName>"), body);
|
||||
assertTrue(body.contains("<EngineName>mysql</EngineName>"), body);
|
||||
assertTrue(body.contains("<MajorEngineVersion>8.0</MajorEngineVersion>"), body);
|
||||
assertTrue(body.contains("<OptionGroupDescription>my og</OptionGroupDescription>"), body);
|
||||
assertTrue(body.contains(
|
||||
"<OptionGroupArn>arn:aws:rds:us-east-1:123456789012:og:og1</OptionGroupArn>"), body);
|
||||
assertTrue(body.contains(
|
||||
"<AllowsVpcAndNonVpcInstanceMemberships>true</AllowsVpcAndNonVpcInstanceMemberships>"), body);
|
||||
assertTrue(body.contains("<Options></Options>"), body);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createOptionGroup_passesTags() {
|
||||
when(service.createOptionGroup(eq("og1"), eq("mysql"), eq("8.0"), eq("my og"),
|
||||
eq(Map.of("env", "dev")), isNull()))
|
||||
.thenReturn(makeOptionGroup("og1"));
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("OptionGroupName", "og1");
|
||||
p.add("EngineName", "mysql");
|
||||
p.add("MajorEngineVersion", "8.0");
|
||||
p.add("OptionGroupDescription", "my og");
|
||||
p.add("Tags.Tag.1.Key", "env");
|
||||
p.add("Tags.Tag.1.Value", "dev");
|
||||
Response response = handler.handle("CreateOptionGroup", p);
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
verify(service).createOptionGroup("og1", "mysql", "8.0", "my og", Map.of("env", "dev"), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createOptionGroup_requiresMandatoryParameters() {
|
||||
assertEquals(400, handler.handle("CreateOptionGroup", params()).getStatus());
|
||||
|
||||
MultivaluedMap<String, String> noEngine = params();
|
||||
noEngine.add("OptionGroupName", "og1");
|
||||
assertEquals(400, handler.handle("CreateOptionGroup", noEngine).getStatus());
|
||||
|
||||
MultivaluedMap<String, String> noVersion = params();
|
||||
noVersion.add("OptionGroupName", "og1");
|
||||
noVersion.add("EngineName", "mysql");
|
||||
assertEquals(400, handler.handle("CreateOptionGroup", noVersion).getStatus());
|
||||
|
||||
MultivaluedMap<String, String> noDescription = params();
|
||||
noDescription.add("OptionGroupName", "og1");
|
||||
noDescription.add("EngineName", "mysql");
|
||||
noDescription.add("MajorEngineVersion", "8.0");
|
||||
assertEquals(400, handler.handle("CreateOptionGroup", noDescription).getStatus());
|
||||
|
||||
verify(service, never()).createOptionGroup(any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeOptionGroups_usesOptionGroupsListWrapper() {
|
||||
when(service.listOptionGroups(null, null, null, null))
|
||||
.thenReturn(List.of(makeOptionGroup("og1")));
|
||||
|
||||
Response response = handler.handle("DescribeOptionGroups", params());
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains("<OptionGroupsList>"), body);
|
||||
assertTrue(body.contains("<OptionGroupsList><OptionGroup>"), body);
|
||||
assertTrue(body.contains("</OptionGroup></OptionGroupsList>"), body);
|
||||
assertTrue(body.contains("<Marker></Marker>"), body);
|
||||
assertFalse(body.contains("<member>"), body);
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeOptionGroups_passesFilters() {
|
||||
when(service.listOptionGroups("og1", "mysql", "8.0", null)).thenReturn(List.of());
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("OptionGroupName", "og1");
|
||||
p.add("EngineName", "mysql");
|
||||
p.add("MajorEngineVersion", "8.0");
|
||||
handler.handle("DescribeOptionGroups", p);
|
||||
|
||||
verify(service).listOptionGroups("og1", "mysql", "8.0", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeOptionGroups_propagatesNotFoundFault() {
|
||||
when(service.listOptionGroups("missing", null, null, null))
|
||||
.thenThrow(new AwsException("OptionGroupNotFoundFault",
|
||||
"Option group missing not found.", 404));
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("OptionGroupName", "missing");
|
||||
Response response = handler.handle("DescribeOptionGroups", p);
|
||||
|
||||
assertEquals(404, response.getStatus());
|
||||
assertTrue(((String) response.getEntity()).contains("OptionGroupNotFoundFault"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeOptionGroups_rendersOptionsWithSettingsAndSecurityGroups() {
|
||||
OptionGroup group = makeOptionGroup("og1");
|
||||
OptionGroupOption option = new OptionGroupOption("MEMCACHED");
|
||||
option.setOptionDescription("Innodb Memcached for MySQL");
|
||||
option.setPort(11211);
|
||||
option.setOptionSettings(new java.util.LinkedHashMap<>(
|
||||
Map.of("BACKLOG_QUEUE_LIMIT", "1024")));
|
||||
option.setVpcSecurityGroupMemberships(List.of("sg-123"));
|
||||
option.setDbSecurityGroupMemberships(List.of("default"));
|
||||
group.setOptions(new java.util.ArrayList<>(List.of(option)));
|
||||
when(service.listOptionGroups(null, null, null, null)).thenReturn(List.of(group));
|
||||
|
||||
Response response = handler.handle("DescribeOptionGroups", params());
|
||||
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains("<Options><Option>"), body);
|
||||
assertTrue(body.contains("<OptionName>MEMCACHED</OptionName>"), body);
|
||||
assertTrue(body.contains(
|
||||
"<OptionDescription>Innodb Memcached for MySQL</OptionDescription>"), body);
|
||||
assertTrue(body.contains("<Port>11211</Port>"), body);
|
||||
assertTrue(body.contains("<Persistent>false</Persistent>"), body);
|
||||
assertTrue(body.contains("<Permanent>false</Permanent>"), body);
|
||||
assertTrue(body.contains("<OptionSettings><OptionSetting>"
|
||||
+ "<Name>BACKLOG_QUEUE_LIMIT</Name><Value>1024</Value>"), body);
|
||||
assertTrue(body.contains("<VpcSecurityGroupMemberships><VpcSecurityGroupMembership>"
|
||||
+ "<VpcSecurityGroupId>sg-123</VpcSecurityGroupId>"
|
||||
+ "<Status>active</Status>"), body);
|
||||
assertTrue(body.contains("<DBSecurityGroupMemberships><DBSecurityGroup>"
|
||||
+ "<DBSecurityGroupName>default</DBSecurityGroupName>"
|
||||
+ "<Status>authorized</Status>"), body);
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyOptionGroup_parsesOptionConfigurations() {
|
||||
when(service.modifyOptionGroup(eq("og1"), anyList(), anyList(), isNull()))
|
||||
.thenReturn(makeOptionGroup("og1"));
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("OptionGroupName", "og1");
|
||||
p.add("ApplyImmediately", "true");
|
||||
p.add("OptionsToInclude.OptionConfiguration.1.OptionName", "MEMCACHED");
|
||||
p.add("OptionsToInclude.OptionConfiguration.1.Port", "11211");
|
||||
p.add("OptionsToInclude.OptionConfiguration.1.OptionVersion", "1.0");
|
||||
p.add("OptionsToInclude.OptionConfiguration.1.OptionSettings.OptionSetting.1.Name",
|
||||
"BACKLOG_QUEUE_LIMIT");
|
||||
p.add("OptionsToInclude.OptionConfiguration.1.OptionSettings.OptionSetting.1.Value", "1024");
|
||||
p.add("OptionsToInclude.OptionConfiguration.1.VpcSecurityGroupMemberships"
|
||||
+ ".VpcSecurityGroupId.1", "sg-123");
|
||||
p.add("OptionsToInclude.OptionConfiguration.1.DBSecurityGroupMemberships"
|
||||
+ ".DBSecurityGroupName.1", "default");
|
||||
Response response = handler.handle("ModifyOptionGroup", p);
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
assertTrue(((String) response.getEntity()).contains("<ModifyOptionGroupResult>"));
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<List<OptionGroupOption>> include = ArgumentCaptor.forClass(List.class);
|
||||
verify(service).modifyOptionGroup(eq("og1"), include.capture(), anyList(), isNull());
|
||||
assertEquals(1, include.getValue().size());
|
||||
OptionGroupOption parsed = include.getValue().getFirst();
|
||||
assertEquals("MEMCACHED", parsed.getOptionName());
|
||||
assertEquals(11211, parsed.getPort());
|
||||
assertEquals("1.0", parsed.getOptionVersion());
|
||||
assertEquals(Map.of("BACKLOG_QUEUE_LIMIT", "1024"), parsed.getOptionSettings());
|
||||
assertEquals(List.of("sg-123"), parsed.getVpcSecurityGroupMemberships());
|
||||
assertEquals(List.of("default"), parsed.getDbSecurityGroupMemberships());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyOptionGroup_acceptsLegacyMemberEncodingForOptionsToInclude() {
|
||||
when(service.modifyOptionGroup(eq("og1"), anyList(), anyList(), isNull()))
|
||||
.thenReturn(makeOptionGroup("og1"));
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("OptionGroupName", "og1");
|
||||
p.add("OptionsToInclude.member.1.OptionName", "MEMCACHED");
|
||||
handler.handle("ModifyOptionGroup", p);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<List<OptionGroupOption>> include = ArgumentCaptor.forClass(List.class);
|
||||
verify(service).modifyOptionGroup(eq("og1"), include.capture(), anyList(), isNull());
|
||||
assertEquals(1, include.getValue().size());
|
||||
assertEquals("MEMCACHED", include.getValue().getFirst().getOptionName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyOptionGroup_parsesOptionsToRemove() {
|
||||
when(service.modifyOptionGroup(eq("og1"), anyList(), anyList(), isNull()))
|
||||
.thenReturn(makeOptionGroup("og1"));
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("OptionGroupName", "og1");
|
||||
p.add("OptionsToRemove.member.1", "MEMCACHED");
|
||||
p.add("OptionsToRemove.member.2", "MARIADB_AUDIT_PLUGIN");
|
||||
handler.handle("ModifyOptionGroup", p);
|
||||
|
||||
verify(service).modifyOptionGroup(eq("og1"), anyList(),
|
||||
eq(List.of("MEMCACHED", "MARIADB_AUDIT_PLUGIN")), isNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyOptionGroup_rejectsNonNumericPort() {
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("OptionGroupName", "og1");
|
||||
p.add("OptionsToInclude.OptionConfiguration.1.OptionName", "MEMCACHED");
|
||||
p.add("OptionsToInclude.OptionConfiguration.1.Port", "not-a-number");
|
||||
Response response = handler.handle("ModifyOptionGroup", p);
|
||||
|
||||
assertEquals(400, response.getStatus());
|
||||
assertTrue(((String) response.getEntity()).contains("InvalidParameterValue"));
|
||||
verify(service, never()).modifyOptionGroup(any(), anyList(), anyList(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyOptionGroup_requiresOptionGroupName() {
|
||||
Response response = handler.handle("ModifyOptionGroup", params());
|
||||
|
||||
assertEquals(400, response.getStatus());
|
||||
verify(service, never()).modifyOptionGroup(any(), anyList(), anyList(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteOptionGroup_returnsResultlessEnvelope() {
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("OptionGroupName", "og1");
|
||||
Response response = handler.handle("DeleteOptionGroup", p);
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains("<DeleteOptionGroupResponse"), body);
|
||||
assertFalse(body.contains("<DeleteOptionGroupResult>"), body);
|
||||
verify(service).deleteOptionGroup("og1", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteOptionGroup_requiresOptionGroupName() {
|
||||
Response response = handler.handle("DeleteOptionGroup", params());
|
||||
|
||||
assertEquals(400, response.getStatus());
|
||||
verify(service, never()).deleteOptionGroup(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteOptionGroup_propagatesInvalidStateFault() {
|
||||
doThrow(new AwsException("InvalidOptionGroupStateFault",
|
||||
"The option group og1 is in use.", 400))
|
||||
.when(service).deleteOptionGroup("og1", null);
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("OptionGroupName", "og1");
|
||||
Response response = handler.handle("DeleteOptionGroup", p);
|
||||
|
||||
assertEquals(400, response.getStatus());
|
||||
assertTrue(((String) response.getEntity()).contains("InvalidOptionGroupStateFault"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeDbInstances_includesAttachedOptionGroupMembership() {
|
||||
DbInstance instance = makeInstance("mydb");
|
||||
instance.setOptionGroupName("og1");
|
||||
when(service.listDbInstances(null, null)).thenReturn(List.of(instance));
|
||||
|
||||
Response response = handler.handle("DescribeDBInstances", params());
|
||||
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains("<OptionGroupMemberships><OptionGroupMembership>"
|
||||
+ "<OptionGroupName>og1</OptionGroupName><Status>in-sync</Status>"), body);
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeDbInstances_reportsDefaultOptionGroupWhenUnattached() {
|
||||
DbInstance instance = makeInstance("mydb");
|
||||
instance.setEngineVersion("16.3");
|
||||
when(service.listDbInstances(null, null)).thenReturn(List.of(instance));
|
||||
|
||||
Response response = handler.handle("DescribeDBInstances", params());
|
||||
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains(
|
||||
"<OptionGroupName>default:postgres-16</OptionGroupName>"), body);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstance_passesOptionGroupName() {
|
||||
DbInstance instance = makeInstance("mydb");
|
||||
when(service.createDbInstance(any(), any(), any(), any(), any(), any(), any(),
|
||||
anyInt(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), anyBoolean(),
|
||||
any(), any(), anyList(), any(), any()))
|
||||
.thenReturn(instance);
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("DBInstanceIdentifier", "mydb");
|
||||
p.add("Engine", "mysql");
|
||||
p.add("OptionGroupName", "og1");
|
||||
Response response = handler.handle("CreateDBInstance", p);
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
verify(service).createDbInstance(eq("mydb"), eq("mysql"), any(), any(), any(), any(),
|
||||
any(), anyInt(), anyBoolean(), any(), any(), any(), any(), anyBoolean(),
|
||||
anyBoolean(), any(), any(), anyList(), eq("og1"), any());
|
||||
}
|
||||
|
||||
// ──────────────────────────── Helpers ────────────────────────────
|
||||
|
||||
private static OptionGroup makeOptionGroup(String name) {
|
||||
OptionGroup group = new OptionGroup(name, "mysql", "8.0", "my og");
|
||||
group.setOptionGroupArn("arn:aws:rds:us-east-1:123456789012:og:" + name);
|
||||
return group;
|
||||
}
|
||||
|
||||
private static MultivaluedMap<String, String> params() {
|
||||
return new MultivaluedHashMap<>();
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ import io.github.hectorvent.floci.services.rds.model.DbProxyAuth;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxyTarget;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxyTargetGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbSubnetGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.OptionGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.OptionGroupOption;
|
||||
import io.github.hectorvent.floci.services.rds.proxy.RdsAuthProxy;
|
||||
import io.github.hectorvent.floci.services.rds.proxy.RdsProxyManager;
|
||||
import io.github.hectorvent.floci.services.secretsmanager.SecretsManagerService;
|
||||
@@ -559,7 +561,7 @@ class RdsServiceTest {
|
||||
@Test
|
||||
void tagOperationsRejectUnsupportedResourceArn() {
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
rdsService.listTagsForResource("arn:aws:rds:us-east-1:123456789012:og:some-option-group"));
|
||||
rdsService.listTagsForResource("arn:aws:rds:us-east-1:123456789012:pg:some-parameter-group"));
|
||||
|
||||
assertEquals("InvalidParameterValue", exception.getErrorCode());
|
||||
// The type is valid on real AWS; the message must present this as a Floci limitation.
|
||||
@@ -3726,6 +3728,479 @@ class RdsServiceTest {
|
||||
assertTrue(rawTargetGroups.get(targetAccount + "/app-proxy").isEmpty());
|
||||
}
|
||||
|
||||
// ── Option Groups ─────────────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
void createOptionGroupReturnsArnAndNoOptions() {
|
||||
OptionGroup group = rdsService.createOptionGroup(
|
||||
"og1", "mysql", "8.0", "my option group");
|
||||
|
||||
assertEquals("og1", group.getOptionGroupName());
|
||||
assertEquals("mysql", group.getEngineName());
|
||||
assertEquals("8.0", group.getMajorEngineVersion());
|
||||
assertEquals("my option group", group.getOptionGroupDescription());
|
||||
assertEquals("arn:aws:rds:us-east-1:123456789012:og:og1", group.getOptionGroupArn());
|
||||
assertTrue(group.isAllowsVpcAndNonVpcInstanceMemberships());
|
||||
assertTrue(group.getOptions().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createOptionGroupRejectsDuplicateName() {
|
||||
rdsService.createOptionGroup("og1", "mysql", "8.0", "first");
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> rdsService.createOptionGroup("og1", "mysql", "8.0", "second"));
|
||||
|
||||
assertEquals("OptionGroupAlreadyExistsFault", exception.getErrorCode());
|
||||
assertEquals(400, exception.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createOptionGroupCannotShadowAManagedDefaultName() {
|
||||
// A default group's name contains ':', which the AWS name constraint forbids, so the
|
||||
// name check rejects it before the already-exists check can ever be reached.
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> rdsService.createOptionGroup(
|
||||
"default:mysql-8-0", "mysql", "8.0", "shadowing a default"));
|
||||
|
||||
assertEquals("InvalidParameterValue", exception.getErrorCode());
|
||||
assertEquals("mysql", rdsService.getOptionGroup("default:mysql-8-0").getEngineName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createOptionGroupRejectsUnknownEngine() {
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> rdsService.createOptionGroup("og1", "cassandra", "5.0", "nope"));
|
||||
|
||||
assertEquals("InvalidParameterValue", exception.getErrorCode());
|
||||
assertEquals(400, exception.getHttpStatus());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"1og", // must start with a letter
|
||||
"-og", // must start with a letter
|
||||
"og-", // can't end with a hyphen
|
||||
"og--1", // can't contain two consecutive hyphens
|
||||
"og_1", // only letters, numbers and hyphens
|
||||
"og name" // only letters, numbers and hyphens
|
||||
})
|
||||
void createOptionGroupRejectsNamesThatViolateAwsConstraints(String name) {
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> rdsService.createOptionGroup(name, "mysql", "8.0", "bad name"));
|
||||
|
||||
assertEquals("InvalidParameterValue", exception.getErrorCode());
|
||||
assertEquals(400, exception.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createOptionGroupRejectsNameLongerThan255Characters() {
|
||||
String name = "o" + "g".repeat(255);
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> rdsService.createOptionGroup(name, "mysql", "8.0", "too long"));
|
||||
|
||||
assertEquals("InvalidParameterValue", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createOptionGroupAcceptsHyphenatedAlphanumericName() {
|
||||
OptionGroup group = rdsService.createOptionGroup(
|
||||
"my-og-1", "mysql", "8.0", "valid name");
|
||||
|
||||
assertEquals("my-og-1", group.getOptionGroupName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getOptionGroupThrowsOptionGroupNotFoundFaultForUnknownName() {
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> rdsService.getOptionGroup("missing"));
|
||||
|
||||
assertEquals("OptionGroupNotFoundFault", exception.getErrorCode());
|
||||
assertEquals(404, exception.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listOptionGroupsAlwaysIncludesManagedDefaults() {
|
||||
List<String> names = rdsService.listOptionGroups(null, null, null).stream()
|
||||
.map(OptionGroup::getOptionGroupName)
|
||||
.toList();
|
||||
|
||||
assertTrue(names.contains("default:mysql-8-0"), names.toString());
|
||||
assertTrue(names.contains("default:postgres-16"), names.toString());
|
||||
assertTrue(names.contains("default:mariadb-11-4"), names.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listOptionGroupsIncludesCreatedGroupsAlongsideDefaults() {
|
||||
rdsService.createOptionGroup("og1", "mysql", "8.0", "mine");
|
||||
|
||||
List<String> names = rdsService.listOptionGroups(null, null, null).stream()
|
||||
.map(OptionGroup::getOptionGroupName)
|
||||
.toList();
|
||||
|
||||
assertTrue(names.contains("og1"), names.toString());
|
||||
assertTrue(names.contains("default:mysql-8-0"), names.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listOptionGroupsFiltersByEngineName() {
|
||||
rdsService.createOptionGroup("og-oracle", "oracle-ee", "19", "oracle");
|
||||
|
||||
Collection<OptionGroup> groups = rdsService.listOptionGroups(null, "oracle-ee", null);
|
||||
|
||||
assertFalse(groups.isEmpty());
|
||||
assertTrue(groups.stream().allMatch(group -> "oracle-ee".equals(group.getEngineName())));
|
||||
assertTrue(groups.stream()
|
||||
.anyMatch(group -> "og-oracle".equals(group.getOptionGroupName())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listOptionGroupsFiltersByMajorEngineVersion() {
|
||||
Collection<OptionGroup> groups = rdsService.listOptionGroups(null, "mysql", "8.4");
|
||||
|
||||
assertEquals(1, groups.size());
|
||||
assertEquals("default:mysql-8-4", groups.iterator().next().getOptionGroupName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listOptionGroupsRejectsMajorEngineVersionWithoutEngineName() {
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> rdsService.listOptionGroups(null, null, "8.0"));
|
||||
|
||||
assertEquals("InvalidParameterCombination", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listOptionGroupsByUnknownNameThrowsInsteadOfReturningEmptyList() {
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> rdsService.listOptionGroups("missing", null, null));
|
||||
|
||||
assertEquals("OptionGroupNotFoundFault", exception.getErrorCode());
|
||||
assertEquals(404, exception.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listOptionGroupsByNameResolvesManagedDefault() {
|
||||
Collection<OptionGroup> groups =
|
||||
rdsService.listOptionGroups("default:postgres-16", null, null);
|
||||
|
||||
assertEquals(1, groups.size());
|
||||
OptionGroup group = groups.iterator().next();
|
||||
assertEquals("postgres", group.getEngineName());
|
||||
assertEquals("16", group.getMajorEngineVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyOptionGroupAddsOptions() {
|
||||
rdsService.createOptionGroup("og1", "mariadb", "11.4", "mine");
|
||||
OptionGroupOption option = new OptionGroupOption("MARIADB_AUDIT_PLUGIN");
|
||||
option.setPort(11211);
|
||||
option.setOptionSettings(new java.util.LinkedHashMap<>(
|
||||
Map.of("SERVER_AUDIT_EVENTS", "CONNECT")));
|
||||
option.setVpcSecurityGroupMemberships(List.of("sg-123"));
|
||||
|
||||
OptionGroup group = rdsService.modifyOptionGroup("og1", List.of(option), List.of());
|
||||
|
||||
assertEquals(1, group.getOptions().size());
|
||||
OptionGroupOption stored = group.getOptions().getFirst();
|
||||
assertEquals("MARIADB_AUDIT_PLUGIN", stored.getOptionName());
|
||||
assertEquals(11211, stored.getPort());
|
||||
assertEquals("CONNECT", stored.getOptionSettings().get("SERVER_AUDIT_EVENTS"));
|
||||
assertEquals(List.of("sg-123"), stored.getVpcSecurityGroupMemberships());
|
||||
assertEquals(1, rdsService.getOptionGroup("og1").getOptions().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyOptionGroupUpdatesAnExistingOptionInPlace() {
|
||||
rdsService.createOptionGroup("og1", "mariadb", "11.4", "mine");
|
||||
OptionGroupOption first = new OptionGroupOption("MARIADB_AUDIT_PLUGIN");
|
||||
first.setOptionSettings(new java.util.LinkedHashMap<>(
|
||||
Map.of("SERVER_AUDIT_EVENTS", "CONNECT")));
|
||||
rdsService.modifyOptionGroup("og1", List.of(first), List.of());
|
||||
|
||||
OptionGroupOption update = new OptionGroupOption("MARIADB_AUDIT_PLUGIN");
|
||||
update.setOptionSettings(new java.util.LinkedHashMap<>(
|
||||
Map.of("SERVER_AUDIT_EVENTS", "CONNECT,QUERY")));
|
||||
OptionGroup group = rdsService.modifyOptionGroup("og1", List.of(update), List.of());
|
||||
|
||||
assertEquals(1, group.getOptions().size());
|
||||
assertEquals("CONNECT,QUERY",
|
||||
group.getOptions().getFirst().getOptionSettings().get("SERVER_AUDIT_EVENTS"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyOptionGroupRemovesOptions() {
|
||||
rdsService.createOptionGroup("og1", "mysql", "8.0", "mine");
|
||||
rdsService.modifyOptionGroup(
|
||||
"og1", List.of(new OptionGroupOption("MEMCACHED")), List.of());
|
||||
|
||||
OptionGroup group = rdsService.modifyOptionGroup("og1", List.of(), List.of("MEMCACHED"));
|
||||
|
||||
assertTrue(group.getOptions().isEmpty());
|
||||
assertTrue(rdsService.getOptionGroup("og1").getOptions().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyOptionGroupThrowsForUnknownGroup() {
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> rdsService.modifyOptionGroup("missing", List.of(), List.of()));
|
||||
|
||||
assertEquals("OptionGroupNotFoundFault", exception.getErrorCode());
|
||||
assertEquals(404, exception.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyOptionGroupRejectsManagedDefault() {
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> rdsService.modifyOptionGroup("default:mysql-8-0",
|
||||
List.of(new OptionGroupOption("MEMCACHED")), List.of()));
|
||||
|
||||
assertEquals("InvalidOptionGroupStateFault", exception.getErrorCode());
|
||||
assertEquals(400, exception.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteOptionGroupRemovesTheGroup() {
|
||||
rdsService.createOptionGroup("og1", "mysql", "8.0", "mine");
|
||||
|
||||
rdsService.deleteOptionGroup("og1");
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> rdsService.getOptionGroup("og1"));
|
||||
assertEquals("OptionGroupNotFoundFault", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteOptionGroupThrowsForUnknownGroup() {
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> rdsService.deleteOptionGroup("missing"));
|
||||
|
||||
assertEquals("OptionGroupNotFoundFault", exception.getErrorCode());
|
||||
assertEquals(404, exception.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteOptionGroupRejectsManagedDefault() {
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> rdsService.deleteOptionGroup("default:mysql-8-0"));
|
||||
|
||||
assertEquals("InvalidOptionGroupStateFault", exception.getErrorCode());
|
||||
assertEquals(400, exception.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteOptionGroupRejectsGroupStillAttachedToAnInstance() {
|
||||
rdsService.createOptionGroup("og1", "mysql", "8.0", "mine");
|
||||
createInstanceWithOptionGroup("mydb", "mysql", "8.0", "og1");
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> rdsService.deleteOptionGroup("og1"));
|
||||
|
||||
assertEquals("InvalidOptionGroupStateFault", exception.getErrorCode());
|
||||
assertEquals(400, exception.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void optionGroupsAreScopedByRegion() {
|
||||
rdsService.createOptionGroup("og1", "mysql", "8.0", "mine", Map.of(), "us-east-1");
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> rdsService.getOptionGroup("og1", "eu-west-1"));
|
||||
|
||||
assertEquals("OptionGroupNotFoundFault", exception.getErrorCode());
|
||||
assertEquals("arn:aws:rds:us-east-1:123456789012:og:og1",
|
||||
rdsService.getOptionGroup("og1", "us-east-1").getOptionGroupArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstanceStoresAttachedOptionGroup() {
|
||||
rdsService.createOptionGroup("og1", "mysql", "8.0", "mine");
|
||||
|
||||
DbInstance instance = createInstanceWithOptionGroup("mydb", "mysql", "8.0", "og1");
|
||||
|
||||
assertEquals("og1", instance.getOptionGroupName());
|
||||
assertEquals("og1", rdsService.getDbInstance("mydb").getOptionGroupName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstanceRejectsUnknownOptionGroup() {
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> createInstanceWithOptionGroup("mydb", "mysql", "8.0", "missing"));
|
||||
|
||||
assertEquals("OptionGroupNotFoundFault", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstanceRejectsOptionGroupForAnotherEngine() {
|
||||
rdsService.createOptionGroup("og1", "mysql", "8.0", "mine");
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> createInstanceWithOptionGroup("mydb", "postgres", "16.3", "og1"));
|
||||
|
||||
assertEquals("InvalidParameterCombination", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstanceRejectsOptionGroupForAnotherMajorEngineVersion() {
|
||||
rdsService.createOptionGroup("og1", "mysql", "8.0", "mine");
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> createInstanceWithOptionGroup("mydb", "mysql", "8.4.3", "og1"));
|
||||
|
||||
assertEquals("InvalidParameterCombination", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstanceRejectsPostgresOptionGroupForAnotherMajorEngineVersion() {
|
||||
rdsService.createOptionGroup("og1", "postgres", "13", "mine");
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> createInstanceWithOptionGroup("mydb", "postgres", "16.3", "og1"));
|
||||
|
||||
assertEquals("InvalidParameterCombination", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstanceAcceptsOptionGroupMatchingTheInstanceMajorEngineVersion() {
|
||||
rdsService.createOptionGroup("og1", "mysql", "8.0", "mine");
|
||||
|
||||
DbInstance instance = createInstanceWithOptionGroup("mydb", "mysql", "8.0.36", "og1");
|
||||
|
||||
assertEquals("og1", instance.getOptionGroupName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstanceAcceptsPostgresOptionGroupRegardlessOfTheMinorVersion() {
|
||||
rdsService.createOptionGroup("og1", "postgres", "16", "mine");
|
||||
|
||||
DbInstance instance = createInstanceWithOptionGroup("mydb", "postgres", "16.3", "og1");
|
||||
|
||||
assertEquals("og1", instance.getOptionGroupName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstanceAcceptsManagedDefaultOptionGroup() {
|
||||
DbInstance instance =
|
||||
createInstanceWithOptionGroup("mydb", "mysql", "8.0", "default:mysql-8-0");
|
||||
|
||||
assertEquals("default:mysql-8-0", instance.getOptionGroupName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void optionGroupIsTaggableByArn() {
|
||||
OptionGroup group = rdsService.createOptionGroup("og1", "mysql", "8.0", "mine");
|
||||
|
||||
rdsService.addTagsToResource(group.getOptionGroupArn(), Map.of("env", "dev"));
|
||||
|
||||
assertEquals(Map.of("env", "dev"),
|
||||
rdsService.listTagsForResource(group.getOptionGroupArn()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultOptionGroupCannotBeTagged() {
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
rdsService.addTagsToResource(
|
||||
"arn:aws:rds:us-east-1:123456789012:og:default:mysql-8-0",
|
||||
Map.of("env", "dev")));
|
||||
|
||||
assertEquals("InvalidOptionGroupStateFault", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDbInstanceAttachesOptionGroup() {
|
||||
rdsService.createOptionGroup("og1", "mysql", "8.0", "mine");
|
||||
createInstanceWithOptionGroup("mydb", "mysql", "8.0", null);
|
||||
|
||||
DbInstance modified = rdsService.modifyDbInstance(
|
||||
"mydb", null, null, null, List.of(), "og1", "us-east-1");
|
||||
|
||||
assertEquals("og1", modified.getOptionGroupName());
|
||||
assertEquals("og1", rdsService.getDbInstance("mydb").getOptionGroupName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDbInstanceRejectsOptionGroupForAnotherEngine() {
|
||||
rdsService.createOptionGroup("og1", "postgres", "16", "mine");
|
||||
createInstanceWithOptionGroup("mydb", "mysql", "8.0", null);
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
rdsService.modifyDbInstance(
|
||||
"mydb", null, null, null, List.of(), "og1", "us-east-1"));
|
||||
|
||||
assertEquals("InvalidParameterCombination", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDbInstanceRejectsOptionGroupForAnotherMajorEngineVersion() {
|
||||
rdsService.createOptionGroup("og1", "mysql", "8.4", "mine");
|
||||
createInstanceWithOptionGroup("mydb", "mysql", "8.0.36", null);
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
rdsService.modifyDbInstance(
|
||||
"mydb", null, null, null, List.of(), "og1", "us-east-1"));
|
||||
|
||||
assertEquals("InvalidParameterCombination", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDbInstanceAcceptsOptionGroupMatchingTheInstanceMajorEngineVersion() {
|
||||
rdsService.createOptionGroup("og1", "mysql", "8.0", "mine");
|
||||
createInstanceWithOptionGroup("mydb", "mysql", "8.0.36", null);
|
||||
|
||||
DbInstance modified = rdsService.modifyDbInstance(
|
||||
"mydb", null, null, null, List.of(), "og1", "us-east-1");
|
||||
|
||||
assertEquals("og1", modified.getOptionGroupName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void optionGroupsUseTheInjectedAccountAwareStorage() {
|
||||
String accountId = "123456789012";
|
||||
InMemoryStorage<String, OptionGroup> rawOptionGroups = new InMemoryStorage<>();
|
||||
RdsService service = optionGroupStoreService(regionResolver,
|
||||
new AccountAwareStorageBackend<>(rawOptionGroups, null, accountId));
|
||||
|
||||
service.createOptionGroup("og1", "mysql", "8.0", "mine", Map.of(), "us-east-1");
|
||||
|
||||
assertTrue(rawOptionGroups.get(accountId + "/us-east-1::og1").isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void sameNamedOptionGroupsInDifferentAccountsAreIsolated() {
|
||||
String accountA = "111111111111";
|
||||
String accountB = "222222222222";
|
||||
InMemoryStorage<String, OptionGroup> rawOptionGroups = new InMemoryStorage<>();
|
||||
RdsService serviceA = optionGroupStoreService(
|
||||
new RegionResolver("us-east-1", accountA),
|
||||
new AccountAwareStorageBackend<>(rawOptionGroups, null, accountA));
|
||||
RdsService serviceB = optionGroupStoreService(
|
||||
new RegionResolver("us-east-1", accountB),
|
||||
new AccountAwareStorageBackend<>(rawOptionGroups, null, accountB));
|
||||
|
||||
serviceA.createOptionGroup("og1", "mysql", "8.0", "account a", Map.of(), "us-east-1");
|
||||
serviceB.createOptionGroup("og1", "postgres", "16", "account b", Map.of(), "us-east-1");
|
||||
serviceA.deleteOptionGroup("og1", "us-east-1");
|
||||
|
||||
assertThrows(AwsException.class, () -> serviceA.getOptionGroup("og1", "us-east-1"));
|
||||
assertEquals("postgres", serviceB.getOptionGroup("og1", "us-east-1").getEngineName());
|
||||
}
|
||||
|
||||
private RdsService optionGroupStoreService(
|
||||
RegionResolver resolver, StorageBackend<String, OptionGroup> optionGroups) {
|
||||
return new RdsService(containerManager, proxyManager, ec2Service, resolver, config,
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), null, null, null,
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), optionGroups);
|
||||
}
|
||||
|
||||
private DbInstance createInstanceWithOptionGroup(
|
||||
String id, String engine, String engineVersion, String optionGroupName) {
|
||||
return rdsService.createDbInstance(id, engine, engineVersion, "admin", "password",
|
||||
"dbname", "db.t3.micro", 20, false, null, null, null, null, false, false,
|
||||
null, Map.of(), List.of(), optionGroupName, null);
|
||||
}
|
||||
|
||||
private RdsService newService(RdsContainerManager containerManager,
|
||||
RdsProxyManager proxyManager,
|
||||
StorageBackend<String, DbInstance> instances,
|
||||
|
||||
Reference in new issue
Block a user