提交 f4b0beeb 编写于 作者: X xuelei

8001569: Regression test GetPeerHost uses static port number

Reviewed-by: weijun
上级 fe336b37
/* /*
* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -21,13 +21,15 @@ ...@@ -21,13 +21,15 @@
* questions. * questions.
*/ */
//
// SunJSSE does not support dynamic system properties, no way to re-use
// system properties in samevm/agentvm mode.
//
/** /**
* @test * @test
* @bug 4302026 * @bug 4302026
* @run main/othervm GetPeerHost * @run main/othervm GetPeerHost
*
* SunJSSE does not support dynamic system properties, no way to re-use
* system properties in samevm/agentvm mode.
* @summary make sure the server side doesn't do DNS lookup. * @summary make sure the server side doesn't do DNS lookup.
*/ */
import javax.net.*; import javax.net.*;
...@@ -41,7 +43,8 @@ public class GetPeerHost { ...@@ -41,7 +43,8 @@ public class GetPeerHost {
+ "/../../../../../../../etc/truststore"); + "/../../../../../../../etc/truststore");
GetPeerHostServer server = new GetPeerHostServer(); GetPeerHostServer server = new GetPeerHostServer();
server.start(); server.start();
GetPeerHostClient client = new GetPeerHostClient(); GetPeerHostClient client =
new GetPeerHostClient(server.getServerPort());
client.start(); client.start();
server.join (); server.join ();
if (!server.getPassStatus ()) { if (!server.getPassStatus ()) {
......
/* /*
* Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -38,13 +38,13 @@ class GetPeerHostClient extends Thread ...@@ -38,13 +38,13 @@ class GetPeerHostClient extends Thread
SSLSocket s; SSLSocket s;
String server; String server;
public GetPeerHostClient () public GetPeerHostClient (int serverPort)
{ {
try { try {
SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory
.getDefault(); .getDefault();
server = InetAddress.getLocalHost().getHostName(); server = InetAddress.getLocalHost().getHostName();
s = (SSLSocket) factory.createSocket(server, 9999); s = (SSLSocket) factory.createSocket(server, serverPort);
System.out.println("CLIENT: connected to the server- " + server); System.out.println("CLIENT: connected to the server- " + server);
} catch (Exception e) { } catch (Exception e) {
System.err.println("Unexpected exceptions: " + e); System.err.println("Unexpected exceptions: " + e);
......
/* /*
* Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -42,6 +42,7 @@ class GetPeerHostServer extends Thread ...@@ -42,6 +42,7 @@ class GetPeerHostServer extends Thread
private String host; private String host;
ServerSocket ss; ServerSocket ss;
boolean isHostIPAddr = false; boolean isHostIPAddr = false;
int serverPort = 0;
public GetPeerHostServer () public GetPeerHostServer ()
{ {
...@@ -57,7 +58,8 @@ class GetPeerHostServer extends Thread ...@@ -57,7 +58,8 @@ class GetPeerHostServer extends Thread
kmf.init(ks, passphrase); kmf.init(ks, passphrase);
ctx.init(kmf.getKeyManagers(), null, null); ctx.init(kmf.getKeyManagers(), null, null);
ServerSocketFactory ssf = ctx.getServerSocketFactory(); ServerSocketFactory ssf = ctx.getServerSocketFactory();
ss = ssf.createServerSocket(9999); ss = ssf.createServerSocket(serverPort);
serverPort = ss.getLocalPort();
}catch (Exception e) { }catch (Exception e) {
System.err.println("Unexpected exceptions: " + e); System.err.println("Unexpected exceptions: " + e);
e.printStackTrace(); e.printStackTrace();
...@@ -90,4 +92,8 @@ class GetPeerHostServer extends Thread ...@@ -90,4 +92,8 @@ class GetPeerHostServer extends Thread
boolean getPassStatus () { boolean getPassStatus () {
return isHostIPAddr; return isHostIPAddr;
} }
int getServerPort() {
return serverPort;
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册