author | lana |
Thu, 26 Dec 2013 12:04:16 -0800 | |
changeset 23010 | 6dadb192ad81 |
parent 22969 | d5c38e7ba6d0 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
22969
diff
changeset
|
2 |
* Copyright (c) 2003, 2012, 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 |
|
26 |
* @bug 4932837 6582235 |
|
27 |
* @summary Test SslRMI[Client|Server]SocketFactory equals() and hashCode(). |
|
22969
d5c38e7ba6d0
8034000: lack of /othervm option can cause some RMI tests to fail
smarks
parents:
14778
diff
changeset
|
28 |
* This test does not affect VM global state, so othervm is |
d5c38e7ba6d0
8034000: lack of /othervm option can cause some RMI tests to fail
smarks
parents:
14778
diff
changeset
|
29 |
* not required. |
2 | 30 |
* @author Daniel Fuchs |
14778 | 31 |
* |
2 | 32 |
* @run main SocketFactoryTest |
33 |
*/ |
|
34 |
||
35 |
import java.io.PrintWriter; |
|
36 |
import java.io.IOException; |
|
37 |
import java.io.Serializable; |
|
38 |
import java.io.ObjectInputStream; |
|
39 |
import java.io.ObjectOutputStream; |
|
40 |
import java.io.ByteArrayInputStream; |
|
41 |
import java.io.ByteArrayOutputStream; |
|
42 |
import java.util.Map; |
|
43 |
import java.util.HashMap; |
|
44 |
import javax.net.ssl.SSLContext; |
|
45 |
import javax.rmi.ssl.SslRMIClientSocketFactory; |
|
46 |
import javax.rmi.ssl.SslRMIServerSocketFactory; |
|
47 |
||
48 |
public class SocketFactoryTest { |
|
49 |
||
50 |
public static final String[] ciphersuite = |
|
51 |
new String[] { "SSL_RSA_WITH_NULL_MD5" }; |
|
52 |
||
53 |
public static final String[] protocol = |
|
54 |
new String[] { "TLSv1" }; |
|
55 |
||
56 |
public static class MySslRMIClientSocketFactory |
|
57 |
extends SslRMIClientSocketFactory { |
|
58 |
} |
|
59 |
||
60 |
public static class MySslRMIServerSocketFactory |
|
61 |
extends SslRMIServerSocketFactory { |
|
62 |
public MySslRMIServerSocketFactory() { |
|
63 |
super(); |
|
64 |
} |
|
65 |
public MySslRMIServerSocketFactory(String[] ciphers, |
|
66 |
String[] protocols, |
|
67 |
boolean need) { |
|
68 |
super(ciphers, protocols, need); |
|
69 |
} |
|
70 |
public MySslRMIServerSocketFactory(SSLContext context, |
|
71 |
String[] ciphers, |
|
72 |
String[] protocols, |
|
73 |
boolean need) { |
|
74 |
super(context, ciphers, protocols, need); |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
public static Object serializeAndClone(Object o) throws Exception { |
|
79 |
System.out.println("Serializing object: " + o); |
|
80 |
final ByteArrayOutputStream obytes = |
|
81 |
new ByteArrayOutputStream(); |
|
82 |
final ObjectOutputStream ostr = |
|
83 |
new ObjectOutputStream(obytes); |
|
84 |
ostr.writeObject(o); |
|
85 |
ostr.flush(); |
|
86 |
||
87 |
System.out.println("Deserializing object"); |
|
88 |
final ByteArrayInputStream ibytes = |
|
89 |
new ByteArrayInputStream(obytes.toByteArray()); |
|
90 |
final ObjectInputStream istr = |
|
91 |
new ObjectInputStream(ibytes); |
|
92 |
return istr.readObject(); |
|
93 |
} |
|
94 |
||
95 |
public static void testEquals(Object a, Object b, boolean expected) { |
|
96 |
final boolean found = a.equals(b); |
|
97 |
if (found != expected) |
|
98 |
throw new RuntimeException("testEquals failed: objects are " + |
|
99 |
((found)?"equals":"not equals")); |
|
100 |
if (found && a.hashCode()!=b.hashCode()) |
|
101 |
throw new RuntimeException("testEquals failed: objects are " + |
|
102 |
"equals but their hashcode differ"); |
|
103 |
} |
|
104 |
||
105 |
public static void main(String[] args) { |
|
106 |
try { |
|
107 |
System.out.println("SocketFactoryTest START."); |
|
108 |
||
109 |
final SSLContext context = SSLContext.getInstance("SSL"); |
|
110 |
context.init(null, null, null); |
|
111 |
||
112 |
final SslRMIClientSocketFactory client1 = |
|
113 |
new SslRMIClientSocketFactory(); |
|
114 |
final SslRMIClientSocketFactory client2 = |
|
115 |
new SslRMIClientSocketFactory(); |
|
116 |
final SslRMIClientSocketFactory client11 = |
|
117 |
(SslRMIClientSocketFactory) serializeAndClone(client1); |
|
118 |
final SslRMIClientSocketFactory client21 = |
|
119 |
(SslRMIClientSocketFactory) serializeAndClone(client2); |
|
120 |
final SslRMIServerSocketFactory server1 = |
|
121 |
new SslRMIServerSocketFactory(); |
|
122 |
final SslRMIServerSocketFactory server2 = |
|
123 |
new SslRMIServerSocketFactory(null, |
|
124 |
null, |
|
125 |
false); |
|
126 |
final SslRMIServerSocketFactory server3 = |
|
127 |
new SslRMIServerSocketFactory(ciphersuite, |
|
128 |
null, |
|
129 |
false); |
|
130 |
final SslRMIServerSocketFactory server4 = |
|
131 |
new SslRMIServerSocketFactory(null, |
|
132 |
protocol, |
|
133 |
false); |
|
134 |
final SslRMIServerSocketFactory server5 = |
|
135 |
new SslRMIServerSocketFactory(null, |
|
136 |
null, |
|
137 |
true); |
|
138 |
final SslRMIServerSocketFactory server6 = |
|
139 |
new SslRMIServerSocketFactory(null, |
|
140 |
null, |
|
141 |
null, |
|
142 |
false); |
|
143 |
final SslRMIServerSocketFactory server7 = |
|
144 |
new SslRMIServerSocketFactory(SSLContext.getDefault(), |
|
145 |
null, |
|
146 |
null, |
|
147 |
false); |
|
148 |
final SslRMIServerSocketFactory server8 = |
|
149 |
new SslRMIServerSocketFactory(null, |
|
150 |
null, |
|
151 |
null, |
|
152 |
true); |
|
153 |
final SslRMIServerSocketFactory server9 = |
|
154 |
new SslRMIServerSocketFactory(SSLContext.getDefault(), |
|
155 |
null, |
|
156 |
null, |
|
157 |
true); |
|
158 |
final SslRMIServerSocketFactory server10 = |
|
159 |
new SslRMIServerSocketFactory(context, |
|
160 |
null, |
|
161 |
null, |
|
162 |
true); |
|
163 |
final MySslRMIClientSocketFactory subclient1 = |
|
164 |
new MySslRMIClientSocketFactory(); |
|
165 |
final MySslRMIClientSocketFactory subclient2 = |
|
166 |
new MySslRMIClientSocketFactory(); |
|
167 |
final MySslRMIServerSocketFactory subserver1 = |
|
168 |
new MySslRMIServerSocketFactory(); |
|
169 |
final MySslRMIServerSocketFactory subserver2 = |
|
170 |
new MySslRMIServerSocketFactory(null, |
|
171 |
null, |
|
172 |
false); |
|
173 |
final MySslRMIServerSocketFactory subserver3 = |
|
174 |
new MySslRMIServerSocketFactory(ciphersuite, |
|
175 |
null, |
|
176 |
false); |
|
177 |
final MySslRMIServerSocketFactory subserver4 = |
|
178 |
new MySslRMIServerSocketFactory(null, |
|
179 |
protocol, |
|
180 |
false); |
|
181 |
final MySslRMIServerSocketFactory subserver5 = |
|
182 |
new MySslRMIServerSocketFactory(null, |
|
183 |
null, |
|
184 |
true); |
|
185 |
final MySslRMIServerSocketFactory subserver6 = |
|
186 |
new MySslRMIServerSocketFactory(null, |
|
187 |
ciphersuite, |
|
188 |
null, |
|
189 |
false); |
|
190 |
final MySslRMIServerSocketFactory subserver7 = |
|
191 |
new MySslRMIServerSocketFactory(SSLContext.getDefault(), |
|
192 |
ciphersuite, |
|
193 |
null, |
|
194 |
false); |
|
195 |
final MySslRMIServerSocketFactory subserver8 = |
|
196 |
new MySslRMIServerSocketFactory(context, |
|
197 |
null, |
|
198 |
null, |
|
199 |
true); |
|
200 |
||
201 |
// clients |
|
202 |
System.out.println("testEquals(client1,client1,true)"); |
|
203 |
testEquals(client1,client1,true); |
|
204 |
System.out.println("testEquals(client1,client2,true)"); |
|
205 |
testEquals(client1,client2,true); |
|
206 |
System.out.println("testEquals(client1,client11,true)"); |
|
207 |
testEquals(client1,client11,true); |
|
208 |
System.out.println("testEquals(client1,client21,true)"); |
|
209 |
testEquals(client1,client21,true); |
|
210 |
System.out.println("testEquals(client11,client21,true)"); |
|
211 |
testEquals(client11,client21,true); |
|
212 |
System.out.println("testEquals(client1,null,false)"); |
|
213 |
testEquals(client1,null,false); |
|
214 |
System.out.println("testEquals(client1,server1,false)"); |
|
215 |
testEquals(client1,server1,false); |
|
216 |
System.out.println("testEquals(client21,server2,false)"); |
|
217 |
testEquals(client21,server2,false); |
|
218 |
System.out.println("testEquals(client1,new Object(),false)"); |
|
219 |
testEquals(client1,new Object(),false); |
|
220 |
||
221 |
// servers |
|
222 |
System.out.println("testEquals(server1,server1,true)"); |
|
223 |
testEquals(server1,server1,true); |
|
224 |
System.out.println("testEquals(server2,server2,true)"); |
|
225 |
testEquals(server2,server2,true); |
|
226 |
System.out.println("testEquals(server3,server3,true)"); |
|
227 |
testEquals(server3,server3,true); |
|
228 |
System.out.println("testEquals(server4,server4,true)"); |
|
229 |
testEquals(server4,server4,true); |
|
230 |
System.out.println("testEquals(server5,server5,true)"); |
|
231 |
testEquals(server5,server5,true); |
|
232 |
System.out.println("testEquals(server1,server2,true)"); |
|
233 |
testEquals(server1,server2,true); |
|
234 |
System.out.println("testEquals(server1,server3,false)"); |
|
235 |
testEquals(server1,server3,false); |
|
236 |
System.out.println("testEquals(server2,server3,false)"); |
|
237 |
testEquals(server2,server3,false); |
|
238 |
System.out.println("testEquals(server3,server4,false)"); |
|
239 |
testEquals(server3,server4,false); |
|
240 |
System.out.println("testEquals(server4,server5,false)"); |
|
241 |
testEquals(server4,server5,false); |
|
242 |
System.out.println("testEquals(server6,server7,false)"); |
|
243 |
testEquals(server6,server7,false); |
|
244 |
System.out.println("testEquals(server8,server9,false)"); |
|
245 |
testEquals(server8,server9,false); |
|
246 |
System.out.println("testEquals(server9,server10,false)"); |
|
247 |
testEquals(server9,server10,false); |
|
248 |
System.out.println("testEquals(server2,server6,true)"); |
|
249 |
testEquals(server2,server6,true); |
|
250 |
System.out.println("testEquals(server2,server7,false)"); |
|
251 |
testEquals(server2,server7,false); |
|
252 |
System.out.println("testEquals(server5,server8,true)"); |
|
253 |
testEquals(server5,server8,true); |
|
254 |
System.out.println("testEquals(server5,server9,false)"); |
|
255 |
testEquals(server5,server9,false); |
|
256 |
System.out.println("testEquals(server1,null,false)"); |
|
257 |
testEquals(server1,null,false); |
|
258 |
System.out.println("testEquals(server2,null,false)"); |
|
259 |
testEquals(server2,null,false); |
|
260 |
System.out.println("testEquals(server3,null,false)"); |
|
261 |
testEquals(server3,null,false); |
|
262 |
System.out.println("testEquals(server1,client2,false)"); |
|
263 |
testEquals(server1,client2,false); |
|
264 |
System.out.println("testEquals(server2,client11,false)"); |
|
265 |
testEquals(server2,client11,false); |
|
266 |
System.out.println("testEquals(server1,new Object(),false)"); |
|
267 |
testEquals(server1,new Object(),false); |
|
268 |
||
269 |
// client subclass |
|
270 |
System.out.println("testEquals(subclient1,subclient1,true)"); |
|
271 |
testEquals(subclient1,subclient1,true); |
|
272 |
System.out.println("testEquals(subclient1,subclient2,true)"); |
|
273 |
testEquals(subclient1,subclient2,true); |
|
274 |
System.out.println("testEquals(subclient1,client1,false)"); |
|
275 |
testEquals(subclient1,client1,false); |
|
276 |
System.out.println("testEquals(client1,subclient1,false)"); |
|
277 |
testEquals(client1,subclient1,false); |
|
278 |
System.out.println("testEquals(subclient1,null,false)"); |
|
279 |
testEquals(subclient1,null,false); |
|
280 |
System.out.println("testEquals(subclient1,server1,false)"); |
|
281 |
testEquals(subclient1,server1,false); |
|
282 |
System.out.println("testEquals(server1,subclient1,false)"); |
|
283 |
testEquals(server1,subclient1,false); |
|
284 |
System.out.println("testEquals(subclient2,subserver2,false)"); |
|
285 |
testEquals(subclient1,subserver2,false); |
|
286 |
System.out.println("testEquals(subclient1,new Object(),false)"); |
|
287 |
testEquals(subclient1,new Object(),false); |
|
288 |
||
289 |
// server subclass |
|
290 |
System.out.println("testEquals(subserver1,subserver1,true)"); |
|
291 |
testEquals(subserver1,subserver1,true); |
|
292 |
System.out.println("testEquals(subserver2,subserver2,true)"); |
|
293 |
testEquals(subserver2,subserver2,true); |
|
294 |
System.out.println("testEquals(subserver3,subserver3,true)"); |
|
295 |
testEquals(subserver3,subserver3,true); |
|
296 |
System.out.println("testEquals(subserver4,subserver4,true)"); |
|
297 |
testEquals(subserver4,subserver4,true); |
|
298 |
System.out.println("testEquals(subserver5,subserver5,true)"); |
|
299 |
testEquals(subserver5,subserver5,true); |
|
300 |
System.out.println("testEquals(subserver1,subserver2,true)"); |
|
301 |
testEquals(subserver1,subserver2,true); |
|
302 |
System.out.println("testEquals(subserver1,subserver3,false)"); |
|
303 |
testEquals(subserver1,subserver3,false); |
|
304 |
System.out.println("testEquals(subserver2,subserver3,false)"); |
|
305 |
testEquals(subserver2,subserver3,false); |
|
306 |
System.out.println("testEquals(subserver3,subserver4,false)"); |
|
307 |
testEquals(subserver3,subserver4,false); |
|
308 |
System.out.println("testEquals(subserver4,subserver5,false)"); |
|
309 |
testEquals(subserver4,subserver5,false); |
|
310 |
System.out.println("testEquals(subserver3,subserver6,true)"); |
|
311 |
testEquals(subserver3,subserver6,true); |
|
312 |
System.out.println("testEquals(subserver3,subserver7,false)"); |
|
313 |
testEquals(subserver3,subserver7,false); |
|
314 |
System.out.println("testEquals(subserver1,server1,false)"); |
|
315 |
testEquals(subserver1,server1,false); |
|
316 |
System.out.println("testEquals(server1,subserver1,false)"); |
|
317 |
testEquals(server1,subserver1,false); |
|
318 |
System.out.println("testEquals(subserver2,server2,false)"); |
|
319 |
testEquals(subserver2,server2,false); |
|
320 |
System.out.println("testEquals(server2,subserver2,false)"); |
|
321 |
testEquals(server2,subserver2,false); |
|
322 |
System.out.println("testEquals(subserver3,server3,false)"); |
|
323 |
testEquals(subserver3,server3,false); |
|
324 |
System.out.println("testEquals(server3,subserver3,false)"); |
|
325 |
testEquals(server3,subserver3,false); |
|
326 |
System.out.println("testEquals(subserver4,server4,false)"); |
|
327 |
testEquals(subserver4,server4,false); |
|
328 |
System.out.println("testEquals(server4,subserver4,false)"); |
|
329 |
testEquals(server4,subserver4,false); |
|
330 |
System.out.println("testEquals(subserver5,server5,false)"); |
|
331 |
testEquals(subserver5,server5,false); |
|
332 |
System.out.println("testEquals(server5,subserver5,false)"); |
|
333 |
testEquals(server5,subserver5,false); |
|
334 |
System.out.println("testEquals(server10,subserver8,false)"); |
|
335 |
testEquals(server10,subserver8,false); |
|
336 |
System.out.println("testEquals(subserver8,server10,false)"); |
|
337 |
testEquals(subserver8,server10,false); |
|
338 |
System.out.println("testEquals(subserver1,null,false)"); |
|
339 |
testEquals(subserver1,null,false); |
|
340 |
System.out.println("testEquals(subserver1,client2,false)"); |
|
341 |
testEquals(subserver1,client2,false); |
|
342 |
System.out.println("testEquals(subserver1,subclient2,false)"); |
|
343 |
testEquals(subserver1,subclient2,false); |
|
344 |
System.out.println("testEquals(client1,subserver2,false)"); |
|
345 |
testEquals(client1,subserver2,false); |
|
346 |
System.out.println("testEquals(subserver1,new Object(),false)"); |
|
347 |
testEquals(subserver1,new Object(),false); |
|
348 |
||
349 |
System.out.println("SocketFactoryTest PASSED."); |
|
350 |
} catch (Exception x) { |
|
351 |
System.out.println("SocketFactoryTest FAILED: " + x); |
|
352 |
x.printStackTrace(); |
|
353 |
System.exit(1); |
|
354 |
} |
|
355 |
} |
|
356 |
} |