mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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:
1 parent
8ad3e2b419
commit
f3116c8b8d
12 files changed
+74
-69
No files matched your search
@@ -5,6 +5,7 @@ import io.floci.aws.core.common.Pem;
|
||||
import io.floci.aws.services.acm.CertificateGenerator;
|
||||
import io.floci.aws.services.acm.model.KeyAlgorithm;
|
||||
import io.floci.aws.services.lambda.launcher.BootstrapProcess;
|
||||
import io.floci.aws.testing.ExtraCaConfigs;
|
||||
import io.floci.aws.testing.LocalHttpsServer;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -494,9 +495,7 @@ class ContainerCaBundleTest {
|
||||
}
|
||||
|
||||
private EmulatorConfig config(boolean tlsEnabled, Optional<String> extraCaPath) {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
|
||||
when(config.tls().enabled()).thenReturn(tlsEnabled);
|
||||
when(config.tls().extraCaPath()).thenReturn(extraCaPath);
|
||||
EmulatorConfig config = ExtraCaConfigs.config(tlsEnabled, extraCaPath);
|
||||
when(config.storage().persistentPath()).thenReturn(tempDir.toString());
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.floci.aws.config;
|
||||
|
||||
import io.floci.aws.testing.ExtraCaConfigs;
|
||||
import io.quarkus.runtime.StartupEvent;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
@@ -13,9 +14,6 @@ import java.util.Optional;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* The floci.tls.extra-ca-path file is checked at startup, from whichever source sets it, with TLS on or off.
|
||||
@@ -85,9 +83,6 @@ class TlsExtraCaStartupValidatorTest {
|
||||
}
|
||||
|
||||
private static TlsExtraCaStartupValidator validator(boolean tlsEnabled, Optional<String> extraCaPath) {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
|
||||
when(config.tls().enabled()).thenReturn(tlsEnabled);
|
||||
when(config.tls().extraCaPath()).thenReturn(extraCaPath);
|
||||
return new TlsExtraCaStartupValidator(config);
|
||||
return new TlsExtraCaStartupValidator(ExtraCaConfigs.config(tlsEnabled, extraCaPath));
|
||||
}
|
||||
}
|
||||
+4
-13
@@ -2,7 +2,6 @@ package io.floci.aws.services.apigatewayv2;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.sun.net.httpserver.HttpsServer;
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.config.FlociCertificateAuthority;
|
||||
import io.floci.aws.services.apigateway.AwsServiceRouter;
|
||||
import io.floci.aws.services.apigateway.VtlTemplateEngine;
|
||||
@@ -14,6 +13,7 @@ import io.floci.aws.services.apigatewayv2.proxy.RequestContext;
|
||||
import io.floci.aws.services.apigatewayv2.websocket.WebSocketIntegrationInvoker;
|
||||
import io.floci.aws.services.apigatewayv2.websocket.WebSocketIntegrationInvoker.IntegrationResult;
|
||||
import io.floci.aws.services.lambda.LambdaService;
|
||||
import io.floci.aws.testing.ExtraCaConfigs;
|
||||
import io.floci.aws.testing.LocalHttpsServer;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -32,9 +32,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import static io.floci.aws.testing.LocalHttpsServer.hookUrl;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* HTTP and HTTP_PROXY integrations reach an https:// backend through Floci's outbound trust, so a certificate from
|
||||
@@ -128,13 +126,14 @@ class ApiGatewayHttpsBackendTrustTest {
|
||||
integration.setIntegrationMethod("GET");
|
||||
RequestContext ctx = new RequestContext("api1", "$default", "GET", "/hook", null, "GET /hook",
|
||||
"req-test", "127.0.0.1", Map.of(), Map.of(), Map.of(), null, Map.of(), Map.of());
|
||||
return new HttpProxyInvoker(config(extraCaPath)).invoke(integration, ctx, options);
|
||||
return new HttpProxyInvoker(ExtraCaConfigs.config(false, extraCaPath)).invoke(integration, ctx, options);
|
||||
}
|
||||
|
||||
// Calls the backend as a WebSocket integration of integrationType, through an invoker built the way CDI builds it.
|
||||
private IntegrationResult webSocket(String integrationType, Optional<String> extraCaPath) {
|
||||
WebSocketIntegrationInvoker invoker = new WebSocketIntegrationInvoker(mock(LambdaService.class),
|
||||
mock(AwsServiceRouter.class), new ObjectMapper(), mock(VtlTemplateEngine.class), config(extraCaPath));
|
||||
mock(AwsServiceRouter.class), new ObjectMapper(), mock(VtlTemplateEngine.class),
|
||||
ExtraCaConfigs.config(false, extraCaPath));
|
||||
return invoker.invoke("us-east-1", integration(integrationType), "{}", Map.of(), Map.of(), Map.of());
|
||||
}
|
||||
|
||||
@@ -145,14 +144,6 @@ class ApiGatewayHttpsBackendTrustTest {
|
||||
return integration;
|
||||
}
|
||||
|
||||
// TLS off, with extraCaPath as the extra CA setting.
|
||||
private static EmulatorConfig config(Optional<String> extraCaPath) {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
|
||||
when(config.tls().enabled()).thenReturn(false);
|
||||
when(config.tls().extraCaPath()).thenReturn(extraCaPath);
|
||||
return config;
|
||||
}
|
||||
|
||||
private Optional<String> privateCaPath() {
|
||||
return Optional.of(privateCa.certificatePath().toString());
|
||||
}
|
||||
|
||||
+2
-4
@@ -11,6 +11,7 @@ import io.floci.aws.services.eventbridge.model.Target;
|
||||
import io.floci.aws.services.lambda.LambdaService;
|
||||
import io.floci.aws.services.sns.SnsService;
|
||||
import io.floci.aws.services.sqs.SqsService;
|
||||
import io.floci.aws.testing.ExtraCaConfigs;
|
||||
import io.floci.aws.testing.LocalHttpsServer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
@@ -33,7 +34,6 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -189,9 +189,7 @@ class EventBridgeInvokerApiDestinationTest {
|
||||
|
||||
// An invoker built the way CDI builds it, its API destination pointing at endpoint, with TLS off.
|
||||
private static EventBridgeInvoker invoker(String endpoint, Optional<String> extraCaPath) {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
|
||||
when(config.tls().enabled()).thenReturn(false);
|
||||
when(config.tls().extraCaPath()).thenReturn(extraCaPath);
|
||||
EmulatorConfig config = ExtraCaConfigs.config(false, extraCaPath);
|
||||
EventBridgeService eventBridgeService = mock(EventBridgeService.class);
|
||||
when(eventBridgeService.findApiDestinationByArn(DESTINATION_ARN, REGION)).thenReturn(
|
||||
new ApiDestination("tls", DESTINATION_ARN, CONNECTION_ARN, endpoint, "POST", null, null));
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.sun.net.httpserver.HttpsServer;
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.config.FlociCertificateAuthority;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.testing.ExtraCaConfigs;
|
||||
import io.floci.aws.testing.LocalHttpsServer;
|
||||
import io.floci.aws.testing.StorageFactories;
|
||||
import io.floci.aws.testutil.LogCapture;
|
||||
@@ -99,10 +100,9 @@ class SnsHttpsSubscriptionTrustTest {
|
||||
|
||||
// A service built the way CDI builds it, with TLS off.
|
||||
private SnsService service(Optional<String> extraCaPath) {
|
||||
EmulatorConfig config = StorageFactories.config(dir.resolve("data"), ACCOUNT);
|
||||
EmulatorConfig config = ExtraCaConfigs.stub(StorageFactories.config(dir.resolve("data"), ACCOUNT), false,
|
||||
extraCaPath);
|
||||
when(config.effectiveBaseUrl()).thenReturn(BASE_URL);
|
||||
when(config.tls().enabled()).thenReturn(false);
|
||||
when(config.tls().extraCaPath()).thenReturn(extraCaPath);
|
||||
return new SnsService(StorageFactories.open(config, "memory"), config, new RegionResolver(REGION, ACCOUNT),
|
||||
null, null, null, new ObjectMapper(), SnsMessageSigner.inMemory(BASE_URL));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package io.floci.aws.testing;
|
||||
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Deep-stubbed {@link EmulatorConfig}s with the TLS settings Floci's outbound trust reads, for the extra-CA
|
||||
* trust tests.
|
||||
*/
|
||||
public final class ExtraCaConfigs {
|
||||
|
||||
private ExtraCaConfigs() {
|
||||
}
|
||||
|
||||
/**
|
||||
* A deep-stubbed config with TLS on or off as {@code tlsEnabled} says and {@code extraCaPath} as
|
||||
* {@code floci.tls.extra-ca-path}.
|
||||
*/
|
||||
public static EmulatorConfig config(boolean tlsEnabled, Optional<String> extraCaPath) {
|
||||
return stub(mock(EmulatorConfig.class, RETURNS_DEEP_STUBS), tlsEnabled, extraCaPath);
|
||||
}
|
||||
|
||||
/** {@code config}, a deep-stubbed mock such as {@link StorageFactories#config} returns, with those TLS settings. */
|
||||
public static EmulatorConfig stub(EmulatorConfig config, boolean tlsEnabled, Optional<String> extraCaPath) {
|
||||
when(config.tls().enabled()).thenReturn(tlsEnabled);
|
||||
when(config.tls().extraCaPath()).thenReturn(extraCaPath);
|
||||
return config;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user