This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
The following commit(s) were added to refs/heads/master by this push:
new 66eff1c04 Move the HTTP test key material into SslTestSupport
66eff1c04 is described below
commit 66eff1c048ae4eb5b594bbdddc984adeb88526ab
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Sat Nov 7 18:59:25 2026 +0100
Move the HTTP test key material into SslTestSupport
HttpTransporterTest sits at checkstyle's 2000-line limit, and HttpServer
read its key store paths from the test class. The paths, the copy of the
stores into the build directory and the client SSLContext now live in
SslTestSupport, which both the test and the server use.
---
.../aether/internal/test/util/http/HttpServer.java | 7 +-
.../test/util/http/HttpTransporterTest.java | 100 +---------------
.../internal/test/util/http/SslTestSupport.java | 133 +++++++++++++++++++++
3 files changed, 140 insertions(+), 100 deletions(-)
diff --git
a/maven-resolver-test-http/src/main/java/org/eclipse/aether/internal/test/util/http/HttpServer.java
b/maven-resolver-test-http/src/main/java/org/eclipse/aether/internal/test/util/http/HttpServer.java
index 103b1534d..0b2703925 100644
---
a/maven-resolver-test-http/src/main/java/org/eclipse/aether/internal/test/util/http/HttpServer.java
+++
b/maven-resolver-test-http/src/main/java/org/eclipse/aether/internal/test/util/http/HttpServer.java
@@ -292,13 +292,12 @@ public class HttpServer {
private SslContextFactory.Server createServerSslContextFactory(boolean
needClientAuth) {
SslContextFactory.Server ssl = new SslContextFactory.Server();
ssl.setSniRequired(false);
- ssl.setKeyStorePath(
-
HttpTransporterTest.SERVER_STORE_PATH.toAbsolutePath().toString());
+
ssl.setKeyStorePath(SslTestSupport.SERVER_STORE_PATH.toAbsolutePath().toString());
ssl.setKeyStorePassword("server-pwd");
ssl.setNeedClientAuth(needClientAuth);
if (needClientAuth) {
ssl.setTrustStorePath(
-
HttpTransporterTest.CLIENT_STORE_PATH.toAbsolutePath().toString());
+
SslTestSupport.CLIENT_STORE_PATH.toAbsolutePath().toString());
ssl.setTrustStorePassword("client-pwd");
}
return ssl;
@@ -311,7 +310,7 @@ public class HttpServer {
public HttpServer addHttp3Connector(boolean needClientAuth, int port) {
if (http3Connector == null) {
QuicheServerQuicConfiguration serverQuicConfig =
HTTP3ServerQuicConfiguration.configure(
- new
QuicheServerQuicConfiguration(HttpTransporterTest.PEM_QUICHE_SERVER_PATH));
+ new
QuicheServerQuicConfiguration(SslTestSupport.PEM_QUICHE_SERVER_PATH));
http3Connector = new QuicheServerConnector(
server,
createServerSslContextFactory(needClientAuth),
diff --git
a/maven-resolver-test-http/src/main/java/org/eclipse/aether/internal/test/util/http/HttpTransporterTest.java
b/maven-resolver-test-http/src/main/java/org/eclipse/aether/internal/test/util/http/HttpTransporterTest.java
index 20d480dbc..5ea7ce3d4 100644
---
a/maven-resolver-test-http/src/main/java/org/eclipse/aether/internal/test/util/http/HttpTransporterTest.java
+++
b/maven-resolver-test-http/src/main/java/org/eclipse/aether/internal/test/util/http/HttpTransporterTest.java
@@ -18,26 +18,18 @@
*/
package org.eclipse.aether.internal.test.util.http;
-import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManagerFactory;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.io.UncheckedIOException;
import java.net.ServerSocket;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.StandardCopyOption;
-import java.security.KeyStore;
import java.security.NoSuchAlgorithmException;
import java.time.Duration;
-import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -104,10 +96,6 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue;
@TestMethodOrder(MethodOrderer.MethodName.class)
public abstract class HttpTransporterTest {
- protected static final Path SERVER_STORE_PATH =
Paths.get("target/server-store");
- protected static final Path CLIENT_STORE_PATH =
Paths.get("target/client-store");
- protected static final Path PEM_QUICHE_SERVER_PATH =
Paths.get("target/pems");
-
protected static SSLContext defaultSslContext;
static {
@@ -117,23 +105,11 @@ public abstract class HttpTransporterTest {
@BeforeAll
protected static void beforeAll() throws NoSuchAlgorithmException {
- // populate custom keystore and truststore
- try {
- try (InputStream keyStoreStream =
-
HttpTransporterTest.class.getClassLoader().getResourceAsStream("ssl/server-store");
- InputStream trustStoreStream =
-
HttpTransporterTest.class.getClassLoader().getResourceAsStream("ssl/client-store");
) {
- Files.copy(keyStoreStream, SERVER_STORE_PATH,
StandardCopyOption.REPLACE_EXISTING);
- Files.copy(trustStoreStream, CLIENT_STORE_PATH,
StandardCopyOption.REPLACE_EXISTING);
- Files.createDirectories(PEM_QUICHE_SERVER_PATH);
- }
- } catch (IOException e) {
- throw new UncheckedIOException(e);
- }
+ SslTestSupport.installKeyStores();
// override default SSLContext to include our custom keystore and
truststore (which are "cross connected" with
// HttpServer)
defaultSslContext = SSLContext.getDefault();
- SSLContext.setDefault(createClientSSLContext());
+ SSLContext.setDefault(SslTestSupport.createClientSSLContext());
}
@AfterAll
@@ -143,74 +119,6 @@ public abstract class HttpTransporterTest {
}
}
- /**
- * Creates an {@link SSLContext} for the client that extends the default
keystore and truststore with the entries
- * from {@link #SERVER_STORE_PATH} (password {@code "server-pwd"}) and
{@link #CLIENT_STORE_PATH}
- * (password {@code "client-pwd"}).
- *
- * @return an {@link SSLContext} combining default and custom key/trust
material
- */
- protected static SSLContext createClientSSLContext() {
- try {
- // Load custom key store (KEY_STORE_PATH acts as truststore in
"cross connected" setup)
- KeyStore customTrustStore = KeyStore.getInstance("pkcs12");
- try (InputStream is = Files.newInputStream(SERVER_STORE_PATH)) {
- customTrustStore.load(is, "server-pwd".toCharArray());
- }
-
- // Load custom trust store (TRUST_STORE_PATH acts as keystore in
"cross connected" setup)
- KeyStore customKeyStore = KeyStore.getInstance("pkcs12");
- try (InputStream is = Files.newInputStream(CLIENT_STORE_PATH)) {
- customKeyStore.load(is, "client-pwd".toCharArray());
- }
-
- // Load default truststore and merge custom entries
- KeyStore defaultTrustStore =
KeyStore.getInstance(KeyStore.getDefaultType());
- Path defaultTrustStorePath =
Path.of(System.getProperty("java.home"), "lib", "security", "cacerts");
- if (Files.exists(defaultTrustStorePath)) {
- try (InputStream is =
Files.newInputStream(defaultTrustStorePath)) {
- defaultTrustStore.load(is, "changeit".toCharArray());
- }
- } else {
- defaultTrustStore.load(null, null);
- }
- Enumeration<String> aliases = customTrustStore.aliases();
- while (aliases.hasMoreElements()) {
- String alias = aliases.nextElement();
- defaultTrustStore.setCertificateEntry("custom-trust-" + alias,
customTrustStore.getCertificate(alias));
- }
-
- // Load default keystore and merge custom entries
- KeyStore mergedKeyStore =
KeyStore.getInstance(KeyStore.getDefaultType());
- mergedKeyStore.load(null, null);
- Enumeration<String> keyAliases = customKeyStore.aliases();
- while (keyAliases.hasMoreElements()) {
- String alias = keyAliases.nextElement();
- if (customKeyStore.isKeyEntry(alias)) {
- mergedKeyStore.setKeyEntry(
- alias,
- customKeyStore.getKey(alias,
"client-pwd".toCharArray()),
- "client-pwd".toCharArray(),
- customKeyStore.getCertificateChain(alias));
- } else {
- mergedKeyStore.setCertificateEntry(alias,
customKeyStore.getCertificate(alias));
- }
- }
-
- TrustManagerFactory tmf =
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
- tmf.init(defaultTrustStore);
-
- KeyManagerFactory kmf =
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
- kmf.init(mergedKeyStore, "client-pwd".toCharArray());
-
- SSLContext sslContext = SSLContext.getInstance("TLS");
- sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(),
null);
- return sslContext;
- } catch (Exception e) {
- throw new RuntimeException("Failed to create SSLContext", e);
- }
- }
-
private final Supplier<HttpTransporterFactory> transporterFactorySupplier;
protected DefaultRepositorySystemSession session;
@@ -979,7 +887,7 @@ public abstract class HttpTransporterTest {
assertEquals(task.getDataString(),
listener.getBaos().toString(StandardCharsets.UTF_8));
} finally {
// restore the default SSL context used for all other tests
- SSLContext.setDefault(createClientSSLContext());
+ SSLContext.setDefault(SslTestSupport.createClientSSLContext());
}
}
@@ -1009,7 +917,7 @@ public abstract class HttpTransporterTest {
});
} finally {
// restore the default SSL context used for all other tests
- SSLContext.setDefault(createClientSSLContext());
+ SSLContext.setDefault(SslTestSupport.createClientSSLContext());
}
}
diff --git
a/maven-resolver-test-http/src/main/java/org/eclipse/aether/internal/test/util/http/SslTestSupport.java
b/maven-resolver-test-http/src/main/java/org/eclipse/aether/internal/test/util/http/SslTestSupport.java
new file mode 100644
index 000000000..adab1a59c
--- /dev/null
+++
b/maven-resolver-test-http/src/main/java/org/eclipse/aether/internal/test/util/http/SslTestSupport.java
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eclipse.aether.internal.test.util.http;
+
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManagerFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.security.KeyStore;
+import java.util.Enumeration;
+
+/**
+ * Key and trust material shared by {@link HttpTransporterTest} and {@link
HttpServer}: the stores are copied from the
+ * test resources into the build directory, where the server reads them, and
the client side gets an
+ * {@link SSLContext} that trusts them.
+ */
+public final class SslTestSupport {
+ public static final Path SERVER_STORE_PATH =
Paths.get("target/server-store");
+ public static final Path CLIENT_STORE_PATH =
Paths.get("target/client-store");
+ public static final Path PEM_QUICHE_SERVER_PATH = Paths.get("target/pems");
+
+ private SslTestSupport() {}
+
+ /**
+ * Copies the server and client stores from the test resources to {@link
#SERVER_STORE_PATH} and
+ * {@link #CLIENT_STORE_PATH}, and creates {@link #PEM_QUICHE_SERVER_PATH}.
+ */
+ public static void installKeyStores() {
+ try {
+ try (InputStream keyStoreStream =
+
SslTestSupport.class.getClassLoader().getResourceAsStream("ssl/server-store");
+ InputStream trustStoreStream =
+
SslTestSupport.class.getClassLoader().getResourceAsStream("ssl/client-store");
) {
+ Files.copy(keyStoreStream, SERVER_STORE_PATH,
StandardCopyOption.REPLACE_EXISTING);
+ Files.copy(trustStoreStream, CLIENT_STORE_PATH,
StandardCopyOption.REPLACE_EXISTING);
+ Files.createDirectories(PEM_QUICHE_SERVER_PATH);
+ }
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
+ /**
+ * Creates an {@link SSLContext} for the client that extends the default
keystore and truststore with the entries
+ * from {@link #SERVER_STORE_PATH} (password {@code "server-pwd"}) and
{@link #CLIENT_STORE_PATH}
+ * (password {@code "client-pwd"}).
+ *
+ * @return an {@link SSLContext} combining default and custom key/trust
material
+ */
+ public static SSLContext createClientSSLContext() {
+ try {
+ // Load custom key store (KEY_STORE_PATH acts as truststore in
"cross connected" setup)
+ KeyStore customTrustStore = KeyStore.getInstance("pkcs12");
+ try (InputStream is = Files.newInputStream(SERVER_STORE_PATH)) {
+ customTrustStore.load(is, "server-pwd".toCharArray());
+ }
+
+ // Load custom trust store (TRUST_STORE_PATH acts as keystore in
"cross connected" setup)
+ KeyStore customKeyStore = KeyStore.getInstance("pkcs12");
+ try (InputStream is = Files.newInputStream(CLIENT_STORE_PATH)) {
+ customKeyStore.load(is, "client-pwd".toCharArray());
+ }
+
+ // Load default truststore and merge custom entries
+ KeyStore defaultTrustStore =
KeyStore.getInstance(KeyStore.getDefaultType());
+ Path defaultTrustStorePath =
Path.of(System.getProperty("java.home"), "lib", "security", "cacerts");
+ if (Files.exists(defaultTrustStorePath)) {
+ try (InputStream is =
Files.newInputStream(defaultTrustStorePath)) {
+ defaultTrustStore.load(is, "changeit".toCharArray());
+ }
+ } else {
+ defaultTrustStore.load(null, null);
+ }
+ Enumeration<String> aliases = customTrustStore.aliases();
+ while (aliases.hasMoreElements()) {
+ String alias = aliases.nextElement();
+ defaultTrustStore.setCertificateEntry("custom-trust-" + alias,
customTrustStore.getCertificate(alias));
+ }
+
+ // Load default keystore and merge custom entries
+ KeyStore mergedKeyStore =
KeyStore.getInstance(KeyStore.getDefaultType());
+ mergedKeyStore.load(null, null);
+ Enumeration<String> keyAliases = customKeyStore.aliases();
+ while (keyAliases.hasMoreElements()) {
+ String alias = keyAliases.nextElement();
+ if (customKeyStore.isKeyEntry(alias)) {
+ mergedKeyStore.setKeyEntry(
+ alias,
+ customKeyStore.getKey(alias,
"client-pwd".toCharArray()),
+ "client-pwd".toCharArray(),
+ customKeyStore.getCertificateChain(alias));
+ } else {
+ mergedKeyStore.setCertificateEntry(alias,
customKeyStore.getCertificate(alias));
+ }
+ }
+
+ TrustManagerFactory tmf =
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+ tmf.init(defaultTrustStore);
+
+ KeyManagerFactory kmf =
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+ kmf.init(mergedKeyStore, "client-pwd".toCharArray());
+
+ SSLContext sslContext = SSLContext.getInstance("TLS");
+ sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(),
null);
+ return sslContext;
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to create SSLContext", e);
+ }
+ }
+}