Skip to content

Commit

Permalink
8310731: Configure a javax.net.ssl.SNIMatcher for the HTTP/1.1 test s…
Browse files Browse the repository at this point in the history
…ervers in java/net/httpclient tests

Reviewed-by: dfuchs
  • Loading branch information
jaikiran committed Jun 27, 2023
1 parent 1587836 commit 05e9c41
Show file tree
Hide file tree
Showing 19 changed files with 293 additions and 53 deletions.
5 changes: 3 additions & 2 deletions test/jdk/java/net/httpclient/AsFileDownloadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsServer;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -53,6 +52,7 @@
import jdk.test.lib.net.SimpleSSLContext;
import jdk.test.lib.util.FileUtils;
import jdk.httpclient.test.lib.common.HttpServerAdapters;
import jdk.httpclient.test.lib.common.TestServerConfigurator;
import jdk.httpclient.test.lib.http2.Http2TestServer;
import jdk.httpclient.test.lib.http2.Http2TestExchange;
import jdk.httpclient.test.lib.http2.Http2Handler;
Expand All @@ -75,6 +75,7 @@
* @library /test/lib /test/jdk/java/net/httpclient/lib
* @build jdk.httpclient.test.lib.http2.Http2TestServer jdk.test.lib.net.SimpleSSLContext
* jdk.test.lib.Platform jdk.test.lib.util.FileUtils
* jdk.httpclient.test.lib.common.TestServerConfigurator
* @run testng/othervm AsFileDownloadTest
* @run testng/othervm/java.security.policy=AsFileDownloadTest.policy AsFileDownloadTest
*/
Expand Down Expand Up @@ -322,7 +323,7 @@ public void setup() throws Exception {
httpURI = "http://" + serverAuthority(httpTestServer) + "/http1/afdt";

httpsTestServer = HttpsServer.create(sa, 0);
httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
httpsTestServer.setHttpsConfigurator(new TestServerConfigurator(sa.getAddress(), sslContext));
httpsTestServer.createContext("/https1/afdt", new Http1FileDispoHandler());
httpsURI = "https://" + serverAuthority(httpsTestServer) + "/https1/afdt";

Expand Down
5 changes: 3 additions & 2 deletions test/jdk/java/net/httpclient/AuthFilterCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsServer;
import jdk.httpclient.test.lib.common.TestServerConfigurator;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
Expand All @@ -51,7 +52,7 @@
* @summary AuthenticationFilter.Cache::remove may throw ConcurrentModificationException
* @library /test/lib /test/jdk/java/net/httpclient/lib
* @build jdk.httpclient.test.lib.common.HttpServerAdapters jdk.test.lib.net.SimpleSSLContext
* DigestEchoServer
* DigestEchoServer jdk.httpclient.test.lib.common.TestServerConfigurator
* @run testng/othervm -Dtest.requiresHost=true
* -Djdk.tracePinnedThreads=full
* -Djdk.httpclient.HttpClient.log=headers
Expand Down Expand Up @@ -133,7 +134,7 @@ public void setUp() throws Exception {
// HTTPS/1.1
HttpsServer sserver1 = HttpsServer.create(sa, 100);
sserver1.setExecutor(serverExecutor);
sserver1.setHttpsConfigurator(new HttpsConfigurator(context));
sserver1.setHttpsConfigurator(new TestServerConfigurator(sa.getAddress(), context));
https1Server = HttpTestServer.of(sserver1);
https1Server.addHandler(new TestHandler(), "/AuthFilterCacheTest/https1/");
https1Server.start();
Expand Down
6 changes: 4 additions & 2 deletions test/jdk/java/net/httpclient/ConcurrentResponses.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* unprocessed HTTP data
* @library /test/lib /test/jdk/java/net/httpclient/lib
* @build jdk.httpclient.test.lib.http2.Http2TestServer jdk.test.lib.net.SimpleSSLContext
* jdk.httpclient.test.lib.common.TestServerConfigurator
* @run testng/othervm
* -Djdk.tracePinnedThreads=full
* -Djdk.httpclient.HttpClient.log=headers,errors,channel
Expand Down Expand Up @@ -55,7 +56,6 @@
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsServer;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
Expand All @@ -64,6 +64,8 @@
import java.net.http.HttpResponse.BodyHandlers;
import java.net.http.HttpResponse.BodySubscriber;
import java.net.http.HttpResponse.BodySubscribers;

import jdk.httpclient.test.lib.common.TestServerConfigurator;
import jdk.httpclient.test.lib.http2.Http2TestServer;
import jdk.httpclient.test.lib.http2.Http2TestExchange;
import jdk.httpclient.test.lib.http2.Http2Handler;
Expand Down Expand Up @@ -291,7 +293,7 @@ public void setup() throws Exception {
httpChunkedURI = "http://" + serverAuthority(httpTestServer) + "/http1/chunked";

httpsTestServer = HttpsServer.create(sa, 0);
httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
httpsTestServer.setHttpsConfigurator(new TestServerConfigurator(sa.getAddress(), sslContext));
httpsTestServer.createContext("/https1/fixed", new Http1FixedHandler());
httpsFixedURI = "https://" + serverAuthority(httpsTestServer) + "/https1/fixed";
httpsTestServer.createContext("/https1/chunked", new Http1ChunkedHandler());
Expand Down
6 changes: 4 additions & 2 deletions test/jdk/java/net/httpclient/CustomResponseSubscriber.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* @summary Tests response body subscribers's onComplete is not invoked before onSubscribe
* @library /test/lib /test/jdk/java/net/httpclient/lib
* @build jdk.test.lib.net.SimpleSSLContext jdk.httpclient.test.lib.http2.Http2TestServer
* jdk.httpclient.test.lib.common.TestServerConfigurator
* @run testng/othervm CustomResponseSubscriber
*/

Expand All @@ -43,7 +44,6 @@
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsServer;
import java.net.http.HttpClient;
import java.net.http.HttpHeaders;
Expand All @@ -52,6 +52,8 @@
import java.net.http.HttpResponse.BodyHandler;
import java.net.http.HttpResponse.BodySubscriber;
import java.net.http.HttpResponse.BodySubscribers;

import jdk.httpclient.test.lib.common.TestServerConfigurator;
import jdk.httpclient.test.lib.http2.Http2TestServer;
import jdk.httpclient.test.lib.http2.Http2TestExchange;
import jdk.httpclient.test.lib.http2.Http2Handler;
Expand Down Expand Up @@ -200,7 +202,7 @@ public void setup() throws Exception {
httpURI_chunk = "http://" + serverAuthority(httpTestServer) + "/http1/chunk";

httpsTestServer = HttpsServer.create(sa, 0);
httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
httpsTestServer.setHttpsConfigurator(new TestServerConfigurator(sa.getAddress(), sslContext));
httpsTestServer.createContext("/https1/fixed", h1_fixedLengthHandler);
httpsTestServer.createContext("/https1/chunk", h1_chunkHandler);
httpsURI_fixed = "https://" + serverAuthority(httpsTestServer) + "/https1/fixed";
Expand Down
11 changes: 6 additions & 5 deletions test/jdk/java/net/httpclient/ExpectContinue.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@
/*
* @test
* @summary Basic test for Expect 100-Continue ( HTTP/1.1 only )
* @modules java.net.http
* @library /test/lib /test/jdk/java/net/httpclient/lib
* @build jdk.test.lib.net.SimpleSSLContext jdk.httpclient.test.lib.common.TestServerConfigurator
* @modules java.net.http/jdk.internal.net.http.common
* jdk.httpserver
* @library /test/lib
* @build jdk.test.lib.net.SimpleSSLContext
* @run testng/othervm ExpectContinue
*/

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsServer;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -49,6 +48,8 @@
import java.net.http.HttpResponse.BodyHandlers;
import java.util.List;
import javax.net.ssl.SSLContext;

import jdk.httpclient.test.lib.common.TestServerConfigurator;
import jdk.test.lib.net.SimpleSSLContext;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
Expand Down Expand Up @@ -148,7 +149,7 @@ public void setup() throws Exception {
httpURI = "http://" + serverAuthority(httpTestServer) + "/http1/ec";

httpsTestServer = HttpsServer.create(sa, 0);
httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
httpsTestServer.setHttpsConfigurator(new TestServerConfigurator(sa.getAddress(), sslContext));
httpsTestServer.createContext("/https1/ec", new Http1ExpectContinueHandler());
httpsURI = "https://" + serverAuthority(httpsTestServer) + "/https1/ec";

Expand Down
7 changes: 3 additions & 4 deletions test/jdk/java/net/httpclient/HttpRedirectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsServer;
import jdk.httpclient.test.lib.common.TestServerConfigurator;
import jdk.test.lib.net.SimpleSSLContext;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
Expand Down Expand Up @@ -60,7 +59,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import jdk.httpclient.test.lib.common.HttpServerAdapters;
import jdk.httpclient.test.lib.http2.Http2TestServer;

/**
* @test
Expand All @@ -69,6 +67,7 @@
* @library /test/lib /test/jdk/java/net/httpclient/lib
* @build jdk.test.lib.net.SimpleSSLContext DigestEchoServer HttpRedirectTest
* jdk.httpclient.test.lib.common.HttpServerAdapters
* jdk.httpclient.test.lib.common.TestServerConfigurator
* @run testng/othervm -Dtest.requiresHost=true
* -Djdk.httpclient.HttpClient.log=headers
* -Djdk.internal.httpclient.debug=false
Expand Down Expand Up @@ -175,7 +174,7 @@ public void setUp() throws Exception {
// HTTPS/1.1
HttpsServer sserver1 = HttpsServer.create(sa, 100);
sserver1.setExecutor(executor);
sserver1.setHttpsConfigurator(new HttpsConfigurator(context));
sserver1.setHttpsConfigurator(new TestServerConfigurator(sa.getAddress(), context));
https1Server = HttpTestServer.of(sserver1);
https1Server.addHandler(new HttpTestRedirectHandler("https", https1Server),
"/HttpRedirectTest/https1/");
Expand Down
7 changes: 3 additions & 4 deletions test/jdk/java/net/httpclient/HttpSlowServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsServer;
import jdk.httpclient.test.lib.common.TestServerConfigurator;
import jdk.test.lib.net.SimpleSSLContext;

import javax.net.ssl.SSLContext;
Expand Down Expand Up @@ -51,7 +50,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import jdk.httpclient.test.lib.common.HttpServerAdapters;
import jdk.httpclient.test.lib.http2.Http2TestServer;
import static java.net.http.HttpClient.Version.HTTP_1_1;
import static java.net.http.HttpClient.Version.HTTP_2;

Expand All @@ -62,6 +60,7 @@
* @library /test/lib /test/jdk/java/net/httpclient/lib
* @build jdk.httpclient.test.lib.common.HttpServerAdapters jdk.test.lib.net.SimpleSSLContext
* DigestEchoServer HttpSlowServerTest
* jdk.httpclient.test.lib.common.TestServerConfigurator
* @run main/othervm -Dtest.requiresHost=true
* -Djdk.httpclient.HttpClient.log=headers
* -Djdk.internal.httpclient.debug=false
Expand Down Expand Up @@ -138,7 +137,7 @@ public void setUp() throws Exception {
// HTTPS/1.1
HttpsServer sserver1 = HttpsServer.create(sa, 100);
sserver1.setExecutor(executor);
sserver1.setHttpsConfigurator(new HttpsConfigurator(context));
sserver1.setHttpsConfigurator(new TestServerConfigurator(sa.getAddress(), context));
https1Server = HttpTestServer.of(sserver1);
https1Server.addHandler(new HttpTestSlowHandler(), "/HttpSlowServerTest/https1/");
https1Server.start();
Expand Down
6 changes: 4 additions & 2 deletions test/jdk/java/net/httpclient/ImmutableFlowItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* and that the buffers are read-only
* @library /test/lib /test/jdk/java/net/httpclient/lib
* @build jdk.test.lib.net.SimpleSSLContext jdk.httpclient.test.lib.http2.Http2TestServer
* jdk.httpclient.test.lib.common.TestServerConfigurator
* @run testng/othervm ImmutableFlowItems
*/

Expand All @@ -43,7 +44,6 @@
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsServer;
import java.net.http.HttpClient;
import java.net.http.HttpHeaders;
Expand All @@ -53,6 +53,8 @@
import java.net.http.HttpResponse.BodySubscriber;
import java.net.http.HttpResponse.BodySubscribers;
import javax.net.ssl.SSLContext;

import jdk.httpclient.test.lib.common.TestServerConfigurator;
import jdk.httpclient.test.lib.http2.Http2TestServer;
import jdk.httpclient.test.lib.http2.Http2TestExchange;
import jdk.httpclient.test.lib.http2.Http2Handler;
Expand Down Expand Up @@ -189,7 +191,7 @@ public void setup() throws Exception {
httpURI_chunk = "http://" + serverAuthority(httpTestServer) + "/http1/chunk";

httpsTestServer = HttpsServer.create(sa, 0);
httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
httpsTestServer.setHttpsConfigurator(new TestServerConfigurator(sa.getAddress(), sslContext));
httpsTestServer.createContext("/https1/fixed", h1_fixedLengthHandler);
httpsTestServer.createContext("/https1/chunk", h1_chunkHandler);
httpsURI_fixed = "https://" + serverAuthority(httpsTestServer) + "/https1/fixed";
Expand Down
7 changes: 3 additions & 4 deletions test/jdk/java/net/httpclient/LargeHandshakeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsServer;

import javax.net.ssl.KeyManagerFactory;
Expand Down Expand Up @@ -61,7 +59,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import jdk.httpclient.test.lib.common.HttpServerAdapters;
import jdk.httpclient.test.lib.http2.Http2TestServer;
import jdk.httpclient.test.lib.common.TestServerConfigurator;
import static java.net.http.HttpClient.Version.HTTP_1_1;
import static java.net.http.HttpClient.Version.HTTP_2;

Expand All @@ -82,6 +80,7 @@
* @library /test/lib /test/jdk/java/net/httpclient/lib
* @build jdk.httpclient.test.lib.common.HttpServerAdapters jdk.test.lib.net.SimpleSSLContext
* DigestEchoServer
* jdk.httpclient.test.lib.common.TestServerConfigurator
* @run main/othervm -Dtest.requiresHost=true
* -Djdk.httpclient.HttpClient.log=headers
* -Djdk.internal.httpclient.debug=true
Expand Down Expand Up @@ -1011,7 +1010,7 @@ public void setUp() throws Exception {
// HTTPS/1.1
HttpsServer sserver1 = HttpsServer.create(sa, 100);
sserver1.setExecutor(executor);
sserver1.setHttpsConfigurator(new HttpsConfigurator(context));
sserver1.setHttpsConfigurator(new TestServerConfigurator(sa.getAddress(), context));
https1Server = HttpTestServer.of(sserver1);
https1Server.addHandler(new HttpTestLargeHandler(), "/LargeHandshakeTest/https1/");
https1Server.start();
Expand Down
8 changes: 3 additions & 5 deletions test/jdk/java/net/httpclient/LargeResponseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsServer;
import jdk.httpclient.test.lib.common.TestServerConfigurator;
import jdk.test.lib.net.SimpleSSLContext;

import javax.net.ssl.SSLContext;
Expand All @@ -38,7 +37,6 @@
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.List;
import java.util.Set;
Expand All @@ -51,7 +49,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import jdk.httpclient.test.lib.common.HttpServerAdapters;
import jdk.httpclient.test.lib.http2.Http2TestServer;
import static java.net.http.HttpClient.Version.HTTP_1_1;
import static java.net.http.HttpClient.Version.HTTP_2;

Expand All @@ -64,6 +61,7 @@
* @library /test/lib /test/jdk/java/net/httpclient/lib
* @build jdk.httpclient.test.lib.common.HttpServerAdapters
* jdk.test.lib.net.SimpleSSLContext DigestEchoServer
* jdk.httpclient.test.lib.common.TestServerConfigurator
* @run main/othervm -Dtest.requiresHost=true
* -Djdk.httpclient.HttpClient.log=headers
* -Djdk.internal.httpclient.debug=true
Expand Down Expand Up @@ -136,7 +134,7 @@ public void setUp() throws Exception {
// HTTPS/1.1
HttpsServer sserver1 = HttpsServer.create(sa, 100);
sserver1.setExecutor(executor);
sserver1.setHttpsConfigurator(new HttpsConfigurator(context));
sserver1.setHttpsConfigurator(new TestServerConfigurator(sa.getAddress(), context));
https1Server = HttpTestServer.of(sserver1);
https1Server.addHandler(new HttpTestLargeHandler(), "/LargeResponseTest/https1/");
https1Server.start();
Expand Down
5 changes: 3 additions & 2 deletions test/jdk/java/net/httpclient/LightWeightHttpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsServer;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -50,6 +49,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.SSLContext;

import jdk.httpclient.test.lib.common.TestServerConfigurator;
import jdk.test.lib.net.SimpleSSLContext;

public class LightWeightHttpServer {
Expand Down Expand Up @@ -111,7 +112,7 @@ public static void initServer() throws IOException {
httpServer.setExecutor(executor);
httpsServer.setExecutor(executor);
ctx = new SimpleSSLContext().get();
httpsServer.setHttpsConfigurator(new HttpsConfigurator(ctx));
httpsServer.setHttpsConfigurator(new TestServerConfigurator(addr.getAddress(), ctx));
httpServer.start();
httpsServer.start();

Expand Down

3 comments on commit 05e9c41

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 05e9c41 Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 05e9c41 Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch backport-GoeLin-05e9c41e in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 05e9c41e from the openjdk/jdk repository.

The commit being backported was authored by Jaikiran Pai on 27 Jun 2023 and was reviewed by Daniel Fuchs.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-GoeLin-05e9c41e:backport-GoeLin-05e9c41e
$ git checkout backport-GoeLin-05e9c41e
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-GoeLin-05e9c41e

Please sign in to comment.