mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(apigatewayv2): cascade-delete child resources and 404 references … (#1300)
* fix(apigatewayv2): cascade-delete child resources and 404 references on DeleteApi Closes #1218. DeleteApi removed only the Api row, leaving routes, integrations, stages, deployments, authorizers, models, route responses, and integration responses orphaned under their region::apiId::* keys. The list endpoints also silently returned empty lists for unknown apiIds instead of 404. Both diverge from real AWS (children deleted; subsequent reads return NotFoundException). - deleteApi now cascades through every api-scoped child store, mirroring the existing apigateway v1 deleteRestApi pattern (api row first, then inline stream-based deletes per store, then LOG.infov). - VpcLink is region-scoped (region::vpcLinkId — shared across APIs) and intentionally excluded from the cascade. - getRoutes / getStages / getIntegrations / getAuthorizers / getModels / getDeployments / getRouteResponses / getIntegrationResponses now call getApi(region, apiId) first so they 404 when the API doesn't exist, matching real AWS behavior. Verified end-to-end with boto3 against running Floci: the reproduction from #1218 went from 6 leaked child types on main to 0 with this branch. * refactor(apigatewayv2): extract deleteByPrefix helper, consolidate cascade tests
This commit is contained in:
1 parent
1ffa9a4e21
commit
bb5a37d19e
2 files changed
+202
No files matched your search
+178
@@ -0,0 +1,178 @@
|
||||
package io.github.hectorvent.floci.services.apigatewayv2;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
@QuarkusTest
|
||||
class ApiGatewayV2DeleteApiCascadeTest {
|
||||
|
||||
@Test
|
||||
void deleteApiCascadesEveryChildResourceAnd404sOnSubsequentReferences() {
|
||||
String apiId = null;
|
||||
try {
|
||||
// 1. setup: create the API and every flavor of child resource under it.
|
||||
apiId = createApi("cascade-probe");
|
||||
String integrationId = createIntegration(apiId);
|
||||
String routeId = createRoute(apiId, integrationId);
|
||||
createStage(apiId);
|
||||
createAuthorizer(apiId);
|
||||
createDeployment(apiId);
|
||||
createModel(apiId);
|
||||
createRouteResponse(apiId, routeId);
|
||||
createIntegrationResponse(apiId, integrationId);
|
||||
|
||||
// 2. delete the API.
|
||||
given().when().delete("/v2/apis/" + apiId).then().statusCode(204);
|
||||
|
||||
// 3. every reference to the deleted apiId must 404.
|
||||
List<String> probes = List.of(
|
||||
"",
|
||||
"/routes",
|
||||
"/integrations",
|
||||
"/stages",
|
||||
"/authorizers",
|
||||
"/deployments",
|
||||
"/models",
|
||||
"/routes/" + routeId + "/routeresponses",
|
||||
"/integrations/" + integrationId + "/integrationresponses"
|
||||
);
|
||||
for (String suffix : probes) {
|
||||
given().when().get("/v2/apis/" + apiId + suffix)
|
||||
.then().statusCode(404);
|
||||
}
|
||||
} finally {
|
||||
// best-effort cleanup in case any assertion above failed before delete-api ran.
|
||||
if (apiId != null) {
|
||||
given().when().delete("/v2/apis/" + apiId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void cascadeIsScopedToSingleApi() {
|
||||
// Create two APIs with children under each; delete only api A; api B's children must remain.
|
||||
String aId = null;
|
||||
String bId = null;
|
||||
try {
|
||||
aId = createApi("cascade-iso-a");
|
||||
bId = createApi("cascade-iso-b");
|
||||
createIntegration(aId);
|
||||
createIntegration(bId);
|
||||
|
||||
given().when().delete("/v2/apis/" + aId).then().statusCode(204);
|
||||
|
||||
// A is gone — every reference 404s.
|
||||
given().when().get("/v2/apis/" + aId + "/integrations").then().statusCode(404);
|
||||
|
||||
// B is untouched.
|
||||
given().when().get("/v2/apis/" + bId + "/integrations")
|
||||
.then().statusCode(200).body("items", hasSize(1));
|
||||
} finally {
|
||||
if (bId != null) given().when().delete("/v2/apis/" + bId);
|
||||
if (aId != null) given().when().delete("/v2/apis/" + aId);
|
||||
}
|
||||
}
|
||||
|
||||
// ──────────────────────────── creation helpers ────────────────────────────
|
||||
|
||||
private static String createApi(String name) {
|
||||
return given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"" + name + "\",\"protocolType\":\"HTTP\"}")
|
||||
.when().post("/v2/apis")
|
||||
.then().statusCode(201)
|
||||
.extract().path("apiId");
|
||||
}
|
||||
|
||||
private static String createIntegration(String apiId) {
|
||||
return given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"integrationType":"HTTP_PROXY","integrationUri":"https://example.com",
|
||||
"integrationMethod":"GET","payloadFormatVersion":"1.0"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/integrations")
|
||||
.then().statusCode(201)
|
||||
.extract().path("integrationId");
|
||||
}
|
||||
|
||||
private static String createRoute(String apiId, String integrationId) {
|
||||
return given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"routeKey":"GET /hello","target":"integrations/%s"}
|
||||
""".formatted(integrationId))
|
||||
.when().post("/v2/apis/" + apiId + "/routes")
|
||||
.then().statusCode(201)
|
||||
.extract().path("routeId");
|
||||
}
|
||||
|
||||
private static void createStage(String apiId) {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"stageName":"dev","autoDeploy":true}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/stages")
|
||||
.then().statusCode(201);
|
||||
}
|
||||
|
||||
private static void createAuthorizer(String apiId) {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"authorizerType":"JWT","name":"probe-jwt",
|
||||
"identitySource":["$request.header.Authorization"],
|
||||
"jwtConfiguration":{"issuer":"https://example.com","audience":["a"]}}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/authorizers")
|
||||
.then().statusCode(201);
|
||||
}
|
||||
|
||||
private static void createDeployment(String apiId) {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"description":"probe-dep","stageName":"dev"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/deployments")
|
||||
.then().statusCode(201);
|
||||
}
|
||||
|
||||
private static void createModel(String apiId) {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"ProbeModel","contentType":"application/json",
|
||||
"schema":"{\\"type\\":\\"object\\"}"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/models")
|
||||
.then().statusCode(201);
|
||||
}
|
||||
|
||||
private static void createRouteResponse(String apiId, String routeId) {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"routeResponseKey":"$default"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/routes/" + routeId + "/routeresponses")
|
||||
.then().statusCode(201);
|
||||
}
|
||||
|
||||
private static void createIntegrationResponse(String apiId, String integrationId) {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"integrationResponseKey":"$default"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/integrations/" + integrationId + "/integrationresponses")
|
||||
.then().statusCode(201);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user