mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(rds): EnableHttpEndpoint, DisableHttpEndpoint and HttpEndpointEnabled (#5736)
* feat(rds): EnableHttpEndpoint, DisableHttpEndpoint and HttpEndpointEnabled EnableHttpEndpoint and DisableHttpEndpoint answered UnsupportedOperation and DBCluster carried no HttpEndpointEnabled, so Terraform's enable_http_endpoint and CDK's enableDataApi never read back what they set. Clusters now record the flag and report it. The two actions take the cluster's ARN and raise ResourceNotFoundFault and InvalidResourceStateFault as the model lists them; CreateDBCluster, ModifyDBCluster and the AWS::RDS::DBCluster EnableHttpEndpoint property set it too. Turning it on is refused for engines other than Aurora PostgreSQL and Aurora MySQL. The Data API itself does not check the flag, so existing callers keep working. Closes #5732 * refactor(rds): one cluster ARN parser, and stricter Data API inputs clusterForResourceArn repeated the ARN parsing, cluster: prefix and account and Region check of clusterIdentifierFromArnOrName; both now call clusterIdFromArn, each raising the error its API documents. The Data API engine check takes aurora-postgresql, aurora-mysql and the older aurora name exactly instead of any name starting with aurora, and the AWS::RDS::DBCluster EnableHttpEndpoint property accepts true or false only, so a malformed value fails instead of turning the endpoint off. * fix(rds): take only aurora-mysql and aurora-postgresql for the Data API The API reference lists those two engines, and new clusters cannot carry the bare aurora name, so the check no longer accepts it.
This commit is contained in:
1 parent
a37c27516a
commit
9cd9002e73
13 files changed
+429
-6
No files matched your search
+55
@@ -232,6 +232,61 @@ class RdsCfnProvisionerTest {
|
||||
null, null, null, false, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
void dbClusterEnableHttpEndpointIsAppliedOnCreateAndUpdate() {
|
||||
createDbClusterEchoesRequestedId();
|
||||
DbCluster enabled = mock(DbCluster.class);
|
||||
when(enabled.getDbClusterIdentifier()).thenReturn("dataapi");
|
||||
when(enabled.isHttpEndpointEnabled()).thenReturn(true);
|
||||
when(rdsService.setHttpEndpoint("us-east-1", "dataapi", true)).thenReturn(enabled);
|
||||
|
||||
StackResource r = provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
{"DBClusterIdentifier":"dataapi","Engine":"aurora-postgresql","EnableHttpEndpoint":true}
|
||||
""");
|
||||
assertEquals("CREATE_COMPLETE", r.getStatus());
|
||||
verify(rdsService).setHttpEndpoint("us-east-1", "dataapi", true);
|
||||
|
||||
// An update that leaves the property out turns the endpoint off again.
|
||||
when(rdsService.getDbCluster("dataapi")).thenReturn(enabled);
|
||||
when(rdsService.modifyDbCluster(eq("dataapi"), any(), any(), any(), any(), any(), any())).thenReturn(enabled);
|
||||
DbCluster disabled = mock(DbCluster.class);
|
||||
when(disabled.getDbClusterIdentifier()).thenReturn("dataapi");
|
||||
when(rdsService.setHttpEndpoint("us-east-1", "dataapi", false)).thenReturn(disabled);
|
||||
provisionExisting("Cluster", "AWS::RDS::DBCluster", """
|
||||
{"DBClusterIdentifier":"dataapi","Engine":"aurora-postgresql"}
|
||||
""", "us-east-1", "dataapi", Map.of("DBClusterIdentifier", "dataapi"));
|
||||
verify(rdsService).setHttpEndpoint("us-east-1", "dataapi", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMalformedEnableHttpEndpointFailsInsteadOfTurningTheEndpointOff() {
|
||||
DbCluster enabled = mock(DbCluster.class);
|
||||
when(enabled.getDbClusterIdentifier()).thenReturn("dataapi");
|
||||
when(enabled.isHttpEndpointEnabled()).thenReturn(true);
|
||||
when(rdsService.getDbCluster("dataapi")).thenReturn(enabled);
|
||||
when(rdsService.modifyDbCluster(eq("dataapi"), any(), any(), any(), any(), any(), any())).thenReturn(enabled);
|
||||
|
||||
StackResource r = provisionExisting("Cluster", "AWS::RDS::DBCluster", """
|
||||
{"DBClusterIdentifier":"dataapi","Engine":"aurora-postgresql","EnableHttpEndpoint":"yes"}
|
||||
""", "us-east-1", "dataapi", Map.of("DBClusterIdentifier", "dataapi"));
|
||||
|
||||
assertEquals("CREATE_FAILED", r.getStatus());
|
||||
assertTrue(r.getStatusReason().contains("EnableHttpEndpoint must be true or false"), r.getStatusReason());
|
||||
verify(rdsService, never()).setHttpEndpoint(any(), any(), anyBoolean());
|
||||
verify(rdsService, never()).modifyDbCluster(any(), any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void dbClusterEnableHttpEndpointOnANonAuroraEngineFailsBeforeCreating() {
|
||||
StackResource r = provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
{"DBClusterIdentifier":"dataapi","Engine":"postgres","EnableHttpEndpoint":true}
|
||||
""");
|
||||
assertEquals("CREATE_FAILED", r.getStatus());
|
||||
assertTrue(r.getStatusReason().contains("Aurora"), r.getStatusReason());
|
||||
verify(rdsService, never()).createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(), anyBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
void provisionsDbClusterInStackRegion() {
|
||||
DbCluster cluster = mock(DbCluster.class);
|
||||
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
package io.github.hectorvent.floci.services.rds;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RdsMockProfile;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
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;
|
||||
|
||||
/**
|
||||
* The Data API switch: {@code EnableHttpEndpoint} and {@code DisableHttpEndpoint} by cluster ARN,
|
||||
* {@code EnableHttpEndpoint} on {@code CreateDBCluster} and {@code ModifyDBCluster}, and
|
||||
* {@code HttpEndpointEnabled} on {@code DBCluster}.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestProfile(RdsMockProfile.class)
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class RdsHttpEndpointIntegrationTest {
|
||||
|
||||
private static final String CLUSTER = "data-api-cluster";
|
||||
private static final String ARN = "arn:aws:rds:us-east-1:000000000000:cluster:" + CLUSTER;
|
||||
private static final String DESCRIBED =
|
||||
"DescribeDBClustersResponse.DescribeDBClustersResult.DBClusters.DBCluster.HttpEndpointEnabled";
|
||||
|
||||
private static final String AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20261015/us-east-1/rds/aws4_request, "
|
||||
+ "SignedHeaders=content-type;host, Signature=test";
|
||||
|
||||
private static RequestSpecification query(String action) {
|
||||
return given().header("Authorization", AUTH)
|
||||
.contentType(URLENC)
|
||||
.formParam("Action", action)
|
||||
.formParam("Version", "2014-10-31");
|
||||
}
|
||||
|
||||
private static RequestSpecification createCluster(String id, String engine) {
|
||||
return query("CreateDBCluster")
|
||||
.formParam("DBClusterIdentifier", id)
|
||||
.formParam("Engine", engine)
|
||||
.formParam("MasterUsername", "admin")
|
||||
.formParam("MasterUserPassword", "password123");
|
||||
}
|
||||
|
||||
private static void expectFlag(String clusterId, String value) {
|
||||
query("DescribeDBClusters").formParam("DBClusterIdentifier", clusterId)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(DESCRIBED, equalTo(value));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void aNewClusterHasTheEndpointOff() {
|
||||
createCluster(CLUSTER, "aurora-postgresql")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<HttpEndpointEnabled>false</HttpEndpointEnabled>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void enableAndDisableByClusterArn() {
|
||||
query("EnableHttpEndpoint").formParam("ResourceArn", ARN)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body("EnableHttpEndpointResponse.EnableHttpEndpointResult.ResourceArn", equalTo(ARN))
|
||||
.body("EnableHttpEndpointResponse.EnableHttpEndpointResult.HttpEndpointEnabled", equalTo("true"));
|
||||
expectFlag(CLUSTER, "true");
|
||||
|
||||
query("DisableHttpEndpoint").formParam("ResourceArn", ARN)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body("DisableHttpEndpointResponse.DisableHttpEndpointResult.HttpEndpointEnabled", equalTo("false"));
|
||||
expectFlag(CLUSTER, "false");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void createAndModifyTakeEnableHttpEndpoint() {
|
||||
createCluster("data-api-at-create", "aurora-mysql").formParam("EnableHttpEndpoint", "true")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<HttpEndpointEnabled>true</HttpEndpointEnabled>"));
|
||||
expectFlag("data-api-at-create", "true");
|
||||
|
||||
query("ModifyDBCluster").formParam("DBClusterIdentifier", "data-api-at-create")
|
||||
.formParam("EnableHttpEndpoint", "false")
|
||||
.when().post("/").then().statusCode(200);
|
||||
expectFlag("data-api-at-create", "false");
|
||||
// A modify that leaves the parameter out leaves the flag as it is.
|
||||
query("ModifyDBCluster").formParam("DBClusterIdentifier", CLUSTER)
|
||||
.formParam("EnableHttpEndpoint", "true")
|
||||
.when().post("/").then().statusCode(200);
|
||||
query("ModifyDBCluster").formParam("DBClusterIdentifier", CLUSTER)
|
||||
.formParam("EnableIAMDatabaseAuthentication", "true")
|
||||
.when().post("/").then().statusCode(200);
|
||||
expectFlag(CLUSTER, "true");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void anArnThatNamesNoClusterHereIsNotFound() {
|
||||
for (String arn : new String[] {
|
||||
"arn:aws:rds:us-east-1:000000000000:cluster:no-such-cluster",
|
||||
"arn:aws:rds:us-east-1:000000000000:db:" + CLUSTER,
|
||||
"arn:aws:rds:eu-west-1:000000000000:cluster:" + CLUSTER,
|
||||
"arn:aws:rds:us-east-1:111111111111:cluster:" + CLUSTER,
|
||||
"not-an-arn"}) {
|
||||
query("EnableHttpEndpoint").formParam("ResourceArn", arn)
|
||||
.when().post("/").then().statusCode(404)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ResourceNotFoundFault"));
|
||||
}
|
||||
query("EnableHttpEndpoint")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("MissingParameter"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void aStoppedClusterIsInTheWrongState() {
|
||||
query("StopDBCluster").formParam("DBClusterIdentifier", CLUSTER)
|
||||
.when().post("/").then().statusCode(200);
|
||||
query("DisableHttpEndpoint").formParam("ResourceArn", ARN)
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("InvalidResourceStateFault"));
|
||||
query("StartDBCluster").formParam("DBClusterIdentifier", CLUSTER)
|
||||
.when().post("/").then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void onlyAuroraClustersTakeTheDataApi() {
|
||||
createCluster("data-api-postgres", "postgres").formParam("EnableHttpEndpoint", "true")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("InvalidParameterCombination"));
|
||||
query("DescribeDBClusters").formParam("DBClusterIdentifier", "data-api-postgres")
|
||||
.when().post("/").then().statusCode(404);
|
||||
|
||||
createCluster("data-api-postgres", "postgres")
|
||||
.when().post("/").then().statusCode(200);
|
||||
query("EnableHttpEndpoint")
|
||||
.formParam("ResourceArn", "arn:aws:rds:us-east-1:000000000000:cluster:data-api-postgres")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("InvalidParameterCombination"));
|
||||
query("ModifyDBCluster").formParam("DBClusterIdentifier", "data-api-postgres")
|
||||
.formParam("EnableHttpEndpoint", "true")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("InvalidParameterCombination"));
|
||||
// Turning it off is never refused.
|
||||
query("DisableHttpEndpoint")
|
||||
.formParam("ResourceArn", "arn:aws:rds:us-east-1:000000000000:cluster:data-api-postgres")
|
||||
.when().post("/").then().statusCode(200);
|
||||
}
|
||||
}
|
||||
@@ -3240,6 +3240,16 @@ class RdsServiceTest {
|
||||
assertNull(RdsEngineCatalog.featureNamesForEngine(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theDataApiTakesOnlyTheAuroraEngines() {
|
||||
RdsService.requireDataApiEngine("aurora-postgresql");
|
||||
RdsService.requireDataApiEngine("AURORA-MYSQL");
|
||||
for (String engine : new String[] {"aurora", "aurora-serverless", "aurora-postgresql-limitless", "postgres", null}) {
|
||||
AwsException refused = assertThrows(AwsException.class, () -> RdsService.requireDataApiEngine(engine));
|
||||
assertEquals("InvalidParameterCombination", refused.getErrorCode(), String.valueOf(engine));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void engineVersionsSortNumericallyForUpgradeTargets() {
|
||||
RdsEngineCatalog.EngineVersion pg163 = RdsEngineCatalog.VERSIONS.stream()
|
||||
|
||||
+20
@@ -12,6 +12,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@@ -88,5 +89,24 @@ class DbClusterPersistenceTest {
|
||||
reader.load();
|
||||
|
||||
assertTrue(reader.get("legacy-cluster").orElseThrow().getAssociatedRoles().isEmpty());
|
||||
assertFalse(reader.get("legacy-cluster").orElseThrow().isHttpEndpointEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void httpEndpointFlagPersistsAcrossInstances(@TempDir Path directory) {
|
||||
Path file = directory.resolve("rds-clusters.json");
|
||||
DbCluster cluster = new DbCluster();
|
||||
cluster.setDbClusterIdentifier("data-api-cluster");
|
||||
cluster.setHttpEndpointEnabled(true);
|
||||
|
||||
PersistentStorage<String, DbCluster> writer = new PersistentStorage<>(
|
||||
file, new TypeReference<Map<String, DbCluster>>() {});
|
||||
writer.put(cluster.getDbClusterIdentifier(), cluster);
|
||||
|
||||
PersistentStorage<String, DbCluster> reader = new PersistentStorage<>(
|
||||
file, new TypeReference<Map<String, DbCluster>>() {});
|
||||
reader.load();
|
||||
|
||||
assertTrue(reader.get("data-api-cluster").orElseThrow().isHttpEndpointEnabled());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user