author | mikael |
Fri, 04 Dec 2015 15:08:49 -0800 | |
changeset 35090 | 1f5b6aa795d0 |
parent 22976 | 90ec9fec7c7f |
child 38883 | d5de564f8089 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
2 |
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/** |
|
25 |
* @test |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
26 |
* @bug 4769350 8017779 |
4916
de44744708a2
6693244: Java Web Start app fails on 6u10 beta w/ AssertionError in AuthenticationInfo.requestCompleted
chegar
parents:
2
diff
changeset
|
27 |
* @run main/othervm B4769350 server |
de44744708a2
6693244: Java Web Start app fails on 6u10 beta w/ AssertionError in AuthenticationInfo.requestCompleted
chegar
parents:
2
diff
changeset
|
28 |
* @run main/othervm B4769350 proxy |
2 | 29 |
* @summary proxy authentication username and password caching only works in serial case |
4916
de44744708a2
6693244: Java Web Start app fails on 6u10 beta w/ AssertionError in AuthenticationInfo.requestCompleted
chegar
parents:
2
diff
changeset
|
30 |
* Run in othervm since the test sets system properties that are read by the |
de44744708a2
6693244: Java Web Start app fails on 6u10 beta w/ AssertionError in AuthenticationInfo.requestCompleted
chegar
parents:
2
diff
changeset
|
31 |
* networking stack and cached when the HTTP handler is invoked, and previous |
de44744708a2
6693244: Java Web Start app fails on 6u10 beta w/ AssertionError in AuthenticationInfo.requestCompleted
chegar
parents:
2
diff
changeset
|
32 |
* tests may already have invoked the HTTP handler. |
2 | 33 |
*/ |
34 |
||
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
35 |
import com.sun.net.httpserver.HttpExchange; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
36 |
import com.sun.net.httpserver.HttpHandler; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
37 |
import com.sun.net.httpserver.HttpServer; |
2 | 38 |
import java.io.*; |
39 |
import java.net.*; |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
40 |
import java.util.concurrent.BrokenBarrierException; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
41 |
import java.util.concurrent.CountDownLatch; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
42 |
import java.util.concurrent.CyclicBarrier; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
43 |
import java.util.concurrent.Executor; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
44 |
import java.util.concurrent.ExecutorService; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
45 |
import java.util.concurrent.Executors; |
2 | 46 |
|
47 |
public class B4769350 { |
|
48 |
||
49 |
static int count = 0; |
|
50 |
static boolean error = false; |
|
51 |
||
52 |
static void read (InputStream is) throws IOException { |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
53 |
while (is.read() != -1) { |
2 | 54 |
//System.out.write (c); |
55 |
} |
|
56 |
} |
|
57 |
||
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
58 |
static class Client extends Thread { |
2 | 59 |
String authority, path; |
60 |
boolean allowerror; |
|
61 |
||
62 |
Client (String authority, String path, boolean allowerror) { |
|
5979
26b9b2b1b37b
6954525: Testcase failure java/net/Authenticator/B4769350.java
chegar
parents:
5506
diff
changeset
|
63 |
super("Thread-" + path); |
2 | 64 |
this.authority = authority; |
65 |
this.path = path; |
|
66 |
this.allowerror = allowerror; |
|
67 |
} |
|
68 |
||
22976
90ec9fec7c7f
8031661: java/net/Authenticator/B4769350.java failed intermittently
michaelm
parents:
21320
diff
changeset
|
69 |
@Override |
2 | 70 |
public void run () { |
71 |
try { |
|
72 |
URI u = new URI ("http", authority, path, null, null); |
|
73 |
URL url = u.toURL(); |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
74 |
URLConnection urlc = url.openConnection(); |
22976
90ec9fec7c7f
8031661: java/net/Authenticator/B4769350.java failed intermittently
michaelm
parents:
21320
diff
changeset
|
75 |
try (InputStream is = urlc.getInputStream()) { |
90ec9fec7c7f
8031661: java/net/Authenticator/B4769350.java failed intermittently
michaelm
parents:
21320
diff
changeset
|
76 |
read (is); |
90ec9fec7c7f
8031661: java/net/Authenticator/B4769350.java failed intermittently
michaelm
parents:
21320
diff
changeset
|
77 |
} |
2 | 78 |
} catch (URISyntaxException e) { |
79 |
System.out.println (e); |
|
80 |
error = true; |
|
81 |
} catch (IOException e) { |
|
82 |
if (!allowerror) { |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
83 |
System.out.println (Thread.currentThread().getName() |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
84 |
+ " " + e); |
5979
26b9b2b1b37b
6954525: Testcase failure java/net/Authenticator/B4769350.java
chegar
parents:
5506
diff
changeset
|
85 |
e.printStackTrace(); |
2 | 86 |
error = true; |
87 |
} |
|
88 |
} |
|
89 |
} |
|
90 |
} |
|
91 |
||
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
92 |
class Server implements AutoCloseable { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
93 |
HttpServer server; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
94 |
Executor executor; |
2 | 95 |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
96 |
public String getAddress() { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
97 |
return server.getAddress().getHostName(); |
2 | 98 |
} |
99 |
||
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
100 |
public void startServer() { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
101 |
InetSocketAddress addr = new InetSocketAddress(0); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
102 |
|
2 | 103 |
try { |
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
104 |
server = HttpServer.create(addr, 0); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
105 |
} catch (IOException ioe) { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
106 |
throw new RuntimeException("Server could not be created"); |
2 | 107 |
} |
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
108 |
executor = Executors.newFixedThreadPool(10); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
109 |
server.setExecutor(executor); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
110 |
server.createContext("/test/realm1/t1a", |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
111 |
new AuthenticationHandlerT1a() ); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
112 |
server.createContext("/test/realm2/t1b", |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
113 |
new AuthenticationHandlerT1b()); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
114 |
server.createContext("/test/realm1/t1c", |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
115 |
new AuthenticationHandlerT1c()); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
116 |
server.createContext("/test/realm2/t1d", |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
117 |
new AuthenticationHandlerT1d()); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
118 |
server.createContext("/test/realm3/t2a", |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
119 |
new AuthenticationHandlerT2a()); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
120 |
server.createContext("/test/realm3/t2b", |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
121 |
new AuthenticationHandlerT2b()); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
122 |
server.createContext("/test/realm4/t3a", |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
123 |
new AuthenticationHandlerT3a()); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
124 |
server.createContext("/test/realm4/t3b", |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
125 |
new AuthenticationHandlerT3bc()); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
126 |
server.createContext("/test/realm4/t3c", |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
127 |
new AuthenticationHandlerT3bc()); |
22976
90ec9fec7c7f
8031661: java/net/Authenticator/B4769350.java failed intermittently
michaelm
parents:
21320
diff
changeset
|
128 |
t1Cond1 = new CyclicBarrier(3); |
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
129 |
server.start(); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
130 |
} |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
131 |
|
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
132 |
public int getPort() { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
133 |
return server.getAddress().getPort(); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
134 |
} |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
135 |
|
22976
90ec9fec7c7f
8031661: java/net/Authenticator/B4769350.java failed intermittently
michaelm
parents:
21320
diff
changeset
|
136 |
@Override |
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
137 |
public void close() { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
138 |
if (executor != null) |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
139 |
((ExecutorService)executor).shutdownNow(); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
140 |
if (server != null) |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
141 |
server.stop(0); |
2 | 142 |
} |
143 |
||
144 |
/* T1 tests the client by sending 4 requests to 2 different realms |
|
145 |
* in parallel. The client should recognise two pairs of dependent requests |
|
146 |
* and execute the first of each pair in parallel. When they both succeed |
|
147 |
* the second requests should be executed without calling the authenticator. |
|
148 |
* The test succeeds if the authenticator was only called twice. |
|
149 |
*/ |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
150 |
class AuthenticationHandlerT1a implements HttpHandler |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
151 |
{ |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
152 |
volatile int count = -1; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
153 |
|
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
154 |
@Override |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
155 |
public void handle(HttpExchange exchange) throws IOException { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
156 |
count++; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
157 |
try { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
158 |
switch(count) { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
159 |
case 0: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
160 |
AuthenticationHandler.errorReply(exchange, |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
161 |
"Basic realm=\"realm1\""); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
162 |
break; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
163 |
case 1: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
164 |
t1Cond1.await(); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
165 |
AuthenticationHandler.okReply(exchange); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
166 |
break; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
167 |
default: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
168 |
System.out.println ("Unexpected request"); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
169 |
} |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
170 |
} catch (InterruptedException | |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
171 |
BrokenBarrierException e) |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
172 |
{ |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
173 |
throw new RuntimeException(e); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
174 |
} |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
175 |
} |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
176 |
} |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
177 |
|
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
178 |
class AuthenticationHandlerT1b implements HttpHandler |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
179 |
{ |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
180 |
volatile int count = -1; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
181 |
|
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
182 |
@Override |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
183 |
public void handle(HttpExchange exchange) throws IOException { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
184 |
count++; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
185 |
try { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
186 |
switch(count) { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
187 |
case 0: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
188 |
AuthenticationHandler.errorReply(exchange, |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
189 |
"Basic realm=\"realm2\""); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
190 |
break; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
191 |
case 1: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
192 |
t1Cond1.await(); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
193 |
AuthenticationHandler.okReply(exchange); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
194 |
break; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
195 |
default: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
196 |
System.out.println ("Unexpected request"); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
197 |
} |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
198 |
} catch (InterruptedException | BrokenBarrierException e) { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
199 |
throw new RuntimeException(e); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
200 |
} |
2 | 201 |
} |
202 |
} |
|
203 |
||
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
204 |
class AuthenticationHandlerT1c implements HttpHandler |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
205 |
{ |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
206 |
volatile int count = -1; |
2 | 207 |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
208 |
@Override |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
209 |
public void handle(HttpExchange exchange) throws IOException { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
210 |
count++; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
211 |
switch(count) { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
212 |
case 0: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
213 |
AuthenticationHandler.errorReply(exchange, |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
214 |
"Basic realm=\"realm1\""); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
215 |
break; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
216 |
case 1: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
217 |
AuthenticationHandler.okReply(exchange); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
218 |
break; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
219 |
default: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
220 |
System.out.println ("Unexpected request"); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
221 |
} |
2 | 222 |
} |
223 |
} |
|
224 |
||
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
225 |
class AuthenticationHandlerT1d implements HttpHandler |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
226 |
{ |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
227 |
volatile int count = -1; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
228 |
|
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
229 |
@Override |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
230 |
public void handle(HttpExchange exchange) throws IOException { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
231 |
count++; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
232 |
switch(count) { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
233 |
case 0: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
234 |
AuthenticationHandler.errorReply(exchange, |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
235 |
"Basic realm=\"realm2\""); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
236 |
break; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
237 |
case 1: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
238 |
AuthenticationHandler.okReply(exchange); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
239 |
break; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
240 |
default: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
241 |
System.out.println ("Unexpected request"); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
242 |
} |
2 | 243 |
} |
244 |
} |
|
245 |
||
246 |
/* T2 tests to check that if initial authentication fails, the second will |
|
247 |
* succeed, and the authenticator is called twice |
|
248 |
*/ |
|
249 |
||
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
250 |
class AuthenticationHandlerT2a implements HttpHandler |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
251 |
{ |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
252 |
volatile int count = -1; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
253 |
|
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
254 |
@Override |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
255 |
public void handle(HttpExchange exchange) throws IOException { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
256 |
count++; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
257 |
if (count == 1) { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
258 |
t2condlatch.countDown(); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
259 |
} |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
260 |
AuthenticationHandler.errorReply(exchange, |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
261 |
"Basic realm=\"realm3\""); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
262 |
|
2 | 263 |
} |
264 |
} |
|
265 |
||
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
266 |
class AuthenticationHandlerT2b implements HttpHandler |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
267 |
{ |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
268 |
volatile int count = -1; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
269 |
|
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
270 |
@Override |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
271 |
public void handle(HttpExchange exchange) throws IOException { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
272 |
count++; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
273 |
switch(count) { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
274 |
case 0: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
275 |
AuthenticationHandler.errorReply(exchange, |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
276 |
"Basic realm=\"realm3\""); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
277 |
break; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
278 |
case 1: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
279 |
AuthenticationHandler.okReply(exchange); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
280 |
break; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
281 |
default: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
282 |
System.out.println ("Unexpected request"); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
283 |
} |
2 | 284 |
} |
285 |
} |
|
286 |
||
287 |
/* T3 tests proxy and server authentication. three threads request same |
|
288 |
* resource at same time. Authenticator should be called once for server |
|
289 |
* and once for proxy |
|
290 |
*/ |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
291 |
|
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
292 |
class AuthenticationHandlerT3a implements HttpHandler |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
293 |
{ |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
294 |
volatile int count = -1; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
295 |
|
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
296 |
@Override |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
297 |
public void handle(HttpExchange exchange) throws IOException { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
298 |
count++; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
299 |
switch(count) { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
300 |
case 0: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
301 |
AuthenticationHandler.proxyReply(exchange, |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
302 |
"Basic realm=\"proxy\""); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
303 |
break; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
304 |
case 1: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
305 |
t3cond1.countDown(); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
306 |
AuthenticationHandler.errorReply(exchange, |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
307 |
"Basic realm=\"realm4\""); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
308 |
break; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
309 |
case 2: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
310 |
AuthenticationHandler.okReply(exchange); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
311 |
break; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
312 |
default: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
313 |
System.out.println ("Unexpected request"); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
314 |
} |
2 | 315 |
} |
316 |
} |
|
317 |
||
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
318 |
class AuthenticationHandlerT3bc implements HttpHandler |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
319 |
{ |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
320 |
volatile int count = -1; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
321 |
|
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
322 |
@Override |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
323 |
public void handle(HttpExchange exchange) throws IOException { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
324 |
count++; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
325 |
switch(count) { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
326 |
case 0: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
327 |
AuthenticationHandler.proxyReply(exchange, |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
328 |
"Basic realm=\"proxy\""); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
329 |
break; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
330 |
case 1: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
331 |
AuthenticationHandler.okReply(exchange); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
332 |
break; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
333 |
default: |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
334 |
System.out.println ("Unexpected request"); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
335 |
} |
2 | 336 |
} |
337 |
} |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
338 |
} |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
339 |
|
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
340 |
static class AuthenticationHandler { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
341 |
static void errorReply(HttpExchange exchange, String reply) |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
342 |
throws IOException |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
343 |
{ |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
344 |
exchange.getResponseHeaders().add("Connection", "close"); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
345 |
exchange.getResponseHeaders().add("WWW-Authenticate", reply); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
346 |
exchange.sendResponseHeaders(401, 0); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
347 |
exchange.close(); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
348 |
} |
2 | 349 |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
350 |
static void proxyReply (HttpExchange exchange, String reply) |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
351 |
throws IOException |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
352 |
{ |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
353 |
exchange.getResponseHeaders().add("Proxy-Authenticate", reply); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
354 |
exchange.sendResponseHeaders(407, 0); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
355 |
} |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
356 |
|
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
357 |
static void okReply (HttpExchange exchange) throws IOException { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
358 |
exchange.getResponseHeaders().add("Connection", "close"); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
359 |
String response = "Hello ."; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
360 |
exchange.sendResponseHeaders(200, response.getBytes().length); |
22976
90ec9fec7c7f
8031661: java/net/Authenticator/B4769350.java failed intermittently
michaelm
parents:
21320
diff
changeset
|
361 |
try (OutputStream os = exchange.getResponseBody()) { |
90ec9fec7c7f
8031661: java/net/Authenticator/B4769350.java failed intermittently
michaelm
parents:
21320
diff
changeset
|
362 |
os.write(response.getBytes()); |
90ec9fec7c7f
8031661: java/net/Authenticator/B4769350.java failed intermittently
michaelm
parents:
21320
diff
changeset
|
363 |
} |
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
364 |
exchange.close(); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
365 |
} |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
366 |
} |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
367 |
|
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
368 |
static Server server; |
2 | 369 |
static MyAuthenticator auth = new MyAuthenticator (); |
370 |
||
371 |
static int redirects = 4; |
|
372 |
||
373 |
static Client c1,c2,c3,c4,c5,c6,c7,c8,c9; |
|
374 |
||
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
375 |
static CountDownLatch t2condlatch; |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
376 |
static CountDownLatch t3cond1; |
22976
90ec9fec7c7f
8031661: java/net/Authenticator/B4769350.java failed intermittently
michaelm
parents:
21320
diff
changeset
|
377 |
static CyclicBarrier t1Cond1; |
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
378 |
|
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
379 |
static void doServerTests (String authority, Server server) throws Exception |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
380 |
{ |
2 | 381 |
System.out.println ("Doing Server tests"); |
382 |
System.out.println ("T1"); |
|
383 |
c1 = new Client (authority, "/test/realm1/t1a", false); |
|
384 |
c2 = new Client (authority, "/test/realm2/t1b", false); |
|
385 |
c3 = new Client (authority, "/test/realm1/t1c", false); |
|
386 |
c4 = new Client (authority, "/test/realm2/t1d", false); |
|
387 |
c1.start(); c2.start(); |
|
22976
90ec9fec7c7f
8031661: java/net/Authenticator/B4769350.java failed intermittently
michaelm
parents:
21320
diff
changeset
|
388 |
t1Cond1.await(); |
2 | 389 |
c3.start(); c4.start(); |
390 |
c1.join(); c2.join(); c3.join(); c4.join(); |
|
391 |
||
392 |
int f = auth.getCount(); |
|
393 |
if (f != 2) { |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
394 |
except ("Authenticator was called "+f+" times. Should be 2", |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
395 |
server); |
2 | 396 |
} |
397 |
if (error) { |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
398 |
except ("error occurred", server); |
2 | 399 |
} |
400 |
||
401 |
auth.resetCount(); |
|
402 |
System.out.println ("T2"); |
|
403 |
||
404 |
c5 = new Client (authority, "/test/realm3/t2a", true); |
|
405 |
c6 = new Client (authority, "/test/realm3/t2b", false); |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
406 |
t2condlatch = new CountDownLatch(1); |
2 | 407 |
c5.start (); |
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
408 |
t2condlatch.await(); |
2 | 409 |
c6.start (); |
410 |
c5.join(); c6.join(); |
|
411 |
||
412 |
f = auth.getCount(); |
|
413 |
if (f != redirects+1) { |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
414 |
except ("Authenticator was called "+f+" times. Should be: " |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
415 |
+ redirects+1, server); |
2 | 416 |
} |
417 |
if (error) { |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
418 |
except ("error occurred", server); |
2 | 419 |
} |
420 |
} |
|
421 |
||
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
422 |
static void doProxyTests (String authority, Server server) throws Exception |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
423 |
{ |
2 | 424 |
System.out.println ("Doing Proxy tests"); |
425 |
c7 = new Client (authority, "/test/realm4/t3a", false); |
|
426 |
c8 = new Client (authority, "/test/realm4/t3b", false); |
|
427 |
c9 = new Client (authority, "/test/realm4/t3c", false); |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
428 |
t3cond1 = new CountDownLatch(1); |
2 | 429 |
c7.start (); |
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
430 |
t3cond1.await(); |
2 | 431 |
c8.start (); |
432 |
c9.start (); |
|
433 |
c7.join(); c8.join(); c9.join(); |
|
434 |
||
435 |
int f = auth.getCount(); |
|
436 |
if (f != 2) { |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
437 |
except ("Authenticator was called "+f+" times. Should be: " + 2, |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
438 |
server); |
2 | 439 |
} |
440 |
if (error) { |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
441 |
except ("error occurred", server); |
2 | 442 |
} |
443 |
} |
|
444 |
||
445 |
public static void main (String[] args) throws Exception { |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
446 |
new B4769350().runTest(args[0].equals ("proxy")); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
447 |
} |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
448 |
|
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
449 |
public void runTest(boolean proxy) throws Exception { |
2 | 450 |
System.setProperty ("http.maxRedirects", Integer.toString (redirects)); |
451 |
System.setProperty ("http.auth.serializeRequests", "true"); |
|
452 |
Authenticator.setDefault (auth); |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
453 |
try (Server server = new Server()) { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
454 |
server.startServer(); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
455 |
System.out.println ("Server: listening on port: " |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
456 |
+ server.getPort()); |
2 | 457 |
if (proxy) { |
458 |
System.setProperty ("http.proxyHost", "localhost"); |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
459 |
System.setProperty ("http.proxyPort", |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
460 |
Integer.toString(server.getPort())); |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
461 |
doProxyTests ("www.foo.com", server); |
2 | 462 |
} else { |
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
463 |
doServerTests ("localhost:"+server.getPort(), server); |
2 | 464 |
} |
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
465 |
} |
2 | 466 |
|
467 |
} |
|
468 |
||
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
469 |
public static void except (String s, Server server) { |
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
470 |
server.close(); |
2 | 471 |
throw new RuntimeException (s); |
472 |
} |
|
473 |
||
474 |
static class MyAuthenticator extends Authenticator { |
|
475 |
MyAuthenticator () { |
|
476 |
super (); |
|
477 |
} |
|
478 |
||
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
479 |
volatile int count = 0; |
2 | 480 |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
481 |
@Override |
2 | 482 |
public PasswordAuthentication getPasswordAuthentication () { |
483 |
PasswordAuthentication pw; |
|
484 |
pw = new PasswordAuthentication ("user", "pass1".toCharArray()); |
|
485 |
count ++; |
|
486 |
return pw; |
|
487 |
} |
|
488 |
||
489 |
public void resetCount () { |
|
490 |
count = 0; |
|
491 |
} |
|
492 |
||
493 |
public int getCount () { |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
494 |
return count; |
2 | 495 |
} |
496 |
} |
|
497 |
} |
|
21320
0a56bf0c2390
8017779: java/net/Authenticator/B4769350.java fails
chegar
parents:
14342
diff
changeset
|
498 |