refactor: share the extra-CA client and test config setup (#8629)

ContainerCaBundle.httpClientBuilder(sslContext) gives the HttpClient builder that trusts Floci's outbound context, or the JVM's default trust when there is none, with hostname verification left on. EventBridge API destinations, SNS HTTP and HTTPS delivery, the API Gateway HTTP proxy and WebSocket integrations start from it and keep their own settings.

The extra-CA trust tests share ExtraCaConfigs for their stubbed TLS config, and ApiGatewayExecuteController.proxyOptions names HttpProxyInvoker.ProxyOptions without its package. No behaviour change.
This commit is contained in:
Saim Zaib authored and GitHub committed 2026-11-16 14:47:28 -04:00
1 parent 8ad3e2b419
commit f3116c8b8d
12 files changed
+74 -69

No files matched your search

@@ -12,6 +12,7 @@ import javax.net.ssl.X509TrustManager;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringReader;
import java.net.http.HttpClient;
import java.nio.charset.StandardCharsets;
import java.nio.file.AtomicMoveNotSupportedException;
import java.nio.file.Files;
@@ -269,6 +270,20 @@ public final class ContainerCaBundle {
}
}
/**
* An {@link HttpClient} builder for Floci's own outbound HTTPS that trusts {@code sslContext}, the
* context {@link #sslContext(EmulatorConfig)} gives: the extra CAs in {@code floci.tls.extra-ca-path},
* and Floci's CA when TLS is on, added to the JVM's roots. A null {@code sslContext} keeps the JVM's
* default trust. Only the context is set, so hostname verification stays on.
*/
public static HttpClient.Builder httpClientBuilder(SSLContext sslContext) {
HttpClient.Builder builder = HttpClient.newBuilder();
if (sslContext != null) {
builder.sslContext(sslContext);
}
return builder;
}
/** The {@code floci.tls.extra-ca-path} file, when one is set; a blank value counts as unset. */
static Optional<Path> extraCaFile(EmulatorConfig config) {
return config.tls().extraCaPath().filter(path -> !path.isBlank()).map(Path::of);
@@ -3076,13 +3076,12 @@ public class ApiGatewayExecuteController {
}
/** REST integrations default to AWS's 29s and may opt out of backend TLS verification. */
private static io.floci.aws.services.apigatewayv2.proxy.HttpProxyInvoker.ProxyOptions
proxyOptions(Integration integration) {
private static HttpProxyInvoker.ProxyOptions proxyOptions(Integration integration) {
long timeoutMillis = integration.getTimeoutInMillis() != null
? integration.getTimeoutInMillis() : 29_000L;
boolean insecure = integration.getTlsConfig() != null
&& integration.getTlsConfig().isInsecureSkipVerification();
return new io.floci.aws.services.apigatewayv2.proxy.HttpProxyInvoker.ProxyOptions(
return new HttpProxyInvoker.ProxyOptions(
java.time.Duration.ofMillis(timeoutMillis), insecure);
}
@@ -296,18 +296,13 @@ public class HttpProxyInvoker {
// Pin to HTTP/1.1: the default HTTP_2 setting attempts cleartext-HTTP/2 negotiation
// against http:// backends, which hangs against plain HTTP/1.1 servers (notably the
// in-JVM Vertx HttpServer used by ELBv2 listeners for HttpAlbIntegration). sslContext,
// when given, adds the extra CAs in floci.tls.extra-ca-path, and Floci's CA when TLS is
// on, to the JVM's roots.
// in-JVM Vertx HttpServer used by ELBv2 listeners for HttpAlbIntegration).
private static HttpClient proxyClient(SSLContext sslContext) {
HttpClient.Builder builder = HttpClient.newBuilder()
return ContainerCaBundle.httpClientBuilder(sslContext)
.version(HttpClient.Version.HTTP_1_1)
.connectTimeout(Duration.ofSeconds(10))
.followRedirects(HttpClient.Redirect.NEVER);
if (sslContext != null) {
builder.sslContext(sslContext);
}
return builder.build();
.followRedirects(HttpClient.Redirect.NEVER)
.build();
}
public ProxyResult invoke(Integration integration, RequestContext ctx) {
@@ -87,21 +87,10 @@ public class WebSocketIntegrationInvoker {
this.serviceRouter = serviceRouter;
this.objectMapper = objectMapper;
this.vtlEngine = vtlEngine;
this.httpClient = backendClient(sslContext);
this.httpClient = ContainerCaBundle.httpClientBuilder(sslContext).build();
this.addressResolver = addressResolver;
}
// The client HTTP and HTTP_PROXY integrations reach https:// backends with. sslContext, when
// given, adds the extra CAs in floci.tls.extra-ca-path, and Floci's CA when TLS is on, to the
// JVM's roots.
private static HttpClient backendClient(SSLContext sslContext) {
HttpClient.Builder builder = HttpClient.newBuilder();
if (sslContext != null) {
builder.sslContext(sslContext);
}
return builder.build();
}
@FunctionalInterface
interface AddressResolver {
InetAddress[] resolve(String host) throws IOException;
@@ -127,14 +127,8 @@ public class EventBridgeInvoker {
serviceRegistry, regionResolver, objectMapper, config, appSyncTargetInvoker);
}
// The client API destinations are delivered with: sslContext, when given, adds the extra CAs in
// floci.tls.extra-ca-path, and Floci's CA when TLS is on, to the JVM's roots
private static HttpClient apiDestinationClient(SSLContext sslContext) {
HttpClient.Builder builder = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5));
if (sslContext != null) {
builder.sslContext(sslContext);
}
return builder.build();
return ContainerCaBundle.httpClientBuilder(sslContext).connectTimeout(Duration.ofSeconds(5)).build();
}
public EventBridgeInvoker(LambdaService lambdaService,
@@ -373,16 +373,12 @@ public class SnsService implements Resettable, ResourceProvider {
}
// The client HTTP and HTTPS subscriptions are posted to. Pin to HTTP/1.1 like AWS SNS: the default
// HTTP_2 sends an h2c upgrade to http:// endpoints. sslContext, when given, adds the extra CAs in
// floci.tls.extra-ca-path, and Floci's CA when TLS is on, to the JVM's roots
// HTTP_2 sends an h2c upgrade to http:// endpoints.
private static HttpClient deliveryClient(SSLContext sslContext) {
HttpClient.Builder builder = HttpClient.newBuilder()
return ContainerCaBundle.httpClientBuilder(sslContext)
.version(HttpClient.Version.HTTP_1_1)
.connectTimeout(Duration.ofSeconds(5));
if (sslContext != null) {
builder.sslContext(sslContext);
}
return builder.build();
.connectTimeout(Duration.ofSeconds(5))
.build();
}
public void clear() {