diff --git a/src/main/java/io/floci/aws/services/apigateway/ApiGatewayController.java b/src/main/java/io/floci/aws/services/apigateway/ApiGatewayController.java index 2748ba19cc..1d92b18267 100644 --- a/src/main/java/io/floci/aws/services/apigateway/ApiGatewayController.java +++ b/src/main/java/io/floci/aws/services/apigateway/ApiGatewayController.java @@ -2879,6 +2879,12 @@ public class ApiGatewayController { } if (i.getConnectionType() != null) node.put("connectionType", i.getConnectionType()); if (i.getConnectionId() != null) node.put("connectionId", i.getConnectionId()); + if (i.getTlsConfig() != null) { + ObjectNode tlsConfig = node.putObject("tlsConfig"); + if (i.getTlsConfig().getServerNameToVerify() != null) { + tlsConfig.put("serverNameToVerify", i.getTlsConfig().getServerNameToVerify()); + } + } node.put("payloadFormatVersion", i.getPayloadFormatVersion()); if (i.getCredentialsArn() != null) { node.put("credentialsArn", i.getCredentialsArn()); diff --git a/src/main/java/io/floci/aws/services/apigatewayv2/ApiGatewayV2JsonHandler.java b/src/main/java/io/floci/aws/services/apigatewayv2/ApiGatewayV2JsonHandler.java index 764c9c37cd..5cf245c018 100644 --- a/src/main/java/io/floci/aws/services/apigatewayv2/ApiGatewayV2JsonHandler.java +++ b/src/main/java/io/floci/aws/services/apigatewayv2/ApiGatewayV2JsonHandler.java @@ -664,6 +664,12 @@ public class ApiGatewayV2JsonHandler { } if (i.getConnectionType() != null) node.put("ConnectionType", i.getConnectionType()); if (i.getConnectionId() != null) node.put("ConnectionId", i.getConnectionId()); + if (i.getTlsConfig() != null) { + ObjectNode tlsConfig = node.putObject("TlsConfig"); + if (i.getTlsConfig().getServerNameToVerify() != null) { + tlsConfig.put("ServerNameToVerify", i.getTlsConfig().getServerNameToVerify()); + } + } node.put("PayloadFormatVersion", i.getPayloadFormatVersion()); if (i.getCredentialsArn() != null) { node.put("CredentialsArn", i.getCredentialsArn()); diff --git a/src/main/java/io/floci/aws/services/apigatewayv2/ApiGatewayV2Service.java b/src/main/java/io/floci/aws/services/apigatewayv2/ApiGatewayV2Service.java index b6a0ca9162..e847897390 100644 --- a/src/main/java/io/floci/aws/services/apigatewayv2/ApiGatewayV2Service.java +++ b/src/main/java/io/floci/aws/services/apigatewayv2/ApiGatewayV2Service.java @@ -823,6 +823,7 @@ public class ApiGatewayV2Service { integration.setResponseParameters(responseParameters); integration.setConnectionId((String) request.get("connectionId")); + integration.setTlsConfig(integrationTlsConfig(request.get("tlsConfig"))); integrationStore.put(integrationKey(region, apiId, integration.getIntegrationId()), integration); return integration; @@ -854,6 +855,7 @@ public class ApiGatewayV2Service { public Integration updateIntegration(String region, String apiId, String integrationId, Map request) { Integration integration = getIntegration(region, apiId, integrationId); + Integration.TlsConfig tlsConfig = integrationTlsConfig(request.get("tlsConfig")); Map requestParameters = mergedParameters(integration.getRequestParameters(), stringParameters(request.get("requestParameters"), "RequestParameters")); Map> responseParameters = mergedResponseParameters( @@ -914,6 +916,9 @@ public class ApiGatewayV2Service { if (request.containsKey("connectionId") && request.get("connectionId") != null) { integration.setConnectionId((String) request.get("connectionId")); } + if (request.get("tlsConfig") != null) { + integration.setTlsConfig(tlsConfig); + } integrationStore.put(integrationKey(region, apiId, integrationId), integration); return integration; @@ -927,6 +932,20 @@ public class ApiGatewayV2Service { return (String) description; } + private static Integration.TlsConfig integrationTlsConfig(Object value) { + if (value == null) { + return null; + } + if (!(value instanceof Map tlsConfig)) { + throw new AwsException("BadRequestException", "TlsConfig must be an object.", 400); + } + Object serverName = tlsConfig.get("serverNameToVerify"); + if (serverName != null && !(serverName instanceof String)) { + throw new AwsException("BadRequestException", "ServerNameToVerify must be a string.", 400); + } + return new Integration.TlsConfig((String) serverName); + } + @SuppressWarnings("unchecked") private static T updatedValue(Map request, String key, T stored) { Object value = request.get(key); diff --git a/src/main/java/io/floci/aws/services/apigatewayv2/model/Integration.java b/src/main/java/io/floci/aws/services/apigatewayv2/model/Integration.java index 8b0bcd2d11..7219d6e2e1 100644 --- a/src/main/java/io/floci/aws/services/apigatewayv2/model/Integration.java +++ b/src/main/java/io/floci/aws/services/apigatewayv2/model/Integration.java @@ -23,11 +23,27 @@ public class Integration { private Map requestParameters; private Map> responseParameters; private String connectionId; + private TlsConfig tlsConfig; private String credentialsArn; public Integration() {} + @RegisterForReflection + @JsonIgnoreProperties(ignoreUnknown = true) + public static class TlsConfig { + private String serverNameToVerify; + + public TlsConfig() {} + + public TlsConfig(String serverNameToVerify) { + this.serverNameToVerify = serverNameToVerify; + } + + public String getServerNameToVerify() { return serverNameToVerify; } + public void setServerNameToVerify(String serverNameToVerify) { this.serverNameToVerify = serverNameToVerify; } + } + public String getCredentialsArn() { return credentialsArn; } public void setCredentialsArn(String credentialsArn) { this.credentialsArn = credentialsArn; } @@ -49,6 +65,7 @@ public class Integration { this.requestParameters = src.requestParameters; this.responseParameters = src.responseParameters; this.connectionId = src.connectionId; + this.tlsConfig = src.tlsConfig; } public String getIntegrationId() { return integrationId; } @@ -95,4 +112,7 @@ public class Integration { public String getConnectionId() { return connectionId; } public void setConnectionId(String connectionId) { this.connectionId = connectionId; } + + public TlsConfig getTlsConfig() { return tlsConfig; } + public void setTlsConfig(TlsConfig tlsConfig) { this.tlsConfig = tlsConfig; } } diff --git a/src/test/java/io/floci/aws/services/apigatewayv2/ApiGatewayV2VpcLinkRestTest.java b/src/test/java/io/floci/aws/services/apigatewayv2/ApiGatewayV2VpcLinkRestTest.java index 475cb470d0..dd429ab41f 100644 --- a/src/test/java/io/floci/aws/services/apigatewayv2/ApiGatewayV2VpcLinkRestTest.java +++ b/src/test/java/io/floci/aws/services/apigatewayv2/ApiGatewayV2VpcLinkRestTest.java @@ -3,6 +3,7 @@ package io.floci.aws.services.apigatewayv2; import io.floci.aws.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; import io.restassured.http.ContentType; +import io.restassured.response.Response; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; @@ -189,25 +190,26 @@ class ApiGatewayV2VpcLinkRestTest { void createIntegrationWithVpcLinkEchoesConnectionFields() { // VPC_LINK + connectionId pointing at our VpcLink + listener-ARN integrationUri: // CreateIntegration must persist + echo connectionType, connectionId, integrationUri. - integrationId = given() + Response response = given() .contentType(ContentType.JSON) .body(""" {"integrationType":"HTTP_PROXY", "integrationUri":"arn:aws:elasticloadbalancing:us-east-1:000000000000:listener/app/my-lb/abcdef0123456789/0011223344556677", "connectionType":"VPC_LINK", "connectionId":"%s", + "tlsConfig":{"serverNameToVerify":"backend.example.com"}, "payloadFormatVersion":"1.0", "integrationMethod":"ANY"} """.formatted(vpcLinkId)) - .when().post("/v2/apis/" + apiId + "/integrations") - .then() - .statusCode(201) + .when().post("/v2/apis/" + apiId + "/integrations"); + integrationId = response.then().statusCode(201).extract().path("integrationId"); + response.then() .body("integrationId", notNullValue()) .body("integrationType", equalTo("HTTP_PROXY")) .body("connectionType", equalTo("VPC_LINK")) .body("connectionId", equalTo(vpcLinkId)) - .body("integrationUri", containsString("listener/app/my-lb")) - .extract().path("integrationId"); + .body("tlsConfig.serverNameToVerify", equalTo("backend.example.com")) + .body("integrationUri", containsString("listener/app/my-lb")); } @Test @@ -218,7 +220,15 @@ class ApiGatewayV2VpcLinkRestTest { .then() .statusCode(200) .body("connectionType", equalTo("VPC_LINK")) - .body("connectionId", equalTo(vpcLinkId)); + .body("connectionId", equalTo(vpcLinkId)) + .body("tlsConfig.serverNameToVerify", equalTo("backend.example.com")); + + given() + .when().get("/v2/apis/" + apiId + "/integrations") + .then() + .statusCode(200) + .body("items.find { it.integrationId == '" + integrationId + "' }.tlsConfig.serverNameToVerify", + equalTo("backend.example.com")); } @Test @@ -235,7 +245,40 @@ class ApiGatewayV2VpcLinkRestTest { .statusCode(200) .body("integrationMethod", equalTo("GET")) .body("connectionType", equalTo("VPC_LINK")) - .body("connectionId", equalTo(vpcLinkId)); + .body("connectionId", equalTo(vpcLinkId)) + .body("tlsConfig.serverNameToVerify", equalTo("backend.example.com")); + + given() + .contentType(ContentType.JSON) + .body(""" + {"tlsConfig":{"serverNameToVerify":"updated.example.com"}} + """) + .when().patch("/v2/apis/" + apiId + "/integrations/" + integrationId) + .then() + .statusCode(200) + .body("tlsConfig.serverNameToVerify", equalTo("updated.example.com")); + + given() + .when().get("/v2/apis/" + apiId + "/integrations/" + integrationId) + .then() + .statusCode(200) + .body("tlsConfig.serverNameToVerify", equalTo("updated.example.com")); + + given() + .contentType(ContentType.JSON) + .body(""" + {"integrationMethod":"POST","tlsConfig":{"serverNameToVerify":123}} + """) + .when().patch("/v2/apis/" + apiId + "/integrations/" + integrationId) + .then() + .statusCode(400); + + given() + .when().get("/v2/apis/" + apiId + "/integrations/" + integrationId) + .then() + .statusCode(200) + .body("integrationMethod", equalTo("GET")) + .body("tlsConfig.serverNameToVerify", equalTo("updated.example.com")); } @Test @@ -258,18 +301,19 @@ class ApiGatewayV2VpcLinkRestTest { .then().statusCode(201) .extract().path("ApiId"); - String localIntegrationId = given() + Response response = given() .contentType(amzJson) .header("X-Amz-Target", targetPrefix + "CreateIntegration") .header("Authorization", authHeader) .body(""" - {"ApiId":"%s","IntegrationType":"HTTP_PROXY","IntegrationUri":"https://example.com","IntegrationMethod":"GET","ConnectionType":"VPC_LINK","ConnectionId":"%s","PayloadFormatVersion":"1.0"} + {"ApiId":"%s","IntegrationType":"HTTP_PROXY","IntegrationUri":"https://example.com","IntegrationMethod":"GET","ConnectionType":"VPC_LINK","ConnectionId":"%s","PayloadFormatVersion":"1.0","TlsConfig":{"ServerNameToVerify":"json.example.com"}} """.formatted(localApiId, vpcLinkId)) - .when().post("/") - .then().statusCode(201) + .when().post("/"); + String localIntegrationId = response.then().statusCode(201).extract().path("IntegrationId"); + response.then() .body("ConnectionType", equalTo("VPC_LINK")) .body("ConnectionId", equalTo(vpcLinkId)) - .extract().path("IntegrationId"); + .body("TlsConfig.ServerNameToVerify", equalTo("json.example.com")); given() .contentType(amzJson) @@ -280,7 +324,8 @@ class ApiGatewayV2VpcLinkRestTest { """.formatted(localApiId, localIntegrationId)) .when().post("/") .then().statusCode(200) - .body("ConnectionId", equalTo(vpcLinkId)); + .body("ConnectionId", equalTo(vpcLinkId)) + .body("TlsConfig.ServerNameToVerify", equalTo("json.example.com")); // cleanup the locally-scoped api so it doesn't leak into the next test given().when().delete("/v2/apis/" + localApiId).then().statusCode(anyOf(equalTo(204), equalTo(404)));