8001569: Regression test GetPeerHost uses static port number

Reviewed-by: weijun
This commit is contained in:
Xue-Lei Andrew Fan 2012-11-09 01:15:04 -08:00
parent fdfd7968f7
commit d0e329751f
3 changed files with 19 additions and 10 deletions

View File

@ -1,5 +1,5 @@
/*
* 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.
*
* This code is free software; you can redistribute it and/or modify it
@ -21,13 +21,15 @@
* questions.
*/
//
// SunJSSE does not support dynamic system properties, no way to re-use
// system properties in samevm/agentvm mode.
//
/**
* @test
* @bug 4302026
* @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.
*/
import javax.net.*;
@ -41,7 +43,8 @@ public class GetPeerHost {
+ "/../../../../../../../etc/truststore");
GetPeerHostServer server = new GetPeerHostServer();
server.start();
GetPeerHostClient client = new GetPeerHostClient();
GetPeerHostClient client =
new GetPeerHostClient(server.getServerPort());
client.start();
server.join ();
if (!server.getPassStatus ()) {

View File

@ -1,5 +1,5 @@
/*
* 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.
*
* This code is free software; you can redistribute it and/or modify it
@ -38,13 +38,13 @@ class GetPeerHostClient extends Thread
SSLSocket s;
String server;
public GetPeerHostClient ()
public GetPeerHostClient (int serverPort)
{
try {
SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory
.getDefault();
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);
} catch (Exception e) {
System.err.println("Unexpected exceptions: " + e);

View File

@ -1,5 +1,5 @@
/*
* 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.
*
* This code is free software; you can redistribute it and/or modify it
@ -42,6 +42,7 @@ class GetPeerHostServer extends Thread
private String host;
ServerSocket ss;
boolean isHostIPAddr = false;
int serverPort = 0;
public GetPeerHostServer ()
{
@ -57,7 +58,8 @@ class GetPeerHostServer extends Thread
kmf.init(ks, passphrase);
ctx.init(kmf.getKeyManagers(), null, null);
ServerSocketFactory ssf = ctx.getServerSocketFactory();
ss = ssf.createServerSocket(9999);
ss = ssf.createServerSocket(serverPort);
serverPort = ss.getLocalPort();
}catch (Exception e) {
System.err.println("Unexpected exceptions: " + e);
e.printStackTrace();
@ -90,4 +92,8 @@ class GetPeerHostServer extends Thread
boolean getPassStatus () {
return isHostIPAddr;
}
int getServerPort() {
return serverPort;
}
}