summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Carlstrom <bdc@google.com>2010-05-04 13:59:40 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-05-04 13:59:40 -0700
commit0ebe2220e2828228b3d9b1003fbc5a47d80872e7 (patch)
tree74cb9c22104d2294d729de06fd9219be83d80e15
parent252299f5206edf81e208f368deef054c464e9d2e (diff)
parent17c744222e249ed5f7ab36e49ed11f9bb062a302 (diff)
downloadlibcore-0ebe2220e2828228b3d9b1003fbc5a47d80872e7.zip
libcore-0ebe2220e2828228b3d9b1003fbc5a47d80872e7.tar.gz
libcore-0ebe2220e2828228b3d9b1003fbc5a47d80872e7.tar.bz2
Merge "Remove workarounds from JSSE tests now that SSLServerSocket.accept no longer tries to handshake" into dalvik-dev
-rw-r--r--luni/src/test/java/javax/net/ssl/SSLSessionContextTest.java27
-rw-r--r--luni/src/test/java/javax/net/ssl/SSLSocketTest.java191
-rw-r--r--support/src/test/java/javax/net/ssl/TestSSLSessions.java2
-rw-r--r--support/src/test/java/javax/net/ssl/TestSSLSocketPair.java22
4 files changed, 69 insertions, 173 deletions
diff --git a/luni/src/test/java/javax/net/ssl/SSLSessionContextTest.java b/luni/src/test/java/javax/net/ssl/SSLSessionContextTest.java
index 7dedc24..cb0f852 100644
--- a/luni/src/test/java/javax/net/ssl/SSLSessionContextTest.java
+++ b/luni/src/test/java/javax/net/ssl/SSLSessionContextTest.java
@@ -35,7 +35,7 @@ public class SSLSessionContextTest extends TestCase {
assertSSLSessionContextSize(0, c.sslContext.getClientSessionContext());
assertSSLSessionContextSize(0, c.sslContext.getServerSessionContext());
- TestSSLSocketPair s = TestSSLSocketPair.create_workaround();
+ TestSSLSocketPair s = TestSSLSocketPair.create();
assertSSLSessionContextSize(1, s.c.sslContext.getClientSessionContext());
if (TestSSLContext.sslServerSocketSupportsSessionTickets()) {
assertSSLSessionContextSize(0, s.c.sslContext.getServerSessionContext());
@@ -66,7 +66,7 @@ public class SSLSessionContextTest extends TestCase {
assertNull(c.sslContext.getClientSessionContext().getSession(new byte[0]));
assertNull(c.sslContext.getClientSessionContext().getSession(new byte[1]));
- TestSSLSocketPair s = TestSSLSocketPair.create_workaround();
+ TestSSLSocketPair s = TestSSLSocketPair.create();
SSLSessionContext client = s.c.sslContext.getClientSessionContext();
SSLSessionContext server = s.c.sslContext.getServerSessionContext();
byte[] clientId = (byte[]) client.getIds().nextElement();
@@ -83,7 +83,7 @@ public class SSLSessionContextTest extends TestCase {
assertEquals(0, c.sslContext.getClientSessionContext().getSessionCacheSize());
assertEquals(0, c.sslContext.getServerSessionContext().getSessionCacheSize());
- TestSSLSocketPair s = TestSSLSocketPair.create_workaround();
+ TestSSLSocketPair s = TestSSLSocketPair.create();
assertEquals(0, s.c.sslContext.getClientSessionContext().getSessionCacheSize());
assertEquals(0, s.c.sslContext.getServerSessionContext().getSessionCacheSize());
}
@@ -109,7 +109,7 @@ public class SSLSessionContextTest extends TestCase {
@KnownFailure("Should return 0 for unlimited, not 10 entries")
public void test_SSLSessionContext_setSessionCacheSize_dynamic() {
- TestSSLSocketPair s = TestSSLSocketPair.create_workaround();
+ TestSSLSocketPair s = TestSSLSocketPair.create();
SSLSessionContext client = s.c.sslContext.getClientSessionContext();
SSLSessionContext server = s.c.sslContext.getServerSessionContext();
assertEquals(0, client.getSessionCacheSize());
@@ -152,12 +152,10 @@ public class SSLSessionContextTest extends TestCase {
*/
assertTrue(uniqueCipherSuites.size() > 5);
- TestSSLSocketPair.connect_workaround(s.c,
- new String[] { uniqueCipherSuites.remove() }); // 1
+ TestSSLSocketPair.connect(s.c, new String[] { uniqueCipherSuites.remove() }); // 1
assertSSLSessionContextSize(2, client);
assertSSLSessionContextSize(2, server);
- TestSSLSocketPair.connect_workaround(s.c,
- new String[] { uniqueCipherSuites.remove() }); // 2
+ TestSSLSocketPair.connect(s.c, new String[] { uniqueCipherSuites.remove() }); // 2
assertSSLSessionContextSize(3, client);
assertSSLSessionContextSize(3, server);
@@ -167,19 +165,16 @@ public class SSLSessionContextTest extends TestCase {
assertEquals(1, server.getSessionCacheSize());
assertSSLSessionContextSize(1, client);
assertSSLSessionContextSize(1, server);
- TestSSLSocketPair.connect_workaround(s.c,
- new String[] { uniqueCipherSuites.remove() }); // 3
+ TestSSLSocketPair.connect(s.c, new String[] { uniqueCipherSuites.remove() }); // 3
assertSSLSessionContextSize(1, client);
assertSSLSessionContextSize(1, server);
client.setSessionCacheSize(2);
server.setSessionCacheSize(2);
- TestSSLSocketPair.connect_workaround(s.c,
- new String[] { uniqueCipherSuites.remove() }); // 4
+ TestSSLSocketPair.connect(s.c, new String[] { uniqueCipherSuites.remove() }); // 4
assertSSLSessionContextSize(2, client);
assertSSLSessionContextSize(2, server);
- TestSSLSocketPair.connect_workaround(s.c,
- new String[] { uniqueCipherSuites.remove() }); // 5
+ TestSSLSocketPair.connect(s.c, new String[] { uniqueCipherSuites.remove() }); // 5
assertSSLSessionContextSize(2, client);
assertSSLSessionContextSize(2, server);
}
@@ -190,7 +185,7 @@ public class SSLSessionContextTest extends TestCase {
assertEquals(86400, c.sslContext.getClientSessionContext().getSessionTimeout());
assertEquals(86400, c.sslContext.getServerSessionContext().getSessionTimeout());
- TestSSLSocketPair s = TestSSLSocketPair.create_workaround();
+ TestSSLSocketPair s = TestSSLSocketPair.create();
assertEquals(86400, s.c.sslContext.getClientSessionContext().getSessionTimeout());
assertEquals(86400, s.c.sslContext.getServerSessionContext().getSessionTimeout());
}
@@ -216,7 +211,7 @@ public class SSLSessionContextTest extends TestCase {
} catch (IllegalArgumentException e) {
}
- TestSSLSocketPair s = TestSSLSocketPair.create_workaround();
+ TestSSLSocketPair s = TestSSLSocketPair.create();
assertSSLSessionContextSize(1, s.c.sslContext.getClientSessionContext());
assertSSLSessionContextSize(1, s.c.sslContext.getServerSessionContext());
Thread.sleep(1 * 1000);
diff --git a/luni/src/test/java/javax/net/ssl/SSLSocketTest.java b/luni/src/test/java/javax/net/ssl/SSLSocketTest.java
index 7c3a8bf..9e2cb63 100644
--- a/luni/src/test/java/javax/net/ssl/SSLSocketTest.java
+++ b/luni/src/test/java/javax/net/ssl/SSLSocketTest.java
@@ -169,7 +169,7 @@ public class SSLSocketTest extends TestCase {
assertFalse(session.isValid());
}
- @KnownFailure("Implementation should not start handshake in ServerSocket.accept")
+ @KnownFailure("local certificates should be null as it should not have been requested by server")
public void test_SSLSocket_startHandshake() throws Exception {
final TestSSLContext c = TestSSLContext.create();
SSLSocket client = (SSLSocket) c.sslContext.getSocketFactory().createSocket(c.host, c.port);
@@ -208,79 +208,27 @@ public class SSLSocketTest extends TestCase {
thread.join();
}
- @KnownFailure("local certificates should be null as it should not have been requested by server")
- public void test_SSLSocket_startHandshake_workaround() throws Exception {
- final TestSSLContext c = TestSSLContext.create();
- Thread thread = new Thread(new Runnable () {
- public void run() {
- try {
- SSLSocket server = (SSLSocket) c.serverSocket.accept();
- server.startHandshake();
- assertNotNull(server.getSession());
- try {
- server.getSession().getPeerCertificates();
- fail();
- } catch (SSLPeerUnverifiedException e) {
- }
- Certificate[] localCertificates = server.getSession().getLocalCertificates();
- assertNotNull(localCertificates);
- assertEquals(1, localCertificates.length);
- assertNotNull(localCertificates[0]);
- assertNotNull(localCertificates[0].equals(c.keyStore.getCertificate(c.privateAlias)));
- } catch (RuntimeException e) {
- throw e;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- });
- thread.start();
- SSLSocket client = (SSLSocket) c.sslContext.getSocketFactory().createSocket(c.host, c.port);
- client.startHandshake();
- assertNotNull(client.getSession());
- assertNull(client.getSession().getLocalCertificates());
- Certificate[] peerCertificates = client.getSession().getPeerCertificates();
- assertNotNull(peerCertificates);
- assertEquals(1, peerCertificates.length);
- assertNotNull(peerCertificates[0]);
- assertNotNull(peerCertificates[0].equals(c.keyStore.getCertificate(c.publicAlias)));
- thread.join();
- }
-
- public void test_SSLSocket_startHandshake_noKeyStore_workaround() throws Exception {
- final TestSSLContext c = TestSSLContext.create(null, null, null, null);
- Thread thread = new Thread(new Runnable () {
- public void run() {
- try {
- c.serverSocket.accept();
- // TODO Fix [Un]Known Failure
- // This fails because accept should throw an
- // SSLException since we have the server no
- // private key to use, but instead it continues.
- fail();
- } catch (SSLException e) {
- } catch (RuntimeException e) {
- throw e;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- });
- thread.start();
+ @KnownFailure("Should throw SSLException from SSLServerSocket.accept with no private key configured")
+ public void test_SSLSocket_startHandshake_noKeyStore() throws Exception {
+ TestSSLContext c = TestSSLContext.create(null, null, null, null);
SSLSocket client = (SSLSocket) c.sslContext.getSocketFactory().createSocket(c.host, c.port);
- thread.join();
+ try {
+ SSLSocket server = (SSLSocket) c.serverSocket.accept();
+ // TODO Fix Known Failure
+ // Need to make SSLServerSocket.accept check if necessary private keys for enabled cipher suites are available
+ fail();
+ } catch (SSLException e) {
+ }
}
- /**
- * Marked workaround because it avoid accepting on main thread like test_SSLSocket_startHandshake_workaround
- */
@KnownFailure("local certificates should be null as it should not have been requested by server")
- public void test_SSLSocket_HandshakeCompletedListener_workaround() throws Exception {
+ public void test_SSLSocket_HandshakeCompletedListener() throws Exception {
final TestSSLContext c = TestSSLContext.create();
+ final SSLSocket client = (SSLSocket) c.sslContext.getSocketFactory().createSocket(c.host, c.port);
+ final SSLSocket server = (SSLSocket) c.serverSocket.accept();
Thread thread = new Thread(new Runnable () {
public void run() {
try {
- SSLSocket server = (SSLSocket) c.serverSocket.accept();
server.startHandshake();
} catch (RuntimeException e) {
throw e;
@@ -290,7 +238,6 @@ public class SSLSocketTest extends TestCase {
}
});
thread.start();
- final SSLSocket client = (SSLSocket) c.sslContext.getSocketFactory().createSocket(c.host, c.port);
final boolean[] handshakeCompletedListenerCalled = new boolean[1];
client.addHandshakeCompletedListener(new HandshakeCompletedListener() {
public void handshakeCompleted(HandshakeCompletedEvent event) {
@@ -394,43 +341,23 @@ public class SSLSocketTest extends TestCase {
}
}
- /**
- * Marked workaround because it avoid accepting on main thread like test_SSLSocket_startHandshake_workaround.
- * Technically this test shouldn't even need a second thread.
- */
- public void test_SSLSocket_getUseClientMode_workaround() throws Exception {
- final TestSSLContext c = TestSSLContext.create();
- Thread thread = new Thread(new Runnable () {
- public void run() {
- try {
- SSLSocket server = (SSLSocket) c.serverSocket.accept();
- assertFalse(server.getUseClientMode());
- } catch (RuntimeException e) {
- throw e;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- });
- thread.start();
+ public void test_SSLSocket_getUseClientMode() throws Exception {
+ TestSSLContext c = TestSSLContext.create();
SSLSocket client = (SSLSocket) c.sslContext.getSocketFactory().createSocket(c.host, c.port);
+ SSLSocket server = (SSLSocket) c.serverSocket.accept();
assertTrue(client.getUseClientMode());
- thread.join();
+ assertFalse(server.getUseClientMode());
}
- /**
- * Marked workaround because it avoid accepting on main thread like test_SSLSocket_startHandshake_workaround.
- * Technically this test shouldn't even need a second thread.
- */
@KnownFailure("This test relies on socket timeouts which are not working. It also fails because SSLException is thrown instead of SSLProtocolException")
- public void test_SSLSocket_setUseClientMode_workaround() throws Exception {
+ public void test_SSLSocket_setUseClientMode() throws Exception {
// client is client, server is server
- test_SSLSocket_setUseClientMode_workaround(true, false);
+ test_SSLSocket_setUseClientMode(true, false);
// client is server, server is client
- test_SSLSocket_setUseClientMode_workaround(true, false);
+ test_SSLSocket_setUseClientMode(true, false);
// both are client
try {
- test_SSLSocket_setUseClientMode_workaround(true, true);
+ test_SSLSocket_setUseClientMode(true, true);
fail();
} catch (SSLProtocolException e) {
// TODO Fix [Un]KnownFailure
@@ -439,22 +366,24 @@ public class SSLSocketTest extends TestCase {
// both are server
try {
- test_SSLSocket_setUseClientMode_workaround(false, false);
+ test_SSLSocket_setUseClientMode(false, false);
fail();
} catch (SocketTimeoutException e) {
}
}
- private void test_SSLSocket_setUseClientMode_workaround(final boolean clientClientMode,
- final boolean serverClientMode)
+ private void test_SSLSocket_setUseClientMode(final boolean clientClientMode,
+ final boolean serverClientMode)
throws Exception {
- final TestSSLContext c = TestSSLContext.create();
+ TestSSLContext c = TestSSLContext.create();
+ SSLSocket client = (SSLSocket) c.sslContext.getSocketFactory().createSocket(c.host, c.port);
+ final SSLSocket server = (SSLSocket) c.serverSocket.accept();
+
final SSLProtocolException[] sslProtocolException = new SSLProtocolException[1];
final SocketTimeoutException[] socketTimeoutException = new SocketTimeoutException[1];
Thread thread = new Thread(new Runnable () {
public void run() {
try {
- SSLSocket server = (SSLSocket) c.serverSocket.accept();
if (!serverClientMode) {
server.setSoTimeout(1 * 1000);
}
@@ -472,7 +401,6 @@ public class SSLSocketTest extends TestCase {
}
});
thread.start();
- SSLSocket client = (SSLSocket) c.sslContext.getSocketFactory().createSocket(c.host, c.port);
if (!clientClientMode) {
client.setSoTimeout(1 * 1000);
}
@@ -487,15 +415,13 @@ public class SSLSocketTest extends TestCase {
}
}
- /**
- * Marked workaround because it avoid accepting on main thread like test_SSLSocket_startHandshake_workaround
- */
- public void test_SSLSocket_clientAuth_workaround() throws Exception {
- final TestSSLContext c = TestSSLContext.create();
+ public void test_SSLSocket_clientAuth() throws Exception {
+ TestSSLContext c = TestSSLContext.create();
+ SSLSocket client = (SSLSocket) c.sslContext.getSocketFactory().createSocket(c.host, c.port);
+ final SSLSocket server = (SSLSocket) c.serverSocket.accept();
Thread thread = new Thread(new Runnable () {
public void run() {
try {
- SSLSocket server = (SSLSocket) c.serverSocket.accept();
assertFalse(server.getWantClientAuth());
assertFalse(server.getNeedClientAuth());
@@ -524,46 +450,27 @@ public class SSLSocketTest extends TestCase {
}
});
thread.start();
- SSLSocket client = (SSLSocket) c.sslContext.getSocketFactory().createSocket(c.host, c.port);
client.startHandshake();
assertNotNull(client.getSession().getLocalCertificates());
assertEquals(1, client.getSession().getLocalCertificates().length);
thread.join();
}
- /**
- * Marked workaround because it avoid accepting on main thread like test_SSLSocket_startHandshake_workaround
- * Technically this test shouldn't even need a second thread.
- */
- public void test_SSLSocket_getEnableSessionCreation_workaround() throws Exception {
- final TestSSLContext c = TestSSLContext.create();
- Thread thread = new Thread(new Runnable () {
- public void run() {
- try {
- SSLSocket server = (SSLSocket) c.serverSocket.accept();
- assertTrue(server.getEnableSessionCreation());
- } catch (RuntimeException e) {
- throw e;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- });
- thread.start();
+ public void test_SSLSocket_getEnableSessionCreation() throws Exception {
+ TestSSLContext c = TestSSLContext.create();
SSLSocket client = (SSLSocket) c.sslContext.getSocketFactory().createSocket(c.host, c.port);
+ SSLSocket server = (SSLSocket) c.serverSocket.accept();
assertTrue(client.getEnableSessionCreation());
- thread.join();
+ assertTrue(server.getEnableSessionCreation());
}
- /**
- * Marked workaround because it avoid accepting on main thread like test_SSLSocket_startHandshake_workaround
- */
- public void test_SSLSocket_setEnableSessionCreation_server_workaround() throws Exception {
- final TestSSLContext c = TestSSLContext.create();
+ public void test_SSLSocket_setEnableSessionCreation_server() throws Exception {
+ TestSSLContext c = TestSSLContext.create();
+ SSLSocket client = (SSLSocket) c.sslContext.getSocketFactory().createSocket(c.host, c.port);
+ final SSLSocket server = (SSLSocket) c.serverSocket.accept();
Thread thread = new Thread(new Runnable () {
public void run() {
try {
- SSLSocket server = (SSLSocket) c.serverSocket.accept();
server.setEnableSessionCreation(false);
try {
server.startHandshake();
@@ -578,7 +485,6 @@ public class SSLSocketTest extends TestCase {
}
});
thread.start();
- SSLSocket client = (SSLSocket) c.sslContext.getSocketFactory().createSocket(c.host, c.port);
try {
client.startHandshake();
fail();
@@ -587,15 +493,13 @@ public class SSLSocketTest extends TestCase {
thread.join();
}
- /**
- * Marked workaround because it avoid accepting on main thread like test_SSLSocket_startHandshake_workaround
- */
- public void test_SSLSocket_setEnableSessionCreation_client_workaround() throws Exception {
- final TestSSLContext c = TestSSLContext.create();
+ public void test_SSLSocket_setEnableSessionCreation_client() throws Exception {
+ TestSSLContext c = TestSSLContext.create();
+ SSLSocket client = (SSLSocket) c.sslContext.getSocketFactory().createSocket(c.host, c.port);
+ final SSLSocket server = (SSLSocket) c.serverSocket.accept();
Thread thread = new Thread(new Runnable () {
public void run() {
try {
- SSLSocket server = (SSLSocket) c.serverSocket.accept();
try {
server.startHandshake();
fail();
@@ -609,7 +513,6 @@ public class SSLSocketTest extends TestCase {
}
});
thread.start();
- SSLSocket client = (SSLSocket) c.sslContext.getSocketFactory().createSocket(c.host, c.port);
client.setEnableSessionCreation(false);
try {
client.startHandshake();
@@ -620,7 +523,7 @@ public class SSLSocketTest extends TestCase {
}
public void test_SSLSocketTest_Test_create() {
- TestSSLSocketPair test = TestSSLSocketPair.create_workaround();
+ TestSSLSocketPair test = TestSSLSocketPair.create();
assertNotNull(test.c);
assertNotNull(test.server);
assertNotNull(test.client);
@@ -637,7 +540,7 @@ public class SSLSocketTest extends TestCase {
public void stress_test_SSLSocketTest_Test_create() {
final boolean verbose = true;
while (true) {
- TestSSLSocketPair test = TestSSLSocketPair.create_workaround();
+ TestSSLSocketPair test = TestSSLSocketPair.create();
if (verbose) {
System.out.println("client=" + test.client.getLocalPort()
+ " server=" + test.server.getLocalPort());
diff --git a/support/src/test/java/javax/net/ssl/TestSSLSessions.java b/support/src/test/java/javax/net/ssl/TestSSLSessions.java
index 061a7f2..23b8ed5 100644
--- a/support/src/test/java/javax/net/ssl/TestSSLSessions.java
+++ b/support/src/test/java/javax/net/ssl/TestSSLSessions.java
@@ -59,7 +59,7 @@ public final class TestSSLSessions {
SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket ssl = (SSLSocket) sf.createSocket();
SSLSession invalid = ssl.getSession();
- TestSSLSocketPair s = TestSSLSocketPair.create_workaround();
+ TestSSLSocketPair s = TestSSLSocketPair.create();
return new TestSSLSessions(invalid, s.server.getSession(), s.client.getSession(), s);
} catch (Exception e) {
throw new RuntimeException(e);
diff --git a/support/src/test/java/javax/net/ssl/TestSSLSocketPair.java b/support/src/test/java/javax/net/ssl/TestSSLSocketPair.java
index 6347877..4409183 100644
--- a/support/src/test/java/javax/net/ssl/TestSSLSocketPair.java
+++ b/support/src/test/java/javax/net/ssl/TestSSLSocketPair.java
@@ -35,12 +35,11 @@ public final class TestSSLSocketPair {
}
/**
- * based on test_SSLSocket_startHandshake_workaround, should
- * be written to non-workaround form when possible
+ * based on test_SSLSocket_startHandshake
*/
- public static TestSSLSocketPair create_workaround () {
+ public static TestSSLSocketPair create () {
TestSSLContext c = TestSSLContext.create();
- SSLSocket[] sockets = connect_workaround(c, null);
+ SSLSocket[] sockets = connect(c, null);
return new TestSSLSocketPair(c, sockets[0], sockets[1]);
}
@@ -49,15 +48,16 @@ public final class TestSSLSocketPair {
* existing SSLContext. Optional clientCipherSuites allows
* forcing new SSLSession to test SSLSessionContext caching
*/
- public static SSLSocket[] connect_workaround (final TestSSLContext c,
- String[] clientCipherSuites) {
+ public static SSLSocket[] connect (final TestSSLContext c,
+ String[] clientCipherSuites) {
try {
- final SSLSocket[] server = new SSLSocket[1];
+ SSLSocket client = (SSLSocket)
+ c.sslContext.getSocketFactory().createSocket(c.host, c.port);
+ final SSLSocket server = (SSLSocket) c.serverSocket.accept();
Thread thread = new Thread(new Runnable () {
public void run() {
try {
- server[0] = (SSLSocket) c.serverSocket.accept();
- server[0].startHandshake();
+ server.startHandshake();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
@@ -66,14 +66,12 @@ public final class TestSSLSocketPair {
}
});
thread.start();
- SSLSocket client = (SSLSocket)
- c.sslContext.getSocketFactory().createSocket(c.host, c.port);
if (clientCipherSuites != null) {
client.setEnabledCipherSuites(clientCipherSuites);
}
client.startHandshake();
thread.join();
- return new SSLSocket[] { server[0], client };
+ return new SSLSocket[] { server, client };
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {