From 8068ea8daa37ac1e4d55c2ebd15bf9dda3d7891e Mon Sep 17 00:00:00 2001 From: Huahui Wu Date: Mon, 19 Apr 2010 18:05:17 -0400 Subject: [PATCH] Update the ssl test so the client reads something from the server. This is needed when cut-through feature is needed as in b/2586347. Dr. No approved in http://b/issue?id=2511073 . Change-Id: Id84724873522fe0435dbda342616da02783f7d6b --- .../javax/net/ssl/HandshakeCompletedEventTest.java | 45 ++++++++++++++++------ .../tests/api/javax/net/ssl/SSLSessionTest.java | 22 ++++++++--- 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/libcore/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedEventTest.java b/libcore/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedEventTest.java index fa36d0c96..aebde6bd1 100644 --- a/libcore/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedEventTest.java +++ b/libcore/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedEventTest.java @@ -500,8 +500,8 @@ public class HandshakeCompletedEventTest extends TestCase { /** * Implements a test SSL socket server. It wait for a connection on a given - * port, requests client authentication (if specified), and read 256 bytes - * from the socket. + * port, requests client authentication (if specified), reads 256 bytes + * from the socket, and writes 256 bytes to the socket. */ class TestServer implements Runnable { @@ -551,16 +551,26 @@ public class HandshakeCompletedEventTest extends TestCase { SSLSocket clientSocket = (SSLSocket)serverSocket.accept(); - InputStream stream = clientSocket.getInputStream(); + InputStream istream = clientSocket.getInputStream(); for (int i = 0; i < 256; i++) { - int j = stream.read(); + int j = istream.read(); if (i != j) { throw new RuntimeException("Error reading socket, expected " + i + ", got " + j); } } - stream.close(); + istream.close(); + + OutputStream ostream = clientSocket.getOutputStream(); + + for (int i = 0; i < 256; i++) { + ostream.write(i); + } + + ostream.flush(); + ostream.close(); + clientSocket.close(); serverSocket.close(); @@ -581,7 +591,8 @@ public class HandshakeCompletedEventTest extends TestCase { /** * Implements a test SSL socket client. It open a connection to localhost on - * a given port and writes 256 bytes to the socket. + * a given port, writes 256 bytes to the socket, and reads 256 bytes from the + * socket. */ class TestClient implements Runnable { @@ -614,14 +625,26 @@ public class HandshakeCompletedEventTest extends TestCase { socket.addHandshakeCompletedListener(listener); socket.startHandshake(); - OutputStream stream = socket.getOutputStream(); + OutputStream ostream = socket.getOutputStream(); for (int i = 0; i < 256; i++) { - stream.write(i); + ostream.write(i); } - stream.flush(); - stream.close(); + ostream.flush(); + ostream.close(); + + InputStream istream = socket.getInputStream(); + + for (int i = 0; i < 256; i++) { + int j = istream.read(); + if (i != j) { + throw new RuntimeException("Error reading socket, expected " + i + ", got " + j); + } + } + + istream.close(); + socket.close(); } catch (Exception ex) { @@ -649,7 +672,7 @@ public class HandshakeCompletedEventTest extends TestCase { KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(inputStream, PASSWORD.toCharArray()); inputStream.close(); - + String algorithm = KeyManagerFactory.getDefaultAlgorithm(); KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(algorithm); keyManagerFactory.init(keyStore, PASSWORD.toCharArray()); diff --git a/libcore/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionTest.java b/libcore/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionTest.java index 430d11710..384084fc1 100644 --- a/libcore/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionTest.java +++ b/libcore/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionTest.java @@ -706,8 +706,8 @@ public class SSLSessionTest extends TestCase { /** * Implements a test SSL socket server. It waits for a connection on a given - * port, requests client authentication (if specified), and reads - * from the socket. + * port, requests client authentication (if specified), reads from the socket, + * and writes to the socket. */ class TestServer implements Runnable { @@ -761,8 +761,16 @@ public class SSLSessionTest extends TestCase { SSLSocket clientSocket = (SSLSocket)serverSocket.accept(); + InputStream istream = clientSocket.getInputStream(); + byte[] buffer = new byte[1024]; + istream.read(buffer); + + OutputStream ostream = clientSocket.getOutputStream(); + ostream.write(testData.getBytes()); + ostream.flush(); + while (notFinished) { - clientSocket.getInputStream().read(); + Thread.currentThread().sleep(500); } clientSocket.close(); @@ -788,8 +796,8 @@ public class SSLSessionTest extends TestCase { } /** - * Implements a test SSL socket client. It open a connection to localhost on - * a given port and writes to the socket. + * Implements a test SSL socket client. It opens a connection to localhost on + * a given port, writes to the socket, and reads from the socket. */ class TestClient implements Runnable { @@ -826,6 +834,10 @@ public class SSLSessionTest extends TestCase { ostream.write(testData.getBytes()); ostream.flush(); + InputStream istream = socket.getInputStream(); + byte[] buffer = new byte[1024]; + istream.read(buffer); + clientSession = socket.getSession(); while (notFinished) { Thread.currentThread().sleep(500); -- 2.11.0