Skip to content

Commit b2a2ddf

Browse files
Evan WhelanRob McKenna
authored andcommitted
8262438: sun/security/ssl/SSLLogger/LoggingFormatConsistency.java failed with "SocketException: Socket is closed"
Reviewed-by: rhalade
1 parent c8c0234 commit b2a2ddf

File tree

1 file changed

+7
-62
lines changed

1 file changed

+7
-62
lines changed

test/jdk/sun/security/ssl/SSLLogger/LoggingFormatConsistency.java

Lines changed: 7 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,7 @@
3838
import jdk.test.lib.process.ProcessTools;
3939
import jdk.test.lib.security.SecurityUtils;
4040

41-
import javax.net.ssl.HostnameVerifier;
42-
import javax.net.ssl.HttpsURLConnection;
43-
import javax.net.ssl.SSLSession;
44-
import javax.net.ssl.SSLSocket;
45-
import java.io.BufferedReader;
46-
import java.io.DataOutputStream;
47-
import java.io.IOException;
48-
import java.io.InputStreamReader;
4941
import java.net.InetAddress;
50-
import java.net.URL;
51-
52-
import static java.nio.charset.StandardCharsets.UTF_8;
5342

5443
public class LoggingFormatConsistency extends SSLSocketTemplate {
5544

@@ -89,63 +78,19 @@ public static void main(String[] args) throws Exception {
8978
"LoggingFormatConsistency",
9079
"runTest"); // Ensuring args.length is greater than 0 when test JVM starts
9180

81+
output.asLines()
82+
.stream()
83+
.filter(line -> line.startsWith("Connecting to"))
84+
.forEach(System.out::println); // prints connection info from test jvm output
85+
9286
if (output.getExitValue() != 0) {
93-
throw new RuntimeException("Test JVM process failed. JVM stderr= " + output.getStderr());
87+
output.asLines().forEach(System.out::println);
88+
throw new RuntimeException("Test JVM process failed");
9489
}
9590

9691
output.shouldContain(expectedTLSVersion);
9792
output.shouldNotContain(incorrectTLSVersion);
9893
}
9994
}
10095
}
101-
102-
@Override
103-
protected boolean isCustomizedClientConnection() { return true; }
104-
105-
@Override
106-
protected void runServerApplication(SSLSocket socket) throws Exception {
107-
var response = "Hello World!";
108-
var out = new DataOutputStream(socket.getOutputStream());
109-
try {
110-
// We don't need to process the data from the socket
111-
// Simply sending a response right away is sufficient
112-
// to generate the desired debug output
113-
var responseBytes = response.getBytes(UTF_8);
114-
115-
out.writeBytes("HTTP/1.0 200 OK\r\n");
116-
out.writeBytes("Content-Length: " + responseBytes.length + "\r\n");
117-
out.writeBytes("Content-Type: text/html\r\n\r\n");
118-
out.write(responseBytes);
119-
out.flush();
120-
} catch (IOException e) {
121-
out.writeBytes("HTTP/1.0 400 " + e.getMessage() + "\r\n");
122-
out.writeBytes("Content-Type: text/html\r\n\r\n");
123-
out.flush();
124-
}
125-
}
126-
127-
@Override
128-
protected void runClientApplication(int serverPort) throws Exception {
129-
var context = createClientSSLContext();
130-
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
131-
HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier());
132-
133-
var host = serverAddress == null ? "localhost" : serverAddress.getHostAddress();
134-
var url = new URL("https://" + host + ":" + serverPort + "/");
135-
var httpsConnection = (HttpsURLConnection) url.openConnection();
136-
httpsConnection.disconnect();
137-
try (var in = new BufferedReader(new InputStreamReader(httpsConnection.getInputStream()))) {
138-
// Getting the input stream from the BufferedReader is sufficient to generate the desired debug output
139-
// We don't need to process the data
140-
} catch (IOException e) {
141-
throw new RuntimeException(e);
142-
}
143-
}
144-
145-
private static class NameVerifier implements HostnameVerifier {
146-
@Override
147-
public boolean verify(String s, SSLSession sslSession) {
148-
return true;
149-
}
150-
}
15196
}

0 commit comments

Comments
 (0)