/* * Copyright (c) 2002, 2019, 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 4769350 8017779 8191169 * @modules jdk.httpserver * @run main/othervm B4769350 server * @run main/othervm B4769350 proxy * @run main/othervm -Djava.net.preferIPv6Addresses=true B4769350 server * @run main/othervm -Djava.net.preferIPv6Addresses=true B4769350 proxy * @summary proxy authentication username and password caching only works in serial case * Run in othervm since the test sets system properties that are read by the * networking stack and cached when the HTTP handler is invoked, and previous * tests may already have invoked the HTTP handler.
*/
try {
server = HttpServer.create(addr, 0);
} catch (IOException ioe) { thrownew RuntimeException("Server could not be created");
}
executor = Executors.newFixedThreadPool(10);
server.setExecutor(executor);
server.createContext("/test/realm1/t1a", new AuthenticationHandlerT1a() );
server.createContext("/test/realm2/t1b", new AuthenticationHandlerT1b());
server.createContext("/test/realm1/t1c", new AuthenticationHandlerT1c());
server.createContext("/test/realm2/t1d", new AuthenticationHandlerT1d());
server.createContext("/test/realm3/t2a", new AuthenticationHandlerT2a());
server.createContext("/test/realm3/t2b", new AuthenticationHandlerT2b());
server.createContext("/test/realm4/t3a", new AuthenticationHandlerT3a());
server.createContext("/test/realm4/t3b", new AuthenticationHandlerT3bc());
server.createContext("/test/realm4/t3c", new AuthenticationHandlerT3bc());
t1Cond1 = new CyclicBarrier(3);
server.start();
}
@Override publicvoid close() { if (executor != null)
((ExecutorService)executor).shutdownNow(); if (server != null)
server.stop(0);
}
/* T1 tests the client by sending 4 requests to 2 different realms * in parallel. The client should recognise two pairs of dependent requests * and execute the first of each pair in parallel. When they both succeed * the second requests should be executed without calling the authenticator. * The test succeeds if the authenticator was only called twice.
*/ class AuthenticationHandlerT1a implements HttpHandler
{ volatileint count = -1;
/* T3 tests proxy and server authentication. three threads request same * resource at same time. Authenticator should be called once for server * and once for proxy
*/
class AuthenticationHandlerT3a implements HttpHandler
{ volatileint count = -1;
staticvoid doServerTests (String authority, Server server) throws Exception
{
System.out.println ("Doing Server tests");
System.out.println ("T1");
c1 = new Client (authority, "/test/realm1/t1a", false);
c2 = new Client (authority, "/test/realm2/t1b", false);
c3 = new Client (authority, "/test/realm1/t1c", false);
c4 = new Client (authority, "/test/realm2/t1d", false);
c1.start(); c2.start();
t1Cond1.await();
c3.start(); c4.start();
c1.join(); c2.join(); c3.join(); c4.join();
int f = auth.getCount(); if (f != 2) {
except ("Authenticator was called "+f+" times. Should be 2",
server);
} if (error) {
except ("error occurred", server);
}
auth.resetCount();
System.out.println ("T2");
c5 = new Client (authority, "/test/realm3/t2a", true);
c6 = new Client (authority, "/test/realm3/t2b", false);
t2condlatch = new CountDownLatch(1);
c5.start ();
t2condlatch.await();
c6.start ();
c5.join(); c6.join();
f = auth.getCount(); if (f != redirects+1) {
except ("Authenticator was called "+f+" times. Should be: "
+ redirects+1, server);
} if (error) {
except ("error occurred", server);
}
}
staticvoid doProxyTests (String authority, Server server) throws Exception
{
System.out.println ("Doing Proxy tests");
c7 = new Client (authority, "/test/realm4/t3a", false);
c8 = new Client (authority, "/test/realm4/t3b", false);
c9 = new Client (authority, "/test/realm4/t3c", false);
t3cond1 = new CountDownLatch(1);
c7.start ();
t3cond1.await();
c8.start ();
c9.start ();
c7.join(); c8.join(); c9.join();
int f = auth.getCount(); if (f != 2) {
except ("Authenticator was called "+f+" times. Should be: " + 2,
server);
} if (error) {
except ("error occurred", server);
}
}
publicstaticvoid main (String[] args) throws Exception { new B4769350().runTest(args[0].equals ("proxy"));
}
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 und die Messung sind noch experimentell.