feat(http): SslContextBuilder supports system/trust-all/trust-paths modes

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-19 15:54:15 +02:00
parent 2224f7d902
commit 262ee91684
3 changed files with 153 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
package com.cameleer.server.app.http;
import com.cameleer.server.core.http.OutboundHttpProperties;
import com.cameleer.server.core.http.OutboundHttpRequestContext;
import com.cameleer.server.core.http.TrustMode;
import org.junit.jupiter.api.Test;
import javax.net.ssl.SSLContext;
import java.nio.file.Path;
import java.time.Duration;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
class SslContextBuilderTest {
private final OutboundHttpProperties systemProps =
new OutboundHttpProperties(false, List.of(), Duration.ofMillis(2000), Duration.ofMillis(5000),
null, null, null);
private final SslContextBuilder builder = new SslContextBuilder();
@Test
void systemDefaultUsesJdkTrustStore() throws Exception {
SSLContext ctx = builder.build(systemProps, OutboundHttpRequestContext.systemDefault());
assertThat(ctx).isNotNull();
assertThat(ctx.getProtocol()).isEqualTo("TLS");
}
@Test
void trustAllSkipsValidation() throws Exception {
SSLContext ctx = builder.build(systemProps,
new OutboundHttpRequestContext(TrustMode.TRUST_ALL, List.of(), null, null));
assertThat(ctx).isNotNull();
}
@Test
void trustPathsLoadsPemFile() throws Exception {
Path pem = Path.of("src/test/resources/test-ca.pem");
assertThat(pem).exists();
SSLContext ctx = builder.build(systemProps,
new OutboundHttpRequestContext(TrustMode.TRUST_PATHS, List.of(pem.toString()), null, null));
assertThat(ctx).isNotNull();
}
@Test
void trustPathsMissingFileThrows() {
assertThatThrownBy(() -> builder.build(systemProps,
new OutboundHttpRequestContext(TrustMode.TRUST_PATHS, List.of("/no/such/file.pem"), null, null)))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("CA file not found");
}
}

View File

@@ -0,0 +1,19 @@
-----BEGIN CERTIFICATE-----
MIIDFzCCAf+g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