Skip to content

Commit

Permalink
8348102: java/net/httpclient/HttpClientSNITest.java fails intermittently
Browse files Browse the repository at this point in the history
Reviewed-by: dfuchs, djelinski
  • Loading branch information
jaikiran committed Jan 23, 2025
1 parent a36e166 commit 8cf0735
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions test/jdk/java/net/httpclient/HttpClientSNITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import jdk.httpclient.test.lib.common.ServerNameMatcher;
import jdk.test.lib.net.SimpleSSLContext;
import jdk.test.lib.net.URIBuilder;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import static java.nio.charset.StandardCharsets.US_ASCII;
Expand All @@ -70,8 +69,6 @@
public class HttpClientSNITest {
private static final String RESP_BODY_TEXT = "hello world";

private static SSLContext sslContext;

private static final class Handler implements HttpTestHandler {

@Override
Expand All @@ -85,12 +82,6 @@ public void handle(final HttpTestExchange exch) throws IOException {
}
}

@BeforeAll
static void beforeAll() throws Exception {
sslContext = new SimpleSSLContext().get();
assertNotNull(sslContext, "could not create a SSLContext");
}

/*
* Creates and configures a HTTPS server with a SNIMatcher that
* expects a specific SNI name to be sent by the connection client.
Expand All @@ -104,9 +95,11 @@ static void beforeAll() throws Exception {
@ParameterizedTest
@ValueSource(booleans = {false, true})
void testRequestToIPLiteralHost(final boolean sniConfiguredOnClient) throws Exception {
final SSLContext sslContext = new SimpleSSLContext().get();
assertNotNull(sslContext, "could not create a SSLContext");
final String expectedSNI = "non-dns-resolvable.foo.bar.localhost";
final ServerNameMatcher matcher = new ServerNameMatcher(expectedSNI);
final HttpTestServer server = createServer(matcher);
final HttpTestServer server = createServer(matcher, sslContext);
try {
final HttpClient.Builder builder = HttpClient.newBuilder().sslContext(sslContext);
if (sniConfiguredOnClient) {
Expand Down Expand Up @@ -156,10 +149,12 @@ void testRequestToIPLiteralHost(final boolean sniConfiguredOnClient) throws Exce
@ParameterizedTest
@ValueSource(booleans = {false, true})
void testRequestResolvedHostName(final boolean sniConfiguredOnClient) throws Exception {
final SSLContext sslContext = new SimpleSSLContext().get();
assertNotNull(sslContext, "could not create a SSLContext");
final String resolvedHostName = InetAddress.getLoopbackAddress().getHostName();
final String expectedSNI = resolvedHostName;
final ServerNameMatcher matcher = new ServerNameMatcher(expectedSNI);
final HttpTestServer server = createServer(matcher);
final HttpTestServer server = createServer(matcher, sslContext);
try {
final HttpClient.Builder builder = HttpClient.newBuilder().sslContext(sslContext);
if (sniConfiguredOnClient) {
Expand Down Expand Up @@ -190,7 +185,8 @@ void testRequestResolvedHostName(final boolean sniConfiguredOnClient) throws Exc
/*
* Creates a HttpsServer configured to use the given SNIMatcher
*/
private static HttpTestServer createServer(final SNIMatcher matcher) throws Exception {
private static HttpTestServer createServer(final SNIMatcher matcher,
final SSLContext sslContext) throws Exception {
final InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
final int backlog = 0;
final HttpsServer httpsServer = HttpsServer.create(addr, backlog);
Expand Down

0 comments on commit 8cf0735

Please sign in to comment.