Skip to content

Commit 8cf0735

Browse files
committed
8348102: java/net/httpclient/HttpClientSNITest.java fails intermittently
Reviewed-by: dfuchs, djelinski
1 parent a36e166 commit 8cf0735

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

test/jdk/java/net/httpclient/HttpClientSNITest.java

+8-12
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import jdk.httpclient.test.lib.common.ServerNameMatcher;
4747
import jdk.test.lib.net.SimpleSSLContext;
4848
import jdk.test.lib.net.URIBuilder;
49-
import org.junit.jupiter.api.BeforeAll;
5049
import org.junit.jupiter.params.ParameterizedTest;
5150
import org.junit.jupiter.params.provider.ValueSource;
5251
import static java.nio.charset.StandardCharsets.US_ASCII;
@@ -70,8 +69,6 @@
7069
public class HttpClientSNITest {
7170
private static final String RESP_BODY_TEXT = "hello world";
7271

73-
private static SSLContext sslContext;
74-
7572
private static final class Handler implements HttpTestHandler {
7673

7774
@Override
@@ -85,12 +82,6 @@ public void handle(final HttpTestExchange exch) throws IOException {
8582
}
8683
}
8784

88-
@BeforeAll
89-
static void beforeAll() throws Exception {
90-
sslContext = new SimpleSSLContext().get();
91-
assertNotNull(sslContext, "could not create a SSLContext");
92-
}
93-
9485
/*
9586
* Creates and configures a HTTPS server with a SNIMatcher that
9687
* expects a specific SNI name to be sent by the connection client.
@@ -104,9 +95,11 @@ static void beforeAll() throws Exception {
10495
@ParameterizedTest
10596
@ValueSource(booleans = {false, true})
10697
void testRequestToIPLiteralHost(final boolean sniConfiguredOnClient) throws Exception {
98+
final SSLContext sslContext = new SimpleSSLContext().get();
99+
assertNotNull(sslContext, "could not create a SSLContext");
107100
final String expectedSNI = "non-dns-resolvable.foo.bar.localhost";
108101
final ServerNameMatcher matcher = new ServerNameMatcher(expectedSNI);
109-
final HttpTestServer server = createServer(matcher);
102+
final HttpTestServer server = createServer(matcher, sslContext);
110103
try {
111104
final HttpClient.Builder builder = HttpClient.newBuilder().sslContext(sslContext);
112105
if (sniConfiguredOnClient) {
@@ -156,10 +149,12 @@ void testRequestToIPLiteralHost(final boolean sniConfiguredOnClient) throws Exce
156149
@ParameterizedTest
157150
@ValueSource(booleans = {false, true})
158151
void testRequestResolvedHostName(final boolean sniConfiguredOnClient) throws Exception {
152+
final SSLContext sslContext = new SimpleSSLContext().get();
153+
assertNotNull(sslContext, "could not create a SSLContext");
159154
final String resolvedHostName = InetAddress.getLoopbackAddress().getHostName();
160155
final String expectedSNI = resolvedHostName;
161156
final ServerNameMatcher matcher = new ServerNameMatcher(expectedSNI);
162-
final HttpTestServer server = createServer(matcher);
157+
final HttpTestServer server = createServer(matcher, sslContext);
163158
try {
164159
final HttpClient.Builder builder = HttpClient.newBuilder().sslContext(sslContext);
165160
if (sniConfiguredOnClient) {
@@ -190,7 +185,8 @@ void testRequestResolvedHostName(final boolean sniConfiguredOnClient) throws Exc
190185
/*
191186
* Creates a HttpsServer configured to use the given SNIMatcher
192187
*/
193-
private static HttpTestServer createServer(final SNIMatcher matcher) throws Exception {
188+
private static HttpTestServer createServer(final SNIMatcher matcher,
189+
final SSLContext sslContext) throws Exception {
194190
final InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
195191
final int backlog = 0;
196192
final HttpsServer httpsServer = HttpsServer.create(addr, backlog);

0 commit comments

Comments
 (0)