SSL ProxySelectorTest.java
Interaktion und PortierbarkeitJAVA
/* * Copyright (c) 2020, 2021, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @bug 8244205 * @summary checks that a different proxy returned for * the same host:port is taken into account * @modules java.base/sun.net.www.http * java.net.http/jdk.internal.net.http.common * java.net.http/jdk.internal.net.http.frame * java.net.http/jdk.internal.net.http.hpack * java.logging * jdk.httpserver * java.base/sun.net.www.http * java.base/sun.net.www * java.base/sun.net * @library /test/lib http2/server * @build HttpServerAdapters DigestEchoServer Http2TestServer ProxySelectorTest * @build jdk.test.lib.net.SimpleSSLContext * @run testng/othervm * -Djdk.http.auth.tunneling.disabledSchemes * -Djdk.httpclient.HttpClient.log=headers,requests * -Djdk.internal.httpclient.debug=true * ProxySelectorTest
*/
URI uri1 = URI.create(uriString + "/server/ProxySelectorTest");
URI uri2 = URI.create(uriString + "/proxy/noauth/ProxySelectorTest");
URI uri3 = URI.create(uriString + "/proxy/auth/ProxySelectorTest");
HttpResponse<String> response;
// First request should go with a direct connection. // A plain server or https server should serve it, and we should get 200 OK
response = send(client, uri1, BodyHandlers.ofString(), async);
out.println("Got response from plain server: " + response);
assertEquals(response.statusCode(), HTTP_OK);
assertEquals(response.headers().firstValue("X-value"),
scheme == Schemes.HTTPS ? Optional.of("https-server") : Optional.of("plain-server"));
// Second request should go through a non authenticating proxy. // For a clear connection - a proxy-server should serve it, and we should get 200 OK // For an https connection - a tunnel should be established through the non // authenticating proxy - and we should receive 200 OK from an https-server
response = send(client, uri2, BodyHandlers.ofString(), async);
out.println("Got response through noauth proxy: " + response);
assertEquals(response.statusCode(), HTTP_OK);
assertEquals(response.headers().firstValue("X-value"),
scheme == Schemes.HTTPS ? Optional.of("https-server") : Optional.of("proxy-server"));
// Third request should go through an authenticating proxy. // For a clear connection - an auth-proxy-server should serve it, and we // should get 407 // For an https connection - a tunnel should be established through an // authenticating proxy - and we should receive 407 directly from the // proxy - so the X-value header will be absent
response = send(client, uri3, BodyHandlers.ofString(), async);
out.println("Got response through auth proxy: " + response);
assertEquals(response.statusCode(), PROXY_UNAUTHORIZED);
assertEquals(response.headers().firstValue("X-value"),
scheme == Schemes.HTTPS ? Optional.empty() : Optional.of("auth-proxy-server"));
}
// -- Infrastructure
@BeforeTest publicvoid setup() throws Exception {
sslContext = new SimpleSSLContext().get(); if (sslContext == null) thrownew AssertionError("Unexpected null sslContext");
InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.