mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ApiGateway): implement EndpointConfiguration for REST APIs (#1116)
This commit is contained in:
1 parent
938c693f8d
commit
3989064a1c
8 files changed
+314
No files matched your search
+127
@@ -0,0 +1,127 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
@QuarkusTest
|
||||
class ApiGatewayEndpointConfigurationIntegrationTest {
|
||||
|
||||
@Test
|
||||
void createRestApi_withEndpointConfiguration_Private() {
|
||||
String body = """
|
||||
{
|
||||
"name": "private-api",
|
||||
"endpointConfiguration": {
|
||||
"types": ["PRIVATE"],
|
||||
"vpcEndpointIds": ["vpce-123"]
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
String apiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body(body)
|
||||
.when().post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("endpointConfiguration.types", contains("PRIVATE"))
|
||||
.body("endpointConfiguration.vpcEndpointIds", contains("vpce-123"))
|
||||
.extract().path("id");
|
||||
|
||||
// Verify preservation during OpenAPI update (putRestApi)
|
||||
String openApiSpec = """
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: Updated API
|
||||
version: 1.0.0
|
||||
paths:
|
||||
/:
|
||||
get:
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
""";
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body(openApiSpec)
|
||||
.when().put("/restapis/" + apiId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("name", equalTo("Updated API"))
|
||||
.body("endpointConfiguration.types", contains("PRIVATE"))
|
||||
.body("endpointConfiguration.vpcEndpointIds", contains("vpce-123"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRestApi_withDefaultEndpointConfiguration() {
|
||||
String body = """
|
||||
{"name": "default-api"}
|
||||
""";
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body(body)
|
||||
.when().post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("endpointConfiguration.types", contains("REGIONAL"))
|
||||
.body("endpointConfiguration.vpcEndpointIds", empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRestApi_ValidationFailures() {
|
||||
// Multiple types
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"bad-api\", \"endpointConfiguration\":{\"types\":[\"REGIONAL\", \"EDGE\"]}}")
|
||||
.when().post("/restapis")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("message", containsString("exactly one value"));
|
||||
|
||||
// Invalid type
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"bad-api\", \"endpointConfiguration\":{\"types\":[\"INVALID\"]}}")
|
||||
.when().post("/restapis")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("message", containsString("REGIONAL, EDGE, or PRIVATE"));
|
||||
|
||||
// Private without VPC IDs
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"bad-api\", \"endpointConfiguration\":{\"types\":[\"PRIVATE\"]}}")
|
||||
.when().post("/restapis")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("message", containsString("At least one vpcEndpointId is required"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRestApi_RegionalIgnoresVpcIds() {
|
||||
String body = """
|
||||
{
|
||||
"name": "regional-api",
|
||||
"endpointConfiguration": {
|
||||
"types": ["REGIONAL"],
|
||||
"vpcEndpointIds": ["vpce-123"]
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body(body)
|
||||
.when().post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("endpointConfiguration.types", contains("REGIONAL"))
|
||||
.body("endpointConfiguration.vpcEndpointIds", empty());
|
||||
}
|
||||
}
|
||||
+55
@@ -19,6 +19,7 @@ import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
@@ -5781,4 +5782,58 @@ class CloudFormationIntegrationTest {
|
||||
.body(containsString("CREATE_FAILED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStack_apiGatewayRestApi_withEndpointConfiguration() {
|
||||
String template = """
|
||||
{
|
||||
"Resources": {
|
||||
"MyPrivateApi": {
|
||||
"Type": "AWS::ApiGateway::RestApi",
|
||||
"Properties": {
|
||||
"Name": "cfn-private-api",
|
||||
"EndpointConfiguration": {
|
||||
"Types": ["PRIVATE"],
|
||||
"VpcEndpointIds": ["vpce-12345678"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
String stackName = "apigw-ep-stack";
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateStack")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("TemplateBody", template)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<StackId>"));
|
||||
|
||||
String resourcesXml = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStackResources")
|
||||
.formParam("StackName", stackName)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().asString();
|
||||
|
||||
String apiId = physicalIdByLogicalId(resourcesXml, "MyPrivateApi");
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/restapis/" + apiId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("name", equalTo("cfn-private-api"))
|
||||
.body("endpointConfiguration.types", contains("PRIVATE"))
|
||||
.body("endpointConfiguration.vpcEndpointIds", contains("vpce-12345678"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user