From 1fd80ce3a6c69e9df27a5ce38172e24e935ce4c7 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Tue, 9 Jul 2024 11:37:30 +0200 Subject: [PATCH] [MRESOLVER-579] The TODO part Adds tests, as with new test: * JDK transport fails as user explained * Jetty behaves * Apache is not HTTP2 capable --- https://issues.apache.org/jira/browse/MRESOLVER-579 --- .../internal/test/util/http/HttpServer.java | 23 ++++++++++++++----- .../test/util/http/HttpTransporterTest.java | 21 ++++++++++++++++- .../apache/ApacheTransporterTest.java | 6 +++++ .../aether/transport/jdk/JdkTransporter.java | 2 +- 4 files changed, 44 insertions(+), 8 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 919f33951..a892c45ad 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 @@ -147,14 +147,18 @@ public String getHttpsUrl() { } public HttpServer addSslConnector() { - return addSslConnector(true); + return addSslConnector(true, true); } public HttpServer addSelfSignedSslConnector() { - return addSslConnector(false); + return addSslConnector(false, true); } - private HttpServer addSslConnector(boolean needClientAuth) { + public HttpServer addSelfSignedSslConnectorHttp2Only() { + return addSslConnector(false, false); + } + + private HttpServer addSslConnector(boolean needClientAuth, boolean needHttp11) { if (httpsConnector == null) { SslContextFactory.Server ssl = new SslContextFactory.Server(); ssl.setNeedClientAuth(needClientAuth); @@ -179,15 +183,22 @@ private HttpServer addSslConnector(boolean needClientAuth) { customizer.setSniHostCheck(false); httpsConfig.addCustomizer(customizer); - HttpConnectionFactory http1 = new HttpConnectionFactory(httpsConfig); + HttpConnectionFactory http1 = null; + if (needHttp11) { + http1 = new HttpConnectionFactory(httpsConfig); + } HTTP2ServerConnectionFactory http2 = new HTTP2ServerConnectionFactory(httpsConfig); ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory(); - alpn.setDefaultProtocol(http1.getProtocol()); + alpn.setDefaultProtocol(http1 != null ? http1.getProtocol() : http2.getProtocol()); SslConnectionFactory tls = new SslConnectionFactory(ssl, alpn.getProtocol()); - httpsConnector = new ServerConnector(server, tls, alpn, http2, http1); + if (http1 != null) { + httpsConnector = new ServerConnector(server, tls, alpn, http2, http1); + } else { + httpsConnector = new ServerConnector(server, tls, alpn, http2); + } server.addConnector(httpsConnector); try { httpsConnector.start(); 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 8b484d1a2..6dff32f7d 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 @@ -512,7 +512,7 @@ protected void testGet_HTTPS_Unknown_SecurityMode() throws Exception { @Test protected void testGet_HTTPS_Insecure_SecurityMode() throws Exception { - // here we use alternate server-store-selfigned key (as the key set it static initalizer is probably already + // here we use alternate server-store-selfigned key (as the key set it static initializer is probably already // used to init SSLContext/SSLSocketFactory/etc session.setConfigProperty( ConfigurationProperties.HTTPS_SECURITY_MODE, ConfigurationProperties.HTTPS_SECURITY_MODE_INSECURE); @@ -529,6 +529,25 @@ protected void testGet_HTTPS_Insecure_SecurityMode() throws Exception { assertEquals(task.getDataString(), listener.getBaos().toString(StandardCharsets.UTF_8)); } + @Test + protected void testGet_HTTPS_HTTP2Only_Insecure_SecurityMode() throws Exception { + // here we use alternate server-store-selfigned key (as the key set it static initializer is probably already + // used to init SSLContext/SSLSocketFactory/etc + session.setConfigProperty( + ConfigurationProperties.HTTPS_SECURITY_MODE, ConfigurationProperties.HTTPS_SECURITY_MODE_INSECURE); + httpServer.addSelfSignedSslConnectorHttp2Only(); + newTransporter(httpServer.getHttpsUrl()); + RecordingTransportListener listener = new RecordingTransportListener(); + GetTask task = new GetTask(URI.create("repo/file.txt")).setListener(listener); + transporter.get(task); + assertEquals("test", task.getDataString()); + assertEquals(0L, listener.getDataOffset()); + assertEquals(4L, listener.getDataLength()); + assertEquals(1, listener.getStartedCount()); + assertTrue(listener.getProgressedCount() > 0, "Count: " + listener.getProgressedCount()); + assertEquals(task.getDataString(), listener.getBaos().toString(StandardCharsets.UTF_8)); + } + @Test protected void testGet_Redirect() throws Exception { httpServer.addSslConnector(); diff --git a/maven-resolver-transport-apache/src/test/java/org/eclipse/aether/transport/apache/ApacheTransporterTest.java b/maven-resolver-transport-apache/src/test/java/org/eclipse/aether/transport/apache/ApacheTransporterTest.java index f468e42ab..bc7980c52 100644 --- a/maven-resolver-transport-apache/src/test/java/org/eclipse/aether/transport/apache/ApacheTransporterTest.java +++ b/maven-resolver-transport-apache/src/test/java/org/eclipse/aether/transport/apache/ApacheTransporterTest.java @@ -32,6 +32,7 @@ import org.eclipse.aether.internal.test.util.http.RecordingTransportListener; import org.eclipse.aether.spi.connector.transport.GetTask; import org.eclipse.aether.spi.connector.transport.PutTask; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -46,6 +47,11 @@ public ApacheTransporterTest() { super(() -> new ApacheTransporterFactory(standardChecksumExtractor(), new TestPathProcessor())); } + @Override + @Disabled + @Test + protected void testGet_HTTPS_HTTP2Only_Insecure_SecurityMode() throws Exception {} + @Test void testGet_WebDav() throws Exception { httpServer.setWebDav(true); diff --git a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkTransporter.java b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkTransporter.java index 6287ff6c1..780f182d2 100644 --- a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkTransporter.java +++ b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkTransporter.java @@ -488,7 +488,7 @@ public X509Certificate[] getAcceptedIssuers() { .sslContext(sslContext); if (insecure) { - SSLParameters sslParameters = new SSLParameters(); + SSLParameters sslParameters = sslContext.getDefaultSSLParameters(); sslParameters.setEndpointIdentificationAlgorithm(null); builder.sslParameters(sslParameters); }