Skip to content

Commit

Permalink
8348107: test/jdk/java/net/httpclient/HttpsTunnelAuthTest.java fails …
Browse files Browse the repository at this point in the history
…intermittently
  • Loading branch information
dfuch committed Jan 20, 2025
1 parent 3a4d5ff commit fad6b4f
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions test/jdk/java/net/httpclient/HttpsTunnelAuthTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -108,6 +108,7 @@ public class HttpsTunnelAuthTest implements HttpServerAdapters, AutoCloseable {
}

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

// Creates a proxy selector that unconditionally select the
// above proxy.
var ps = proxySelector = ProxySelector.of(proxy.getProxyAddress());
proxySelector = ProxySelector.of(proxy.getProxyAddress());

// Creates a client that uses the above proxy selector
client = newHttpClient(ps);
}

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

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

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

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

// - proxy tunnel SSl connection to HTTP/2 server
test.test(Version.HTTP_2, "https", "/foo/https2");
// - proxy tunnel SSl connection to HTTP/2 server
test.test(client, Version.HTTP_2, "https", "/foo/https2");
}
}
}

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

public void test(Version version, String scheme, String path) throws Exception {
public void test(HttpClient client, Version version, String scheme, String path) throws Exception {
System.out.printf("%nTesting %s, %s, %s%n", version, scheme, path);
DigestEchoServer server = server(scheme, version);
try {

URI uri = jdk.test.lib.net.URIBuilder.newBuilder()
.scheme(scheme)
.host("localhost")
.loopback()
.port(server.getServerAddress().getPort())
.path(path).build();

Expand Down

0 comments on commit fad6b4f

Please sign in to comment.