You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2023/11/28 10:25:38 UTC

(httpcomponents-client) branch 5.2.x updated: Classic test suits to execute in plain and TLS modes

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch 5.2.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


The following commit(s) were added to refs/heads/5.2.x by this push:
     new fbf526af0 Classic test suits to execute in plain and TLS modes
fbf526af0 is described below

commit fbf526af0448cd4014d1351f565efaf3f6730db2
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Tue Nov 28 10:48:51 2023 +0100

    Classic test suits to execute in plain and TLS modes
---
 .../client5/testing/sync/HttpIntegrationTests.java | 115 +++++++++++++++++++++
 .../testing/sync/HttpMinimalIntegrationTests.java  |  55 ++++++++++
 .../testing/sync/TestClientAuthentication.java     |  16 ++-
 .../sync/TestClientAuthenticationFakeNTLM.java     |   4 +-
 .../testing/sync/TestClientRequestExecution.java   |  16 ++-
 .../testing/sync/TestConnectionManagement.java     |   2 +-
 .../client5/testing/sync/TestContentCodings.java   |  16 ++-
 .../sync/TestMinimalClientRequestExecution.java    |  11 +-
 .../hc/client5/testing/sync/TestRedirects.java     |  16 ++-
 .../sync/extension/TestClientResources.java        |  13 ++-
 10 files changed, 240 insertions(+), 24 deletions(-)

diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/HttpIntegrationTests.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/HttpIntegrationTests.java
new file mode 100644
index 000000000..639b0c063
--- /dev/null
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/HttpIntegrationTests.java
@@ -0,0 +1,115 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.client5.testing.sync;
+
+import org.apache.hc.core5.http.URIScheme;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Nested;
+
+public class HttpIntegrationTests {
+
+    @Nested
+    @DisplayName("Request execution (HTTP/1.1)")
+    public class RequestExecution extends TestClientRequestExecution {
+
+        public RequestExecution() throws Exception {
+            super(URIScheme.HTTP);
+        }
+
+    }
+
+    @Nested
+    @DisplayName("Request execution (HTTP/1.1, TLS)")
+    public class RequestExecutionTls extends TestClientRequestExecution {
+
+        public RequestExecutionTls() throws Exception {
+            super(URIScheme.HTTPS);
+        }
+
+    }
+
+    @Nested
+    @DisplayName("Authentication (HTTP/1.1)")
+    public class Authentication extends TestClientAuthentication {
+
+        public Authentication() throws Exception {
+            super(URIScheme.HTTP);
+        }
+
+    }
+
+    @Nested
+    @DisplayName("Authentication (HTTP/1.1, TLS)")
+    public class AuthenticationTls extends TestClientAuthentication {
+
+        public AuthenticationTls() throws Exception {
+            super(URIScheme.HTTPS);
+        }
+
+    }
+
+    @Nested
+    @DisplayName("Content coding (HTTP/1.1)")
+    public class ContentCoding extends TestContentCodings {
+
+        public ContentCoding() throws Exception {
+            super(URIScheme.HTTP);
+        }
+
+    }
+
+    @Nested
+    @DisplayName("Content coding (HTTP/1.1, TLS)")
+    public class ContentCodingTls extends TestContentCodings {
+
+        public ContentCodingTls() throws Exception {
+            super(URIScheme.HTTPS);
+        }
+
+    }
+
+    @Nested
+    @DisplayName("Redirects (HTTP/1.1)")
+    public class Redirects extends TestRedirects {
+
+        public Redirects() throws Exception {
+            super(URIScheme.HTTP);
+        }
+
+    }
+
+    @Nested
+    @DisplayName("Redirects (HTTP/1.1, TLS)")
+    public class RedirectsTls extends TestRedirects {
+
+        public RedirectsTls() throws Exception {
+            super(URIScheme.HTTPS);
+        }
+
+    }
+
+}
\ No newline at end of file
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/HttpMinimalIntegrationTests.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/HttpMinimalIntegrationTests.java
new file mode 100644
index 000000000..6ba2fdac6
--- /dev/null
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/HttpMinimalIntegrationTests.java
@@ -0,0 +1,55 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.client5.testing.sync;
+
+import org.apache.hc.core5.http.URIScheme;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Nested;
+
+public class HttpMinimalIntegrationTests {
+
+    @Nested
+    @DisplayName("Request execution (HTTP/1.1)")
+    public class RequestExecution extends TestMinimalClientRequestExecution {
+
+        public RequestExecution() throws Exception {
+            super(URIScheme.HTTP);
+        }
+
+    }
+
+    @Nested
+    @DisplayName("Request execution (HTTP/1.1, TLS)")
+    public class RequestExecutionTls extends TestMinimalClientRequestExecution {
+
+        public RequestExecutionTls() throws Exception {
+            super(URIScheme.HTTPS);
+        }
+
+    }
+
+}
\ No newline at end of file
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientAuthentication.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientAuthentication.java
index 441d934ee..7aaa196de 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientAuthentication.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientAuthentication.java
@@ -96,12 +96,20 @@ import org.mockito.Mockito;
 /**
  * Unit tests for automatic client authentication.
  */
