Skip to content

Commit 7dd8c8c

Browse files
committed
8348107: test/jdk/java/net/httpclient/HttpsTunnelAuthTest.java fails intermittently
Backport-of: 5c4a387b7e5643815542dd6938e8e1dbb817ad90
1 parent 5b0f3a6 commit 7dd8c8c

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

test/jdk/java/net/httpclient/HttpsTunnelAuthTest.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -108,6 +108,7 @@ public class HttpsTunnelAuthTest implements HttpServerAdapters, AutoCloseable {
108108
}
109109

110110
void setUp() throws IOException {
111+
HttpServerAdapters.enableServerLogging();
111112
// Creates an HTTP/1.1 Server that will authenticate for
112113
// arthur with password dent
113114
http1Server = DigestEchoServer.createServer(Version.HTTP_1_1,
@@ -143,10 +144,8 @@ void setUp() throws IOException {
143144

144145
// Creates a proxy selector that unconditionally select the
145146
// above proxy.
146-
var ps = proxySelector = ProxySelector.of(proxy.getProxyAddress());
147+
proxySelector = ProxySelector.of(proxy.getProxyAddress());
147148

148-
// Creates a client that uses the above proxy selector
149-
client = newHttpClient(ps);
150149
}
151150

152151
@Override
@@ -177,23 +176,26 @@ public static void main(String[] args) throws Exception {
177176
try (HttpsTunnelAuthTest test = new HttpsTunnelAuthTest()) {
178177
test.setUp();
179178

180-
// tests proxy and server authentication through:
181-
// - plain proxy connection to plain HTTP/1.1 server,
182-
test.test(Version.HTTP_1_1, "http", "/foo/http1");
179+
try (HttpClient client = test.newHttpClient(test.proxySelector)) {
180+
// tests proxy and server authentication through:
181+
// - plain proxy connection to plain HTTP/1.1 server,
182+
test.test(client, Version.HTTP_1_1, "http", "/foo/http1");
183+
}
183184

184185
// can't really test plain proxy connection to plain HTTP/2 server:
185186
// this is not supported: we downgrade to HTTP/1.1 in that case
186187
// so that is actually somewhat equivalent to the first case:
187188
// therefore we will use a new client to force re-authentication
188189
// of the proxy connection.
189-
test.client = test.newHttpClient(test.proxySelector);
190-
test.test(Version.HTTP_2, "http", "/foo/http2");
190+
try (HttpClient client = test.newHttpClient(test.proxySelector)) {
191+
test.test(client, Version.HTTP_2, "http", "/foo/http2");
191192

192-
// - proxy tunnel SSL connection to HTTP/1.1 server
193-
test.test(Version.HTTP_1_1, "https", "/foo/https1");
193+
// - proxy tunnel SSL connection to HTTP/1.1 server
194+
test.test(client, Version.HTTP_1_1, "https", "/foo/https1");
194195

195-
// - proxy tunnel SSl connection to HTTP/2 server
196-
test.test(Version.HTTP_2, "https", "/foo/https2");
196+
// - proxy tunnel SSl connection to HTTP/2 server
197+
test.test(client, Version.HTTP_2, "https", "/foo/https2");
198+
}
197199
}
198200
}
199201

@@ -227,14 +229,14 @@ Version expectedVersion(String scheme, Version version) {
227229
return "http".equals(scheme) ? Version.HTTP_1_1 : version;
228230
}
229231

230-
public void test(Version version, String scheme, String path) throws Exception {
232+
public void test(HttpClient client, Version version, String scheme, String path) throws Exception {
231233
System.out.printf("%nTesting %s, %s, %s%n", version, scheme, path);
232234
DigestEchoServer server = server(scheme, version);
233235
try {
234236

235237
URI uri = jdk.test.lib.net.URIBuilder.newBuilder()
236238
.scheme(scheme)
237-
.host("localhost")
239+
.loopback()
238240
.port(server.getServerAddress().getPort())
239241
.path(path).build();
240242

0 commit comments

Comments
 (0)