mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(rds): DB proxy endpoints (#6062)
* feat(rds): DB proxy endpoints CreateDBProxyEndpoint, DescribeDBProxyEndpoints, ModifyDBProxyEndpoint and DeleteDBProxyEndpoint store endpoints per account and Region, checked against the service model. Each endpoint reports its proxy's own host, so a client connects through it as through the proxy. DescribeDBProxyEndpoints lists each proxy's default endpoint first; it cannot be modified or deleted. Deleting a proxy deletes its endpoints, and endpoint ARNs take tags. Closes #5805 * fix(rds): report each proxy endpoint at the proxy's current host A custom endpoint kept the proxy's host from when it was created, so after a restore gave the proxy a new host, every custom endpoint still reported the old one while default reported the new one. The host is no longer stored with the endpoint: create, describe, modify and delete take it from the proxy when they answer. A missing DBProxyName, DBProxyEndpointName or VpcSubnetIds is now MissingParameter, checked before the proxy is looked up. * test(rds): import Executable and assertTrue instead of naming them inline
This commit is contained in:
1 parent
1dce18e766
commit
1108bc75dc
9 files changed
+1021
-2
No files matched your search
+217
@@ -0,0 +1,217 @@
|
||||
package io.github.hectorvent.floci.services.rds;
|
||||
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static io.restassured.http.ContentType.URLENC;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* DB proxy endpoints over the Query protocol: create, describe after the proxy's default endpoint,
|
||||
* tag, rename, delete, and removal with their proxy. Runs in its own Region so the endpoint names
|
||||
* it uses are its own.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class RdsProxyEndpointIntegrationTest {
|
||||
|
||||
private static final String REGION = "eu-west-3";
|
||||
private static final String PROXY = "pep-proxy";
|
||||
private static final String MEMBERS =
|
||||
"DescribeDBProxyEndpointsResponse.DescribeDBProxyEndpointsResult.DBProxyEndpoints.member";
|
||||
private static final String AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20261019/" + REGION + "/rds/aws4_request, "
|
||||
+ "SignedHeaders=content-type;host, Signature=test";
|
||||
|
||||
private static String endpointArn;
|
||||
|
||||
private static RequestSpecification query(String action) {
|
||||
return given().header("Authorization", AUTH)
|
||||
.contentType(URLENC)
|
||||
.formParam("Action", action)
|
||||
.formParam("Version", "2014-10-31");
|
||||
}
|
||||
|
||||
private static RequestSpecification withSubnets(RequestSpecification request) {
|
||||
return request.formParam("VpcSubnetIds.member.1", Ec2Service.defaultSubnetId(REGION, "a"))
|
||||
.formParam("VpcSubnetIds.member.2", Ec2Service.defaultSubnetId(REGION, "b"));
|
||||
}
|
||||
|
||||
private static RequestSpecification describe() {
|
||||
return query("DescribeDBProxyEndpoints").formParam("DBProxyName", PROXY);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void anEndpointIsAddedToAProxy() {
|
||||
withSubnets(query("CreateDBProxy"))
|
||||
.formParam("DBProxyName", PROXY)
|
||||
.formParam("EngineFamily", "POSTGRESQL")
|
||||
.formParam("RoleArn", "arn:aws:iam::000000000000:role/proxy")
|
||||
.formParam("VpcSecurityGroupIds.member.1", "sg-proxy")
|
||||
.formParam("Auth.member.1.AuthScheme", "SECRETS")
|
||||
.formParam("Auth.member.1.SecretArn",
|
||||
"arn:aws:secretsmanager:" + REGION + ":000000000000:secret:db-AbCdEf")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
endpointArn = withSubnets(query("CreateDBProxyEndpoint"))
|
||||
.formParam("DBProxyName", PROXY)
|
||||
.formParam("DBProxyEndpointName", "reader")
|
||||
.formParam("TargetRole", "READ_ONLY")
|
||||
.formParam("VpcSecurityGroupIds.member.1", "sg-endpoint")
|
||||
.formParam("Tags.Tag.1.Key", "team")
|
||||
.formParam("Tags.Tag.1.Value", "data")
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<CreateDBProxyEndpointResult><DBProxyEndpoint>"))
|
||||
.body("CreateDBProxyEndpointResponse.CreateDBProxyEndpointResult.DBProxyEndpoint.DBProxyEndpointName",
|
||||
equalTo("reader"))
|
||||
.body(containsString("<DBProxyName>" + PROXY + "</DBProxyName>"))
|
||||
.body(containsString("<Status>available</Status>"))
|
||||
.body(containsString("<TargetRole>READ_ONLY</TargetRole>"))
|
||||
.body(containsString("<IsDefault>false</IsDefault>"))
|
||||
.body(containsString("<EndpointNetworkType>IPV4</EndpointNetworkType>"))
|
||||
.body(containsString("<VpcSecurityGroupIds><member>sg-endpoint</member></VpcSecurityGroupIds>"))
|
||||
.body(containsString("<CreatedDate>"))
|
||||
.extract().path("CreateDBProxyEndpointResponse.CreateDBProxyEndpointResult.DBProxyEndpoint"
|
||||
+ ".DBProxyEndpointArn");
|
||||
assertTrue(
|
||||
endpointArn.startsWith("arn:aws:rds:" + REGION + ":000000000000:db-proxy-endpoint:prx-endpoint-"),
|
||||
endpointArn);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void theProxysDefaultEndpointIsListedFirst() {
|
||||
String proxyHost = query("DescribeDBProxies").formParam("DBProxyName", PROXY)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().path("DescribeDBProxiesResponse.DescribeDBProxiesResult.DBProxies.member.Endpoint");
|
||||
|
||||
describe().when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(MEMBERS + ".size()", equalTo(2))
|
||||
.body(MEMBERS + "[0].DBProxyEndpointName", equalTo("default"))
|
||||
.body(MEMBERS + "[0].IsDefault", equalTo("true"))
|
||||
.body(MEMBERS + "[0].TargetRole", equalTo("READ_WRITE"))
|
||||
// Only the added endpoint has an ARN.
|
||||
.body(MEMBERS + ".DBProxyEndpointArn.size()", equalTo(1))
|
||||
.body(MEMBERS + "[1].DBProxyEndpointArn", equalTo(endpointArn))
|
||||
.body(MEMBERS + "[0].Endpoint", equalTo(proxyHost))
|
||||
.body(MEMBERS + "[1].DBProxyEndpointName", equalTo("reader"))
|
||||
.body(MEMBERS + "[1].Endpoint", equalTo(proxyHost))
|
||||
.body(not(containsString("<Marker>")));
|
||||
|
||||
query("DescribeDBProxyEndpoints").formParam("DBProxyEndpointName", "absent")
|
||||
.when().post("/").then().statusCode(404)
|
||||
.body(containsString("<Code>DBProxyEndpointNotFoundFault</Code>"));
|
||||
query("DescribeDBProxyEndpoints").formParam("DBProxyName", "absent-proxy")
|
||||
.when().post("/").then().statusCode(404)
|
||||
.body(containsString("<Code>DBProxyNotFoundFault</Code>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void anEndpointIsTaggedByItsArn() {
|
||||
query("ListTagsForResource").formParam("ResourceName", endpointArn)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<Key>team</Key><Value>data</Value>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void requestsOutsideTheModelAreRefused() {
|
||||
withSubnets(query("CreateDBProxyEndpoint"))
|
||||
.formParam("DBProxyName", PROXY).formParam("DBProxyEndpointName", "reader")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>DBProxyEndpointAlreadyExistsFault</Code>"));
|
||||
withSubnets(query("CreateDBProxyEndpoint"))
|
||||
.formParam("DBProxyName", PROXY).formParam("DBProxyEndpointName", "bad--name")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"));
|
||||
withSubnets(query("CreateDBProxyEndpoint"))
|
||||
.formParam("DBProxyName", PROXY).formParam("DBProxyEndpointName", "writer")
|
||||
.formParam("TargetRole", "WRITER")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"));
|
||||
query("CreateDBProxyEndpoint")
|
||||
.formParam("DBProxyName", PROXY).formParam("DBProxyEndpointName", "lonely")
|
||||
.formParam("VpcSubnetIds.member.1", Ec2Service.defaultSubnetId(REGION, "a"))
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidSubnet</Code>"));
|
||||
withSubnets(query("CreateDBProxyEndpoint")).formParam("DBProxyEndpointName", "orphan")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>MissingParameter</Code>"))
|
||||
.body(containsString("The request must contain the parameter DBProxyName."));
|
||||
withSubnets(query("CreateDBProxyEndpoint")).formParam("DBProxyName", PROXY)
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("The request must contain the parameter DBProxyEndpointName."));
|
||||
query("CreateDBProxyEndpoint")
|
||||
.formParam("DBProxyName", PROXY).formParam("DBProxyEndpointName", "nowhere")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("The request must contain the parameter VpcSubnetIds."));
|
||||
query("DeleteDBProxyEndpoint")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>MissingParameter</Code>"));
|
||||
query("ModifyDBProxyEndpoint").formParam("DBProxyEndpointName", "default")
|
||||
.formParam("NewDBProxyEndpointName", "renamed")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidDBProxyEndpointStateFault</Code>"));
|
||||
query("DeleteDBProxyEndpoint").formParam("DBProxyEndpointName", "default")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidDBProxyEndpointStateFault</Code>"));
|
||||
describe().formParam("MaxRecords", "19")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void anEndpointIsRenamedAndDeleted() {
|
||||
query("ModifyDBProxyEndpoint")
|
||||
.formParam("DBProxyEndpointName", "reader")
|
||||
.formParam("NewDBProxyEndpointName", "analytics")
|
||||
.formParam("VpcSecurityGroupIds.member.1", "sg-other")
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<ModifyDBProxyEndpointResult><DBProxyEndpoint>"))
|
||||
.body(containsString("<DBProxyEndpointName>analytics</DBProxyEndpointName>"))
|
||||
.body(containsString("<DBProxyEndpointArn>" + endpointArn + "</DBProxyEndpointArn>"))
|
||||
.body(containsString("<VpcSecurityGroupIds><member>sg-other</member></VpcSecurityGroupIds>"));
|
||||
|
||||
query("DeleteDBProxyEndpoint").formParam("DBProxyEndpointName", "analytics")
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<DeleteDBProxyEndpointResult><DBProxyEndpoint>"))
|
||||
.body(containsString("<Status>deleting</Status>"));
|
||||
query("DeleteDBProxyEndpoint").formParam("DBProxyEndpointName", "analytics")
|
||||
.when().post("/").then().statusCode(404)
|
||||
.body(containsString("<Code>DBProxyEndpointNotFoundFault</Code>"));
|
||||
describe().when().post("/").then().statusCode(200)
|
||||
.body(MEMBERS + ".DBProxyEndpointName", equalTo("default"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void deletingTheProxyDeletesItsEndpoints() {
|
||||
withSubnets(query("CreateDBProxyEndpoint"))
|
||||
.formParam("DBProxyName", PROXY).formParam("DBProxyEndpointName", "leftover")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
query("DeleteDBProxy").formParam("DBProxyName", PROXY).when().post("/").then().statusCode(200);
|
||||
|
||||
query("DeleteDBProxyEndpoint").formParam("DBProxyEndpointName", "leftover")
|
||||
.when().post("/").then().statusCode(404)
|
||||
.body(containsString("<Code>DBProxyEndpointNotFoundFault</Code>"));
|
||||
query("DescribeDBProxyEndpoints").when().post("/").then().statusCode(200)
|
||||
.body(not(containsString("<member>")));
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.github.hectorvent.floci.services.ec2.model.SecurityGroup;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Subnet;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Vpc;
|
||||
import io.github.hectorvent.floci.services.ec2.model.VpcIpv6CidrBlockAssociation;
|
||||
@@ -35,6 +36,7 @@ import io.github.hectorvent.floci.services.rds.model.DbInstanceStatus;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbParameterGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxy;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxyAuth;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxyEndpoint;
|
||||
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.DbSnapshot;
|
||||
@@ -56,6 +58,7 @@ import io.github.hectorvent.floci.services.secretsmanager.model.Secret;
|
||||
import io.github.hectorvent.floci.testutil.LogCapture;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
@@ -67,6 +70,7 @@ import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -10343,4 +10347,291 @@ class RdsServiceTest {
|
||||
rdsService.deleteDbInstance("writer");
|
||||
assertEquals("reader", rdsService.getDbCluster("aurora").resolveWriterIdentifier());
|
||||
}
|
||||
|
||||
// ── DB proxy endpoints ────────────────────────────────────────────────────
|
||||
|
||||
private DbProxy proxyForEndpoints(String name, String engineFamily) {
|
||||
return rdsService.createDbProxy(name, engineFamily, true, false, PROXY_ROLE_ARN,
|
||||
PROXY_SUBNET_IDS, List.of("sg-proxy"), PROXY_AUTH, Map.of());
|
||||
}
|
||||
|
||||
private DbProxyEndpoint addProxyEndpoint(String proxyName, String endpointName, String targetRole) {
|
||||
return rdsService.createDbProxyEndpoint("us-east-1", proxyName, endpointName, PROXY_SUBNET_IDS,
|
||||
List.of("sg-endpoint"), targetRole, null, Map.of());
|
||||
}
|
||||
|
||||
private static List<String> endpointNames(RdsService.ProxyEndpointPage page) {
|
||||
return page.endpoints().stream().map(DbProxyEndpoint::getDbProxyEndpointName).toList();
|
||||
}
|
||||
|
||||
@Test
|
||||
void proxyEndpointIsCreatedDescribedRenamedAndDeleted() {
|
||||
DbProxy proxy = proxyForEndpoints("app-proxy", "POSTGRESQL");
|
||||
|
||||
DbProxyEndpoint reader = rdsService.createDbProxyEndpoint("us-east-1", "app-proxy", "reader",
|
||||
PROXY_SUBNET_IDS, List.of("sg-endpoint"), "READ_ONLY", null, Map.of("team", "data"));
|
||||
assertEquals("READ_ONLY", reader.getTargetRole());
|
||||
assertEquals("available", reader.getStatus());
|
||||
assertEquals("IPV4", reader.getEndpointNetworkType());
|
||||
assertEquals(proxy.getEndpoint(), reader.getEndpoint());
|
||||
assertEquals(proxy.getVpcId(), reader.getVpcId());
|
||||
assertFalse(reader.isDefault());
|
||||
assertTrue(reader.getDbProxyEndpointArn()
|
||||
.startsWith("arn:aws:rds:us-east-1:123456789012:db-proxy-endpoint:prx-endpoint-"));
|
||||
|
||||
RdsService.ProxyEndpointPage page = rdsService.describeDbProxyEndpoints("us-east-1", "app-proxy", null,
|
||||
null, null);
|
||||
assertEquals(List.of("default", "reader"), endpointNames(page));
|
||||
DbProxyEndpoint byDefault = page.endpoints().get(0);
|
||||
assertTrue(byDefault.isDefault());
|
||||
assertEquals("READ_WRITE", byDefault.getTargetRole());
|
||||
assertNull(byDefault.getDbProxyEndpointArn());
|
||||
assertEquals(proxy.getEndpoint(), byDefault.getEndpoint());
|
||||
assertEquals(List.of("sg-proxy"), byDefault.getVpcSecurityGroupIds());
|
||||
assertNull(page.marker());
|
||||
|
||||
DbProxyEndpoint renamed = rdsService.modifyDbProxyEndpoint("us-east-1", "reader", "analytics",
|
||||
List.of("sg-other"));
|
||||
assertEquals("analytics", renamed.getDbProxyEndpointName());
|
||||
assertEquals(List.of("sg-other"), renamed.getVpcSecurityGroupIds());
|
||||
assertEquals(reader.getDbProxyEndpointArn(), renamed.getDbProxyEndpointArn());
|
||||
AwsException oldName = assertThrows(AwsException.class,
|
||||
() -> rdsService.describeDbProxyEndpoints("us-east-1", null, "reader", null, null));
|
||||
assertEquals("DBProxyEndpointNotFoundFault", oldName.getErrorCode());
|
||||
|
||||
// Leaving the security groups out keeps them.
|
||||
assertEquals(List.of("sg-other"), rdsService.modifyDbProxyEndpoint("us-east-1", "analytics", null, null)
|
||||
.getVpcSecurityGroupIds());
|
||||
|
||||
assertEquals("deleting", rdsService.deleteDbProxyEndpoint("us-east-1", "analytics").getStatus());
|
||||
assertEquals(List.of("default"), endpointNames(
|
||||
rdsService.describeDbProxyEndpoints("us-east-1", "app-proxy", null, null, null)));
|
||||
AwsException gone = assertThrows(AwsException.class,
|
||||
() -> rdsService.deleteDbProxyEndpoint("us-east-1", "analytics"));
|
||||
assertEquals("DBProxyEndpointNotFoundFault", gone.getErrorCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* A restore can bring a proxy back on a new host. Every endpoint follows it, not only the
|
||||
* default one built from the proxy.
|
||||
*/
|
||||
@Test
|
||||
void proxyEndpointsReportTheProxysHostAfterARestoreMovesIt() {
|
||||
InMemoryStorage<String, DbProxy> proxies = new InMemoryStorage<>();
|
||||
RdsService service = proxyStoreService(regionResolver, config, proxies, new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>());
|
||||
service.createDbProxy("app-proxy", "POSTGRESQL", true, false, PROXY_ROLE_ARN, PROXY_SUBNET_IDS,
|
||||
List.of(), PROXY_AUTH, Map.of());
|
||||
service.createDbProxyEndpoint("us-east-1", "app-proxy", "reader", PROXY_SUBNET_IDS, List.of(),
|
||||
"READ_ONLY", null, Map.of());
|
||||
|
||||
// Each step moves the proxy to a new host first, so no answer can carry an earlier one.
|
||||
moveProxyHost(proxies, "us-east-1::app-proxy", "proxy-restored-1.internal");
|
||||
RdsService.ProxyEndpointPage page = service.describeDbProxyEndpoints("us-east-1", "app-proxy", null,
|
||||
null, null);
|
||||
assertEquals(List.of("proxy-restored-1.internal", "proxy-restored-1.internal"),
|
||||
page.endpoints().stream().map(DbProxyEndpoint::getEndpoint).toList());
|
||||
moveProxyHost(proxies, "us-east-1::app-proxy", "proxy-restored-2.internal");
|
||||
assertEquals("proxy-restored-2.internal", service.modifyDbProxyEndpoint("us-east-1", "reader", null, null)
|
||||
.getEndpoint());
|
||||
moveProxyHost(proxies, "us-east-1::app-proxy", "proxy-restored-3.internal");
|
||||
assertEquals("proxy-restored-3.internal", service.deleteDbProxyEndpoint("us-east-1", "reader").getEndpoint());
|
||||
}
|
||||
|
||||
private static void moveProxyHost(InMemoryStorage<String, DbProxy> proxies, String key, String host) {
|
||||
DbProxy restored = proxies.get(key).orElseThrow();
|
||||
restored.setEndpointHost(host);
|
||||
proxies.put(key, restored);
|
||||
}
|
||||
|
||||
/** A missing required member is MissingParameter, checked before any lookup, and changes nothing. */
|
||||
@Test
|
||||
void proxyEndpointRequiredMembersAreMissingParameter() {
|
||||
proxyForEndpoints("app-proxy", "POSTGRESQL");
|
||||
addProxyEndpoint("app-proxy", "kept", null);
|
||||
|
||||
List<Map.Entry<String, Executable>> missing = List.of(
|
||||
Map.entry("DBProxyName", () -> rdsService.createDbProxyEndpoint("us-east-1", null, "ep",
|
||||
PROXY_SUBNET_IDS, List.of(), null, null, Map.of())),
|
||||
Map.entry("DBProxyEndpointName", () -> rdsService.createDbProxyEndpoint("us-east-1", "app-proxy",
|
||||
"", PROXY_SUBNET_IDS, List.of(), null, null, Map.of())),
|
||||
Map.entry("VpcSubnetIds", () -> rdsService.createDbProxyEndpoint("us-east-1", "app-proxy", "ep",
|
||||
List.of(), List.of(), null, null, Map.of())),
|
||||
// Reported as missing before the unknown proxy is looked up.
|
||||
Map.entry("VpcSubnetIds", () -> rdsService.createDbProxyEndpoint("us-east-1", "absent", "ep",
|
||||
null, List.of(), null, null, Map.of())),
|
||||
Map.entry("DBProxyEndpointName", () -> rdsService.modifyDbProxyEndpoint("us-east-1", null,
|
||||
"renamed", List.of("sg-x"))),
|
||||
Map.entry("DBProxyEndpointName", () -> rdsService.deleteDbProxyEndpoint("us-east-1", " ")));
|
||||
for (Map.Entry<String, Executable> c : missing) {
|
||||
AwsException e = assertThrows(AwsException.class, c.getValue(), c.getKey());
|
||||
assertEquals("MissingParameter", e.getErrorCode(), c.getKey());
|
||||
assertEquals("The request must contain the parameter " + c.getKey() + ".", e.getMessage());
|
||||
assertEquals(400, e.getHttpStatus());
|
||||
}
|
||||
assertEquals(List.of("default", "kept"), endpointNames(
|
||||
rdsService.describeDbProxyEndpoints("us-east-1", "app-proxy", null, null, null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void proxyEndpointRequestsAreCheckedAgainstTheModel() {
|
||||
proxyForEndpoints("app-proxy", "POSTGRESQL");
|
||||
proxyForEndpoints("mssql-proxy", "SQLSERVER");
|
||||
addProxyEndpoint("app-proxy", "taken", null);
|
||||
|
||||
Map<String, Executable> refused = new LinkedHashMap<>();
|
||||
refused.put("DBProxyNotFoundFault", () -> addProxyEndpoint("absent", "ep", null));
|
||||
refused.put("InvalidParameterValue", () -> addProxyEndpoint("app-proxy", "1st", null));
|
||||
refused.put("DBProxyEndpointAlreadyExistsFault", () -> addProxyEndpoint("app-proxy", "taken", null));
|
||||
refused.put("InvalidParameterCombination", () -> addProxyEndpoint("mssql-proxy", "ro", "READ_ONLY"));
|
||||
refused.put("InvalidSubnet", () -> rdsService.createDbProxyEndpoint("us-east-1", "app-proxy", "ep",
|
||||
List.of("subnet-missing"), List.of(), null, null, Map.of()));
|
||||
for (Map.Entry<String, Executable> c : refused.entrySet()) {
|
||||
assertEquals(c.getKey(), assertThrows(AwsException.class, c.getValue()).getErrorCode(), c.getKey());
|
||||
}
|
||||
for (Executable invalid : List.<Executable>of(
|
||||
() -> addProxyEndpoint("app-proxy", "a--b", null),
|
||||
() -> addProxyEndpoint("app-proxy", "ends-", null),
|
||||
() -> addProxyEndpoint("app-proxy", "e".repeat(64), null),
|
||||
() -> addProxyEndpoint("app-proxy", "ep", "WRITER"),
|
||||
// The default VPC carries no IPv6 block, so an IPv6 endpoint cannot be placed in it.
|
||||
() -> rdsService.createDbProxyEndpoint("us-east-1", "app-proxy", "ep", PROXY_SUBNET_IDS,
|
||||
List.of(), null, "IPV6", Map.of()))) {
|
||||
assertEquals("InvalidParameterValue", assertThrows(AwsException.class, invalid).getErrorCode());
|
||||
}
|
||||
// An unknown network type is refused for what it is, before any VPC check.
|
||||
AwsException networkType = assertThrows(AwsException.class, () -> rdsService.createDbProxyEndpoint(
|
||||
"us-east-1", "app-proxy", "ep", PROXY_SUBNET_IDS, List.of(), null, "IPV5", Map.of()));
|
||||
assertEquals("InvalidParameterValue", networkType.getErrorCode());
|
||||
assertTrue(networkType.getMessage().contains("EndpointNetworkType must be IPV4, IPV6, or DUAL"),
|
||||
networkType.getMessage());
|
||||
// The name is the default endpoint's, which every proxy already has.
|
||||
assertEquals("DBProxyEndpointAlreadyExistsFault", assertThrows(AwsException.class,
|
||||
() -> addProxyEndpoint("app-proxy", "default", null)).getErrorCode());
|
||||
// Names are unique across the account's proxies, not per proxy.
|
||||
assertEquals("DBProxyEndpointAlreadyExistsFault", assertThrows(AwsException.class,
|
||||
() -> addProxyEndpoint("mssql-proxy", "taken", null)).getErrorCode());
|
||||
assertEquals("READ_WRITE", addProxyEndpoint("mssql-proxy", "rw", null).getTargetRole());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aProxyHoldsAtMostTwentyEndpoints() {
|
||||
proxyForEndpoints("app-proxy", "POSTGRESQL");
|
||||
for (int i = 1; i < 20; i++) {
|
||||
addProxyEndpoint("app-proxy", "ep" + i, null);
|
||||
}
|
||||
addProxyEndpoint("app-proxy", "ep20", null);
|
||||
AwsException full = assertThrows(AwsException.class, () -> addProxyEndpoint("app-proxy", "ep21", null));
|
||||
assertEquals("DBProxyEndpointQuotaExceededFault", full.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void theDefaultProxyEndpointCannotBeChangedAndARenameCannotTakeAName() {
|
||||
proxyForEndpoints("app-proxy", "POSTGRESQL");
|
||||
addProxyEndpoint("app-proxy", "first", null);
|
||||
addProxyEndpoint("app-proxy", "second", null);
|
||||
|
||||
assertEquals("InvalidDBProxyEndpointStateFault", assertThrows(AwsException.class,
|
||||
() -> rdsService.modifyDbProxyEndpoint("us-east-1", "default", "renamed", null)).getErrorCode());
|
||||
assertEquals("InvalidDBProxyEndpointStateFault", assertThrows(AwsException.class,
|
||||
() -> rdsService.deleteDbProxyEndpoint("us-east-1", "default")).getErrorCode());
|
||||
assertEquals("DBProxyEndpointAlreadyExistsFault", assertThrows(AwsException.class,
|
||||
() -> rdsService.modifyDbProxyEndpoint("us-east-1", "first", "second", null)).getErrorCode());
|
||||
assertEquals("DBProxyEndpointAlreadyExistsFault", assertThrows(AwsException.class,
|
||||
() -> rdsService.modifyDbProxyEndpoint("us-east-1", "first", "default", null)).getErrorCode());
|
||||
assertEquals("DBProxyEndpointNotFoundFault", assertThrows(AwsException.class,
|
||||
() -> rdsService.modifyDbProxyEndpoint("us-east-1", "absent", null, null)).getErrorCode());
|
||||
assertEquals(List.of("default", "first", "second"), endpointNames(
|
||||
rdsService.describeDbProxyEndpoints("us-east-1", "app-proxy", null, null, null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anEndpointOnAProxyThatIsNotAvailableIsRefused() {
|
||||
InMemoryStorage<String, DbProxy> proxies = new InMemoryStorage<>();
|
||||
rdsService = proxyStoreService(regionResolver, config, proxies, new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>());
|
||||
proxyForEndpoints("app-proxy", "POSTGRESQL");
|
||||
addProxyEndpoint("app-proxy", "before", null);
|
||||
String key = proxies.keys().iterator().next();
|
||||
DbProxy stored = proxies.get(key).orElseThrow();
|
||||
stored.setStatus("modifying");
|
||||
proxies.put(key, stored);
|
||||
|
||||
assertEquals("InvalidDBProxyStateFault", assertThrows(AwsException.class,
|
||||
() -> addProxyEndpoint("app-proxy", "ep", null)).getErrorCode());
|
||||
assertEquals("InvalidDBProxyStateFault", assertThrows(AwsException.class,
|
||||
() -> rdsService.modifyDbProxyEndpoint("us-east-1", "before", "after", null)).getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletingAProxyDeletesItsEndpoints() {
|
||||
proxyForEndpoints("proxy-a", "POSTGRESQL");
|
||||
proxyForEndpoints("proxy-b", "POSTGRESQL");
|
||||
addProxyEndpoint("proxy-a", "shared-name", null);
|
||||
addProxyEndpoint("proxy-b", "b-endpoint", null);
|
||||
|
||||
rdsService.deleteDbProxy("proxy-a", "us-east-1");
|
||||
|
||||
assertEquals(List.of("default", "b-endpoint"), endpointNames(
|
||||
rdsService.describeDbProxyEndpoints("us-east-1", null, null, null, null)));
|
||||
assertEquals("DBProxyEndpointNotFoundFault", assertThrows(AwsException.class,
|
||||
() -> rdsService.deleteDbProxyEndpoint("us-east-1", "shared-name")).getErrorCode());
|
||||
// The deleted proxy's endpoint name is free again.
|
||||
assertEquals("proxy-b", addProxyEndpoint("proxy-b", "shared-name", null).getDbProxyName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void proxyEndpointsPageAndFilterByName() {
|
||||
proxyForEndpoints("proxy-a", "POSTGRESQL");
|
||||
proxyForEndpoints("proxy-b", "POSTGRESQL");
|
||||
for (int i = 10; i < 30; i++) {
|
||||
addProxyEndpoint("proxy-a", "a" + i, null);
|
||||
}
|
||||
for (int i = 10; i < 15; i++) {
|
||||
addProxyEndpoint("proxy-b", "b" + i, null);
|
||||
}
|
||||
|
||||
RdsService.ProxyEndpointPage first = rdsService.describeDbProxyEndpoints("us-east-1", null, null, 20, null);
|
||||
assertEquals(20, first.endpoints().size());
|
||||
assertEquals("default", first.endpoints().get(0).getDbProxyEndpointName());
|
||||
assertEquals("proxy-a", first.endpoints().get(0).getDbProxyName());
|
||||
assertNotNull(first.marker());
|
||||
RdsService.ProxyEndpointPage second = rdsService.describeDbProxyEndpoints("us-east-1", null, null, 20,
|
||||
first.marker());
|
||||
assertEquals(List.of("a29", "default", "b10", "b11", "b12", "b13", "b14"), endpointNames(second));
|
||||
assertNull(second.marker());
|
||||
|
||||
assertEquals(List.of("b12"), endpointNames(
|
||||
rdsService.describeDbProxyEndpoints("us-east-1", null, "b12", null, null)));
|
||||
assertEquals("DBProxyEndpointNotFoundFault", assertThrows(AwsException.class,
|
||||
() -> rdsService.describeDbProxyEndpoints("us-east-1", "proxy-a", "b12", null, null))
|
||||
.getErrorCode());
|
||||
assertEquals("DBProxyNotFoundFault", assertThrows(AwsException.class,
|
||||
() -> rdsService.describeDbProxyEndpoints("us-east-1", "absent", null, null, null)).getErrorCode());
|
||||
assertEquals("InvalidParameterValue", assertThrows(AwsException.class,
|
||||
() -> rdsService.describeDbProxyEndpoints("us-east-1", null, null, 19, null)).getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void proxyEndpointTagsRoundTripAndItDefaultsToTheVpcsDefaultSecurityGroup() {
|
||||
DbProxy proxy = proxyForEndpoints("app-proxy", "POSTGRESQL");
|
||||
SecurityGroup defaultGroup = new SecurityGroup();
|
||||
defaultGroup.setGroupId("sg-vpc-default");
|
||||
defaultGroup.setGroupName("default");
|
||||
SecurityGroup otherGroup = new SecurityGroup();
|
||||
otherGroup.setGroupId("sg-vpc-other");
|
||||
otherGroup.setGroupName("other");
|
||||
when(ec2Service.getSecurityGroupsForVpc("us-east-1", proxy.getVpcId(), Map.of()))
|
||||
.thenReturn(List.of(otherGroup, defaultGroup));
|
||||
|
||||
DbProxyEndpoint endpoint = rdsService.createDbProxyEndpoint("us-east-1", "app-proxy", "ep",
|
||||
PROXY_SUBNET_IDS, List.of(), null, null, Map.of("env", "dev"));
|
||||
assertEquals(List.of("sg-vpc-default"), endpoint.getVpcSecurityGroupIds());
|
||||
|
||||
String arn = endpoint.getDbProxyEndpointArn();
|
||||
assertEquals(Map.of("env", "dev"), rdsService.listTagsForResource(arn));
|
||||
rdsService.addTagsToResource(arn, Map.of("team", "data"));
|
||||
rdsService.removeTagsFromResource(arn, List.of("env"));
|
||||
assertEquals(Map.of("team", "data"), rdsService.listTagsForResource(arn));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user