-public class TestClientAuthentication {
+public abstract class TestClientAuthentication {
 
     public static final Timeout TIMEOUT = Timeout.ofMinutes(1);
 
     @RegisterExtension
-    private TestClientResources testResources = new TestClientResources(URIScheme.HTTP, TIMEOUT);
+    private TestClientResources testResources;
+
+    protected TestClientAuthentication(final URIScheme scheme) {
+        this.testResources = new TestClientResources(scheme, TIMEOUT);
+    }
+
+    public URIScheme scheme() {
+        return testResources.scheme();
+    }
 
     public ClassicTestServer startServer(final Authenticator authenticator) throws IOException {
         return testResources.startServer(
@@ -114,11 +122,11 @@ public class TestClientAuthentication {
         return startServer(new BasicTestAuthenticator("test:test", "test realm"));
     }
 
-    public CloseableHttpClient startClient(final Consumer<HttpClientBuilder> clientCustomizer) {
+    public CloseableHttpClient startClient(final Consumer<HttpClientBuilder> clientCustomizer) throws Exception {
         return testResources.startClient(clientCustomizer);
     }
 
-    public CloseableHttpClient startClient() {
+    public CloseableHttpClient startClient() throws Exception {
         return testResources.startClient(builder -> {});
     }
 
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientAuthenticationFakeNTLM.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientAuthenticationFakeNTLM.java
index 4c531408b..0f17e7e40 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientAuthenticationFakeNTLM.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientAuthenticationFakeNTLM.java
@@ -68,11 +68,11 @@ public class TestClientAuthenticationFakeNTLM {
         return testResources.startServer(null, null, null);
     }
 
-    public CloseableHttpClient startClient(final Consumer<HttpClientBuilder> clientCustomizer) {
+    public CloseableHttpClient startClient(final Consumer<HttpClientBuilder> clientCustomizer) throws Exception {
         return testResources.startClient(clientCustomizer);
     }
 
-    public CloseableHttpClient startClient() {
+    public CloseableHttpClient startClient() throws Exception {
         return testResources.startClient(builder -> {});
     }
 
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientRequestExecution.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientRequestExecution.java
index 5f1fdeb2d..dce158a99 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientRequestExecution.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientRequestExecution.java
@@ -74,22 +74,30 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 /**
  * Client protocol handling tests.
  */
-public class TestClientRequestExecution {
+public abstract class TestClientRequestExecution {
 
     public static final Timeout TIMEOUT = Timeout.ofMinutes(1);
 
     @RegisterExtension
-    private TestClientResources testResources = new TestClientResources(URIScheme.HTTP, TIMEOUT);
+    private TestClientResources testResources;
+
+    protected TestClientRequestExecution(final URIScheme scheme) {
+        this.testResources = new TestClientResources(scheme, TIMEOUT);
+    }
+
+    public URIScheme scheme() {
+        return testResources.scheme();
+    }
 
     public ClassicTestServer startServer() throws IOException {
         return testResources.startServer(null, null, null);
     }
 
-    public CloseableHttpClient startClient(final Consumer<HttpClientBuilder> clientCustomizer) {
+    public CloseableHttpClient startClient(final Consumer<HttpClientBuilder> clientCustomizer) throws Exception {
         return testResources.startClient(clientCustomizer);
     }
 
-    public CloseableHttpClient startClient() {
+    public CloseableHttpClient startClient() throws Exception {
         return testResources.startClient(builder -> {});
     }
 
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestConnectionManagement.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestConnectionManagement.java
index 37f8c46d2..ff1f8d0a2 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestConnectionManagement.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestConnectionManagement.java
@@ -76,7 +76,7 @@ public class TestConnectionManagement {
         return testResources.startServer(null, null, null);
     }
 
-    public CloseableHttpClient startClient() {
+    public CloseableHttpClient startClient() throws Exception {
         return testResources.startClient(b -> {}, b -> {});
     }
 
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java
index 633670f70..6d99a84f9 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java
@@ -72,22 +72,30 @@ import org.junit.jupiter.api.extension.RegisterExtension;
  * require no intervention from the user of HttpClient, but we still want to let clients do their
  * own thing if they so wish.
  */
-public class TestContentCodings {
+public abstract class TestContentCodings {
 
     public static final Timeout TIMEOUT = Timeout.ofMinutes(1);
 
     @RegisterExtension
-    private TestClientResources testResources = new TestClientResources(URIScheme.HTTP, TIMEOUT);
+    private TestClientResources testResources;
+
+    protected TestContentCodings(final URIScheme scheme) {
+        this.testResources = new TestClientResources(scheme, TIMEOUT);
+    }
+
+    public URIScheme scheme() {
+        return testResources.scheme();
+    }
 
     public ClassicTestServer startServer() throws IOException {
         return testResources.startServer(null, null, null);
     }
 
-    public CloseableHttpClient startClient(final Consumer<HttpClientBuilder> clientCustomizer) {
+    public CloseableHttpClient startClient(final Consumer<HttpClientBuilder> clientCustomizer) throws Exception {
         return testResources.startClient(clientCustomizer);
     }
 
-    public CloseableHttpClient startClient() {
+    public CloseableHttpClient startClient() throws Exception {
         return testResources.startClient(builder -> {});
     }
 
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestMinimalClientRequestExecution.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestMinimalClientRequestExecution.java
index 47bbfb1f4..1681a4bdc 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestMinimalClientRequestExecution.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestMinimalClientRequestExecution.java
@@ -56,13 +56,20 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 /**
  * Client protocol handling tests.
  */
-public class TestMinimalClientRequestExecution {
+public abstract class TestMinimalClientRequestExecution {
 
     public static final Timeout TIMEOUT = Timeout.ofMinutes(1);
 
     @RegisterExtension
-    private TestClientResources testResources = new TestClientResources(URIScheme.HTTP, TIMEOUT);
+    private TestClientResources testResources;
 
+    protected TestMinimalClientRequestExecution(final URIScheme scheme) {
+        this.testResources = new TestClientResources(scheme, TIMEOUT);
+    }
+
+    public URIScheme scheme() {
+        return testResources.scheme();
+    }
     private static class SimpleService implements HttpRequestHandler {
 
         public SimpleService() {
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java
index 2499f4798..a881d1750 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestRedirects.java
@@ -81,23 +81,31 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 /**
  * Redirection test cases.
  */
-public class TestRedirects {
+public abstract class TestRedirects {
 
     public static final Timeout TIMEOUT = Timeout.ofMinutes(1);
 
     @RegisterExtension
-    private TestClientResources testResources = new TestClientResources(URIScheme.HTTP, TIMEOUT);
+    private TestClientResources testResources;
+
+    protected TestRedirects(final URIScheme scheme) {
+        this.testResources = new TestClientResources(scheme, TIMEOUT);
+    }
+
+    public URIScheme scheme() {
+        return testResources.scheme();
+    }
 
     public ClassicTestServer startServer(final HttpProcessor httpProcessor,
                                          final Decorator<HttpServerRequestHandler> handlerDecorator) throws IOException {
         return testResources.startServer(null, httpProcessor, handlerDecorator);
     }
 
-    public CloseableHttpClient startClient(final Consumer<HttpClientBuilder> clientCustomizer) {
+    public CloseableHttpClient startClient(final Consumer<HttpClientBuilder> clientCustomizer) throws Exception {
         return testResources.startClient(clientCustomizer);
     }
 
-    public CloseableHttpClient startClient() {
+    public CloseableHttpClient startClient() throws Exception {
         return testResources.startClient(builder -> {});
     }
 
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/extension/TestClientResources.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/extension/TestClientResources.java
index 083a5f25d..fd79bed3e 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/extension/TestClientResources.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/extension/TestClientResources.java
@@ -37,6 +37,7 @@ import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.client5.http.impl.classic.MinimalHttpClient;
 import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
 import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
+import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
 import org.apache.hc.client5.testing.SSLTestContexts;
 import org.apache.hc.core5.function.Decorator;
 import org.apache.hc.core5.http.HttpHost;
@@ -98,6 +99,10 @@ public class TestClientResources implements BeforeEachCallback, AfterEachCallbac
         }
     }
 
+    public URIScheme scheme() {
+        return this.scheme;
+    }
+
     public ClassicTestServer startServer(
             final Http1Config http1Config,
             final HttpProcessor httpProcessor,
@@ -114,11 +119,12 @@ public class TestClientResources implements BeforeEachCallback, AfterEachCallbac
 
     public CloseableHttpClient startClient(
             final Consumer<PoolingHttpClientConnectionManagerBuilder> connManagerCustomizer,
-            final Consumer<HttpClientBuilder> clientCustomizer) {
+            final Consumer<HttpClientBuilder> clientCustomizer) throws Exception {
         Assertions.assertNull(connManager);
         Assertions.assertNull(client);
 
         final PoolingHttpClientConnectionManagerBuilder connManagerBuilder = PoolingHttpClientConnectionManagerBuilder.create();
+        connManagerBuilder.setSSLSocketFactory(new SSLConnectionSocketFactory(SSLTestContexts.createClientSSLContext()));
         connManagerBuilder.setDefaultSocketConfig(SocketConfig.custom()
                 .setSoTimeout(timeout)
                 .build());
@@ -136,11 +142,12 @@ public class TestClientResources implements BeforeEachCallback, AfterEachCallbac
         return client;
     }
 
-    public MinimalHttpClient startMinimalClient() {
+    public MinimalHttpClient startMinimalClient() throws Exception {
         Assertions.assertNull(connManager);
         Assertions.assertNull(client);
 
         final PoolingHttpClientConnectionManagerBuilder connManagerBuilder = PoolingHttpClientConnectionManagerBuilder.create();
+        connManagerBuilder.setSSLSocketFactory(new SSLConnectionSocketFactory(SSLTestContexts.createClientSSLContext()));
         connManagerBuilder.setDefaultSocketConfig(SocketConfig.custom()
                 .setSoTimeout(timeout)
                 .build());
@@ -155,7 +162,7 @@ public class TestClientResources implements BeforeEachCallback, AfterEachCallbac
     }
 
     public CloseableHttpClient startClient(
-            final Consumer<HttpClientBuilder> clientCustomizer) {
+            final Consumer<HttpClientBuilder> clientCustomizer) throws Exception {
         return startClient(b -> {}, clientCustomizer);
     }