diff options
author | Kenny Root <kroot@google.com> | 2014-04-25 23:58:32 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-04-25 23:58:32 +0000 |
commit | edbc606d8ff8a32d17f26da4d4fbfbe8e2363955 (patch) | |
tree | 5b76bb0b6f120392c884db4fcfb28c3773e8cce7 | |
parent | 0bdee7bb93a4e2450850b2f8c36c0c242cfdc4a4 (diff) | |
parent | b330a5e324ef8d399f12db82b4bf472859815faf (diff) | |
download | libcore-edbc606d8ff8a32d17f26da4d4fbfbe8e2363955.zip libcore-edbc606d8ff8a32d17f26da4d4fbfbe8e2363955.tar.gz libcore-edbc606d8ff8a32d17f26da4d4fbfbe8e2363955.tar.bz2 |
Merge "SSLEngine: update harmony tests"
-rw-r--r-- | harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLEngineTest.java | 658 |
1 files changed, 193 insertions, 465 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLEngineTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLEngineTest.java index 30a1a9c..31f5881 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLEngineTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLEngineTest.java @@ -28,23 +28,21 @@ import java.security.NoSuchAlgorithmException; import java.util.Arrays; import java.util.HashSet; import java.util.Set; - import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngineResult; +import javax.net.ssl.SSLEngineResult.Status; import javax.net.ssl.SSLException; import javax.net.ssl.SSLEngineResult.HandshakeStatus; - import junit.framework.TestCase; -import dalvik.annotation.AndroidOnly; -import dalvik.annotation.KnownFailure; - +import libcore.java.security.StandardNames; /** * Tests for SSLEngine class * */ public class SSLEngineTest extends TestCase { + private static final int MAX_TLS_RECORD_SIZE = 32768; private HandshakeHandler clientEngine; private HandshakeHandler serverEngine; @@ -56,9 +54,8 @@ public class SSLEngineTest extends TestCase { /** * Test for <code>SSLEngine()</code> constructor Assertion: creates * SSLEngine object with null host and -1 port - * @throws NoSuchAlgorithmException */ - public void test_Constructor() throws NoSuchAlgorithmException { + public void test_Constructor() throws Exception { SSLEngine e = getEngine(); assertNull(e.getPeerHost()); assertEquals(-1, e.getPeerPort()); @@ -69,41 +66,31 @@ public class SSLEngineTest extends TestCase { /** * Test for <code>SSLEngine(String host, int port)</code> constructor - * @throws NoSuchAlgorithmException */ - public void test_ConstructorLjava_lang_StringI01() throws NoSuchAlgorithmException { + public void test_ConstructorLjava_lang_StringI01() throws Exception { int port = 1010; SSLEngine e = getEngine(null, port); assertNull(e.getPeerHost()); assertEquals(e.getPeerPort(), port); try { e.beginHandshake(); - } catch (IllegalStateException ex) { - // expected - } catch (SSLException ex) { - fail("unexpected SSLException was thrown."); + fail("should throw IllegalStateException"); + } catch (IllegalStateException expected) { } + e = getEngine(null, port); e.setUseClientMode(true); - try { - e.beginHandshake(); - } catch (SSLException ex) { - // expected - } + e.beginHandshake(); + e = getEngine(null, port); e.setUseClientMode(false); - try { - e.beginHandshake(); - } catch (SSLException ex) { - // expected - } + e.beginHandshake(); } /** * Test for <code>SSLEngine(String host, int port)</code> constructor - * @throws NoSuchAlgorithmException */ - public void test_ConstructorLjava_lang_StringI02() throws NoSuchAlgorithmException { + public void test_ConstructorLjava_lang_StringI02() throws Exception { String host = "new host"; int port = 8080; SSLEngine e = getEngine(host, port); @@ -118,9 +105,8 @@ public class SSLEngineTest extends TestCase { /** * Test for <code>getPeerHost()</code> method - * @throws NoSuchAlgorithmException */ - public void test_getPeerHost() throws NoSuchAlgorithmException { + public void test_getPeerHost() throws Exception { SSLEngine e = getEngine(); assertNull(e.getPeerHost()); e = getEngine("www.fortify.net", 80); @@ -129,9 +115,8 @@ public class SSLEngineTest extends TestCase { /** * Test for <code>getPeerPort()</code> method - * @throws NoSuchAlgorithmException */ - public void test_getPeerPort() throws NoSuchAlgorithmException { + public void test_getPeerPort() throws Exception { SSLEngine e = getEngine(); assertEquals("Incorrect default value of peer port", -1 ,e.getPeerPort()); @@ -139,92 +124,72 @@ public class SSLEngineTest extends TestCase { assertEquals("Incorrect peer port", 80, e.getPeerPort()); } - /** - * @throws NoSuchAlgorithmException - * javax.net.ssl.SSLEngine#getSupportedProtocols() - */ - public void test_getSupportedProtocols() throws NoSuchAlgorithmException { + public void test_getSupportedProtocols() throws Exception { SSLEngine sse = getEngine(); - try { - String[] res = sse.getSupportedProtocols(); - assertNotNull(res); - assertTrue(res.length > 0); - } catch (Exception ex) { - fail("Unexpected exception " + ex); - } + + String[] res = sse.getSupportedProtocols(); + assertNotNull(res); + assertTrue(res.length > 0); } /** - * @throws NoSuchAlgorithmException * javax.net.ssl.SSLEngine#setEnabledProtocols(String[] protocols) * javax.net.ssl.SSLEngine#getEnabledProtocols() */ - public void test_EnabledProtocols() throws NoSuchAlgorithmException { + public void test_EnabledProtocols() throws Exception { SSLEngine sse = getEngine(); String[] pr = sse.getSupportedProtocols(); - try { - sse.setEnabledProtocols(pr); - String[] res = sse.getEnabledProtocols(); - assertNotNull("Null array was returned", res); - assertEquals("Incorrect array length", res.length, pr.length); - assertTrue("Incorrect array was returned", Arrays.equals(res, pr)); - } catch (Exception ex) { - fail("Unexpected exception " + ex); - } + + sse.setEnabledProtocols(pr); + String[] res = sse.getEnabledProtocols(); + assertNotNull("Null array was returned", res); + assertEquals("Incorrect array length", res.length, pr.length); + assertTrue("Incorrect array was returned", Arrays.equals(res, pr)); + try { sse.setEnabledProtocols(null); fail("IllegalArgumentException wasn't thrown"); - } catch (IllegalArgumentException iae) { - //expected + } catch (IllegalArgumentException expected) { } } /** - * @throws NoSuchAlgorithmException * javax.net.ssl.SSLEngine#getSupportedCipherSuites() */ - public void test_getSupportedCipherSuites() throws NoSuchAlgorithmException { + public void test_getSupportedCipherSuites() throws Exception { SSLEngine sse = getEngine(); - try { - String[] res = sse.getSupportedCipherSuites(); - assertNotNull(res); - assertTrue(res.length > 0); - } catch (Exception ex) { - fail("Unexpected exception " + ex); - } + + String[] res = sse.getSupportedCipherSuites(); + assertNotNull(res); + assertTrue(res.length > 0); } /** - * @throws NoSuchAlgorithmException * javax.net.ssl.SSLEngine#setEnabledCipherSuites(String[] suites) * javax.net.ssl.SSLEngine#getEnabledCipherSuites() */ - public void test_EnabledCipherSuites() throws NoSuchAlgorithmException { + public void test_EnabledCipherSuites() throws Exception { SSLEngine sse = getEngine(); String[] st = sse.getSupportedCipherSuites(); - try { - sse.setEnabledCipherSuites(st); - String[] res = sse.getEnabledCipherSuites(); - assertNotNull("Null array was returned", res); - assertEquals("Incorrect array length", res.length, st.length); - assertTrue("Incorrect array was returned", Arrays.equals(res, st)); - } catch (Exception ex) { - fail("Unexpected exception " + ex); - } + + sse.setEnabledCipherSuites(st); + String[] res = sse.getEnabledCipherSuites(); + assertNotNull("Null array was returned", res); + assertEquals("Incorrect array length", res.length, st.length); + assertTrue("Incorrect array was returned", Arrays.equals(res, st)); + try { sse.setEnabledCipherSuites(null); fail("IllegalArgumentException wasn't thrown"); - } catch (IllegalArgumentException iae) { - //expected + } catch (IllegalArgumentException expected) { } } /** - * @throws NoSuchAlgorithmException * javax.net.ssl.SSLEngine#setEnableSessionCreation(boolean flag) * javax.net.ssl.SSLEngine#getEnableSessionCreation() */ - public void test_EnableSessionCreation() throws NoSuchAlgorithmException { + public void test_EnableSessionCreation() throws Exception { SSLEngine sse = getEngine(); try { assertTrue(sse.getEnableSessionCreation()); @@ -238,11 +203,10 @@ public class SSLEngineTest extends TestCase { } /** - * @throws NoSuchAlgorithmException * javax.net.ssl.SSLEngine#setNeedClientAuth(boolean need) * javax.net.ssl.SSLEngine#getNeedClientAuth() */ - public void test_NeedClientAuth() throws NoSuchAlgorithmException { + public void test_NeedClientAuth() throws Exception { SSLEngine sse = getEngine(); try { sse.setNeedClientAuth(false); @@ -255,137 +219,92 @@ public class SSLEngineTest extends TestCase { } /** - * @throws NoSuchAlgorithmException * javax.net.ssl.SSLEngine#setWantClientAuth(boolean want) * javax.net.ssl.SSLEngine#getWantClientAuth() */ - public void test_WantClientAuth() throws NoSuchAlgorithmException { + public void test_WantClientAuth() throws Exception { SSLEngine sse = getEngine(); - try { - sse.setWantClientAuth(false); - assertFalse(sse.getWantClientAuth()); - sse.setWantClientAuth(true); - assertTrue(sse.getWantClientAuth()); - } catch (Exception ex) { - fail("Unexpected exception " + ex); - } + sse.setWantClientAuth(false); + assertFalse(sse.getWantClientAuth()); + sse.setWantClientAuth(true); + assertTrue(sse.getWantClientAuth()); } /** - * @throws NoSuchAlgorithmException * javax.net.ssl.SSLEngine#beginHandshake() */ - public void test_beginHandshake() throws NoSuchAlgorithmException { + public void test_beginHandshake() throws Exception { SSLEngine sse = getEngine(); try { sse.beginHandshake(); fail("IllegalStateException wasn't thrown"); - } catch (IllegalStateException se) { - //expected - } catch (Exception e) { - fail(e + " was thrown instead of IllegalStateException"); + } catch (IllegalStateException expected) { } sse = getEngine("new host", 1080); try { sse.beginHandshake(); fail("IllegalStateException wasn't thrown"); - } catch (IllegalStateException ise) { - //expected - } catch (Exception e) { - fail(e + " was thrown instead of IllegalStateException"); + } catch (IllegalStateException expected) { } sse = getEngine(); - try { - sse.setUseClientMode(true); - sse.beginHandshake(); - } catch (Exception ex) { - fail("Unexpected exception " + ex); - } + sse.setUseClientMode(true); + sse.beginHandshake(); } /** - * @throws NoSuchAlgorithmException * javax.net.ssl.SSLEngine#setUseClientMode(boolean mode) * javax.net.ssl.SSLEngine#getUseClientMode() */ - @AndroidOnly("The RI doesn't throw the expected IllegalStateException.") - public void test_UseClientMode() throws NoSuchAlgorithmException { + public void test_UseClientMode() throws Exception { SSLEngine sse = getEngine(); - try { - sse.setUseClientMode(false); - assertFalse(sse.getUseClientMode()); - sse.setUseClientMode(true); - assertTrue(sse.getUseClientMode()); - } catch (Exception ex) { - fail("Unexpected exception " + ex); - } + sse.setUseClientMode(false); + assertFalse(sse.getUseClientMode()); + sse.setUseClientMode(true); + assertTrue(sse.getUseClientMode()); + sse = getEngine(null, 1080); + sse.setUseClientMode(true); + sse.beginHandshake(); try { - sse = getEngine(null, 1080); - sse.setUseClientMode(true); - sse.beginHandshake(); - try { - sse.setUseClientMode(false); - fail("IllegalArgumentException was not thrown"); - } catch (IllegalArgumentException iae) { - //expected - } - } catch (Exception ex) { - fail("Unexpected exception " + ex); + sse.setUseClientMode(false); + fail("IllegalArgumentException was not thrown"); + } catch (IllegalArgumentException expected) { } } /** - * @throws NoSuchAlgorithmException * javax.net.ssl.SSLEngine#getSession() */ - public void test_getSession() throws NoSuchAlgorithmException { + public void test_getSession() throws Exception { SSLEngine sse = getEngine(); - try { - assertNotNull(sse.getSession()); - } catch (Exception ex) { - fail("Unexpected exception " + ex); - } + assertNotNull(sse.getSession()); } /** - * @throws NoSuchAlgorithmException * javax.net.ssl.SSLEngine#getHandshakeStatus() */ - public void test_getHandshakeStatus() throws NoSuchAlgorithmException { + public void test_getHandshakeStatus() throws Exception { SSLEngine sse = getEngine(); - try { - assertEquals(sse.getHandshakeStatus().toString(), "NOT_HANDSHAKING"); - sse.setUseClientMode(true); - sse.beginHandshake(); - assertEquals(sse.getHandshakeStatus().toString(), "NEED_WRAP"); - } catch (Exception ex) { - fail("Unexpected exception " + ex); - } + assertEquals(sse.getHandshakeStatus().toString(), "NOT_HANDSHAKING"); + sse.setUseClientMode(true); + sse.beginHandshake(); + assertEquals(sse.getHandshakeStatus().toString(), "NEED_WRAP"); } /** - * @throws NoSuchAlgorithmException * javax.net.ssl.SSLEngine#getDelegatedTask() */ - @KnownFailure("com.android.org.conscrypt.SSLEngineImpl#getDelegatedTask() throws NPE instead of returning null") - public void test_getDelegatedTask() throws NoSuchAlgorithmException { + public void test_getDelegatedTask() throws Exception { SSLEngine sse = getEngine(); - try { - assertNull(sse.getDelegatedTask()); - } catch (Exception ex) { - fail("Unexpected exception " + ex); - } + assertNull(sse.getDelegatedTask()); } /** - * @throws IOException - * @throws InterruptedException * javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts, * int offset, int length) * Exception case: SSLException should be thrown. */ - public void test_unwrap_01() throws IOException, InterruptedException { + public void test_unwrap_01() throws Exception { prepareEngines(); doHandshake(); @@ -394,8 +313,7 @@ public class SSLEngineTest extends TestCase { try { clientEngine.engine.unwrap(bbs, new ByteBuffer[] { bbd }, 0, 1); fail("SSLException wasn't thrown"); - } catch (SSLException ex) { - //expected + } catch (SSLException expected) { } } @@ -404,8 +322,7 @@ public class SSLEngineTest extends TestCase { * int offset, int length) * Exception case: IndexOutOfBoundsException should be thrown. */ - @KnownFailure("Fixed in DonutBurger, boundary checks missing") - public void test_unwrap_02() throws SSLException { + public void test_unwrap_02() throws Exception { String host = "new host"; int port = 8080; ByteBuffer[] bbA = { ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100) }; @@ -417,26 +334,22 @@ public class SSLEngineTest extends TestCase { try { sse.unwrap(bb, bbA, -1, 3); fail("IndexOutOfBoundsException wasn't thrown"); - } catch (IndexOutOfBoundsException iobe) { - //expected + } catch (IndexOutOfBoundsException expected) { } try { sse.unwrap(bb, bbA, 0, -3); fail("IndexOutOfBoundsException wasn't thrown"); - } catch (IndexOutOfBoundsException iobe) { - //expected + } catch (IndexOutOfBoundsException expected) { } try { sse.unwrap(bb, bbA, bbA.length + 1, bbA.length); fail("IndexOutOfBoundsException wasn't thrown"); - } catch (IndexOutOfBoundsException iobe) { - //expected + } catch (IndexOutOfBoundsException expected) { } try { sse.unwrap(bb, bbA, 0, bbA.length + 1); fail("IndexOutOfBoundsException wasn't thrown"); - } catch (IndexOutOfBoundsException iobe) { - //expected + } catch (IndexOutOfBoundsException expected) { } } @@ -445,8 +358,7 @@ public class SSLEngineTest extends TestCase { * int offset, int length) * Exception case: ReadOnlyBufferException should be thrown. */ - @KnownFailure("Fixed on DonutBurger, Wrong Exception thrown") - public void test_unwrap_03() { + public void test_unwrap_03() throws Exception { String host = "new host"; int port = 8080; ByteBuffer bbR = ByteBuffer.allocate(100).asReadOnlyBuffer(); @@ -459,10 +371,7 @@ public class SSLEngineTest extends TestCase { try { sse.unwrap(bb, bbA, 0, bbA.length); fail("ReadOnlyBufferException wasn't thrown"); - } catch (ReadOnlyBufferException iobe) { - //expected - } catch (Exception e) { - fail(e + " was thrown instead of ReadOnlyBufferException"); + } catch (ReadOnlyBufferException expected) { } } @@ -471,8 +380,7 @@ public class SSLEngineTest extends TestCase { * int offset, int length) * Exception case: IllegalArgumentException should be thrown. */ - @KnownFailure("Fixed on DonutBurger, Wrong Exception thrown") - public void test_unwrap_04() { + public void test_unwrap_04() throws Exception { String host = "new host"; int port = 8080; ByteBuffer[] bbA = {ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100)}; @@ -486,40 +394,23 @@ public class SSLEngineTest extends TestCase { try { sse.unwrap(bN, bbA, 0, 3); fail("IllegalArgumentException wasn't thrown"); - } catch (IllegalArgumentException iobe) { - //expected - } catch (NullPointerException npe) { - } catch (Exception e) { - fail(e + " was thrown instead of IllegalArgumentException"); + } catch (IllegalArgumentException expected) { } try { sse.unwrap(bb, bbAN, 0, 3); fail("IllegalArgumentException wasn't thrown"); - } catch (IllegalArgumentException iobe) { - //expected - } catch (NullPointerException npe) { - } catch (Exception e) { - fail(e + " was thrown instead of IllegalArgumentException"); + } catch (IllegalArgumentException expected) { } try { sse.unwrap(bb, bbN, 0, 0); fail("IllegalArgumentException wasn't thrown"); - } catch (IllegalArgumentException iobe) { - //expected - } catch (NullPointerException npe) { - } catch (Exception e) { - fail(e + " was thrown instead of IllegalArgumentException"); + } catch (IllegalArgumentException expected) { } try { sse.unwrap(bN, bbN, 0, 0); fail("IllegalArgumentException wasn't thrown"); - } catch (IllegalArgumentException iobe) { - //expected - } catch (NullPointerException npe) { - } catch (Exception e) { - fail(e + " was thrown instead of IllegalArgumentException"); + } catch (IllegalArgumentException expected) { } - } /** @@ -527,8 +418,7 @@ public class SSLEngineTest extends TestCase { * int offset, int length) * Exception case: IllegalStateException should be thrown. */ - @AndroidOnly("The RI doesn't throw the IllegalStateException.") - public void test_unwrap_05() { + public void test_unwrap_05() throws Exception { String host = "new host"; int port = 8080; ByteBuffer[] bbA = { ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100) }; @@ -537,12 +427,9 @@ public class SSLEngineTest extends TestCase { SSLEngine sse = getEngine(host, port); try { - sse.unwrap(bb, bbA, 0, bbA.length); + SSLEngineResult result = sse.unwrap(bb, bbA, 0, bbA.length); fail("IllegalStateException wasn't thrown"); - } catch (IllegalStateException iobe) { - //expected - } catch (Exception e) { - fail(e + " was thrown instead of IllegalStateException"); + } catch (IllegalStateException expected) { } } @@ -550,7 +437,7 @@ public class SSLEngineTest extends TestCase { * javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts, * int offset, int length) */ - public void test_unwrap_06() { + public void test_unwrap_06() throws Exception { String host = "new host"; int port = 8080; ByteBuffer[] bbA = { ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100) }; @@ -559,20 +446,16 @@ public class SSLEngineTest extends TestCase { SSLEngine sse = getEngine(host, port); sse.setUseClientMode(true); - try { - SSLEngineResult res = sse.unwrap(bb, bbA, 0, bbA.length); - assertEquals(0, res.bytesConsumed()); - assertEquals(0, res.bytesProduced()); - } catch (Exception ex) { - fail("Unexpected exception: " + ex); - } + SSLEngineResult res = sse.unwrap(bb, bbA, 0, bbA.length); + assertEquals(0, res.bytesConsumed()); + assertEquals(0, res.bytesProduced()); } - public void test_wrap_01() throws IOException, InterruptedException { + public void test_wrap_01() throws Exception { prepareEngines(); doHandshake(); ByteBuffer bbs = ByteBuffer.allocate(100); - ByteBuffer bbd = ByteBuffer.allocate(20000); + ByteBuffer bbd = ByteBuffer.allocate(MAX_TLS_RECORD_SIZE); clientEngine.engine.wrap(new ByteBuffer[] { bbs }, 0, 1, bbd); } @@ -581,8 +464,7 @@ public class SSLEngineTest extends TestCase { * int length, ByteBuffer dst) * Exception case: IndexOutOfBoundsException should be thrown. */ - @KnownFailure("Fixed in DonutBurger, boundary checks missing") - public void test_wrap_02() throws SSLException { + public void test_wrap_02() throws Exception { String host = "new host"; int port = 8080; ByteBuffer bb = ByteBuffer.allocate(10); @@ -593,26 +475,22 @@ public class SSLEngineTest extends TestCase { try { sse.wrap(bbA, -1, 3, bb); fail("IndexOutOfBoundsException wasn't thrown"); - } catch (IndexOutOfBoundsException iobe) { - //expected + } catch (IndexOutOfBoundsException expected) { } try { sse.wrap(bbA, 0, -3, bb); fail("IndexOutOfBoundsException wasn't thrown"); - } catch (IndexOutOfBoundsException iobe) { - //expected + } catch (IndexOutOfBoundsException expected) { } try { sse.wrap(bbA, bbA.length + 1, bbA.length, bb); fail("IndexOutOfBoundsException wasn't thrown"); - } catch (IndexOutOfBoundsException iobe) { - //expected + } catch (IndexOutOfBoundsException expected) { } try { sse.wrap(bbA, 0, bbA.length + 1, bb); fail("IndexOutOfBoundsException wasn't thrown"); - } catch (IndexOutOfBoundsException iobe) { - //expected + } catch (IndexOutOfBoundsException expected) { } } @@ -621,10 +499,10 @@ public class SSLEngineTest extends TestCase { * int length, ByteBuffer dst) * Exception case: ReadOnlyBufferException should be thrown. */ - public void test_wrap_03() throws SSLException { + public void test_wrap_03() throws Exception { String host = "new host"; int port = 8080; - ByteBuffer bb = ByteBuffer.allocate(10).asReadOnlyBuffer(); + ByteBuffer bb = ByteBuffer.allocate(MAX_TLS_RECORD_SIZE).asReadOnlyBuffer(); ByteBuffer[] bbA = {ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5)}; SSLEngine sse = getEngine(host, port); sse.setUseClientMode(true); @@ -632,8 +510,7 @@ public class SSLEngineTest extends TestCase { try { sse.wrap(bbA, 0, bbA.length, bb); fail("ReadOnlyBufferException wasn't thrown"); - } catch (ReadOnlyBufferException iobe) { - //expected + } catch (ReadOnlyBufferException expected) { } } @@ -642,8 +519,7 @@ public class SSLEngineTest extends TestCase { * int length, ByteBuffer dst) * Exception case: IllegalArgumentException should be thrown. */ - @KnownFailure("Fixed on DonutBurger, Wrong Exception thrown") - public void test_wrap_04() { + public void test_wrap_04() throws Exception { String host = "new host"; int port = 8080; ByteBuffer[] bbA = {ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100)}; @@ -655,19 +531,13 @@ public class SSLEngineTest extends TestCase { try { e.wrap(bbA, 0, 3, bN); fail("IllegalArgumentException must be thrown for null srcs byte buffer array"); - } catch (NullPointerException npe) { } catch (IllegalArgumentException ex) { - } catch (Exception ex) { - fail(ex + " was thrown instead of IllegalArgumentException"); } try { e.wrap(bbN, 0, 0, bN); fail("IllegalArgumentException wasn't thrown"); } catch (IllegalArgumentException ex) { - } catch (NullPointerException npe) { - } catch (Exception ex) { - fail(ex + " was thrown instead of IllegalArgumentException"); } } @@ -676,19 +546,17 @@ public class SSLEngineTest extends TestCase { * int length, ByteBuffer dst) * Exception case: IllegalStateException should be thrown. */ - @AndroidOnly("The RI doesn't throw the IllegalStateException.") - public void test_wrap_05() throws SSLException { + public void test_wrap_05() throws Exception { String host = "new host"; int port = 8080; - ByteBuffer bb = ByteBuffer.allocate(10); + ByteBuffer bb = ByteBuffer.allocate(MAX_TLS_RECORD_SIZE); ByteBuffer[] bbA = {ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5)}; SSLEngine sse = getEngine(host, port); try { - sse.wrap(bbA, 0, bbA.length, bb); - fail("IllegalStateException wasn't thrown"); - } catch (IllegalStateException iobe) { - //expected + SSLEngineResult result = sse.wrap(bbA, 0, bbA.length, bb); + fail("Should fail since mode not set yet"); + } catch (IllegalStateException expected) { } } @@ -696,60 +564,49 @@ public class SSLEngineTest extends TestCase { * javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, int offset, * int length, ByteBuffer dst) */ - public void test_wrap_06() { + public void test_wrap_06() throws Exception { String host = "new host"; int port = 8080; - ByteBuffer bb = ByteBuffer.allocate(10); + ByteBuffer bb = ByteBuffer.allocate(MAX_TLS_RECORD_SIZE); ByteBuffer[] bbA = {ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5)}; SSLEngine sse = getEngine(host, port); sse.setUseClientMode(true); - try { - sse.wrap(bbA, 0, bbA.length, bb); - } catch (Exception ex) { - fail("Unexpected exception: " + ex); - } + SSLEngineResult result = sse.wrap(bbA, 0, bbA.length, bb); + assertEquals(SSLEngineResult.Status.OK, result.getStatus()); + assertEquals(0, result.bytesConsumed()); + assertTrue(result.bytesProduced() > 0); } /** - * @throws NoSuchAlgorithmException * javax.net.ssl.SSLEngine#closeOutbound() * javax.net.ssl.SSLEngine#isOutboundDone() */ - public void test_closeOutbound() throws NoSuchAlgorithmException { + public void test_closeOutbound() throws Exception { SSLEngine sse = getEngine(); - try { - assertFalse(sse.isOutboundDone()); - sse.closeOutbound(); - assertTrue(sse.isOutboundDone()); - } catch (Exception ex) { - fail("Unexpected exception: " + ex); - } + assertFalse(sse.isOutboundDone()); + sse.closeOutbound(); + assertTrue(sse.isOutboundDone()); } /** - * @throws NoSuchAlgorithmException * javax.net.ssl.SSLEngine#closeInbound() * javax.net.ssl.SSLEngine#isInboundDone() */ - public void test_closeInbound() throws NoSuchAlgorithmException { + public void test_closeInbound() throws Exception { SSLEngine sse = getEngine(); - try { - assertFalse(sse.isInboundDone()); - sse.closeInbound(); - assertTrue(sse.isInboundDone()); - } catch (Exception ex) { - fail("Unexpected exception: " + ex); - } + assertFalse(sse.isInboundDone()); + sse.closeInbound(); + assertTrue(sse.isInboundDone()); } /** * javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer dst) * SSLException should be thrown. */ - public void test_unwrap_ByteBuffer_ByteBuffer_01() throws InterruptedException, IOException { + public void test_unwrap_ByteBuffer_ByteBuffer_01() throws Exception { prepareEngines(); doHandshake(); ByteBuffer bbs = ByteBuffer.allocate(100); @@ -767,8 +624,7 @@ public class SSLEngineTest extends TestCase { * javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer dst) * ReadOnlyBufferException should be thrown. */ - @KnownFailure("Fixed on DonutBurger, Wrong Exception thrown") - public void test_unwrap_ByteBuffer_ByteBuffer_02() { + public void test_unwrap_ByteBuffer_ByteBuffer_02() throws Exception { String host = "new host"; int port = 8080; ByteBuffer bbs = ByteBuffer.allocate(10); @@ -790,8 +646,7 @@ public class SSLEngineTest extends TestCase { * javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer dst) * IllegalArgumentException should be thrown. */ - @KnownFailure("Fixed on DonutBurger, Wrong Exception thrown") - public void test_unwrap_ByteBuffer_ByteBuffer_03() { + public void test_unwrap_ByteBuffer_ByteBuffer_03() throws Exception { String host = "new host"; int port = 8080; ByteBuffer bbsN = null; @@ -804,31 +659,19 @@ public class SSLEngineTest extends TestCase { try { sse.unwrap(bbsN, bbd); fail("IllegalArgumentException wasn't thrown"); - } catch (IllegalArgumentException iae) { - //expected - } catch (NullPointerException npe) { - } catch (Exception e) { - fail(e + " was thrown instead of IllegalArgumentException"); + } catch (IllegalArgumentException expected) { } try { sse.unwrap(bbs, bbdN); fail("IllegalArgumentException wasn't thrown"); - } catch (IllegalArgumentException iae) { - //expected - } catch (NullPointerException npe) { - } catch (Exception e) { - fail(e + " was thrown instead of IllegalArgumentException"); + } catch (IllegalArgumentException expected) { } try { sse.unwrap(bbsN, bbdN); fail("IllegalArgumentException wasn't thrown"); - } catch (IllegalArgumentException iae) { - //expected - } catch (NullPointerException npe) { - } catch (Exception e) { - fail(e + " was thrown instead of IllegalArgumentException"); + } catch (IllegalArgumentException expected) { } } @@ -836,8 +679,7 @@ public class SSLEngineTest extends TestCase { * javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer dst) * IllegalStateException should be thrown. */ - @AndroidOnly("The RI doesn't throw the IllegalStateException.") - public void test_unwrap_ByteBuffer_ByteBuffer_04() { + public void test_unwrap_ByteBuffer_ByteBuffer_04() throws Exception { String host = "new host"; int port = 8080; ByteBuffer bbs = ByteBuffer.allocate(10); @@ -847,17 +689,14 @@ public class SSLEngineTest extends TestCase { try { sse.unwrap(bbs, bbd); fail("IllegalStateException wasn't thrown"); - } catch (IllegalStateException iobe) { - //expected - } catch (Exception e) { - fail(e + " was thrown instead of IllegalStateException"); + } catch (IllegalStateException expected) { } } /** * javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer dst) */ - public void test_unwrap_ByteBuffer_ByteBuffer_05() { + public void test_unwrap_ByteBuffer_ByteBuffer_05() throws Exception { String host = "new host"; int port = 8080; ByteBuffer bbs = ByteBuffer.allocate(10); @@ -865,20 +704,16 @@ public class SSLEngineTest extends TestCase { SSLEngine sse = getEngine(host, port); sse.setUseClientMode(true); - try { - SSLEngineResult res = sse.unwrap(bbs, bbd); - assertEquals(0, res.bytesConsumed()); - assertEquals(0, res.bytesProduced()); - } catch (Exception e) { - fail("Unexpected exception: " + e); - } + SSLEngineResult res = sse.unwrap(bbs, bbd); + assertEquals(0, res.bytesConsumed()); + assertEquals(0, res.bytesProduced()); } /** * javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts) * SSLException should be thrown. */ - public void test_unwrap_ByteBuffer$ByteBuffer_01() throws IOException, InterruptedException { + public void test_unwrap_ByteBuffer$ByteBuffer_01() throws Exception { prepareEngines(); doHandshake(); @@ -888,8 +723,7 @@ public class SSLEngineTest extends TestCase { try { clientEngine.engine.unwrap(bbs, new ByteBuffer[] { bbd }); fail("SSLException wasn't thrown"); - } catch (SSLException ex) { - //expected + } catch (SSLException expected) { } } @@ -897,8 +731,7 @@ public class SSLEngineTest extends TestCase { * javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts) * ReadOnlyBufferException should be thrown. */ - @KnownFailure("Fixed on DonutBurger, Wrong Exception thrown") - public void test_unwrap_ByteBuffer$ByteBuffer_02() { + public void test_unwrap_ByteBuffer$ByteBuffer_02() throws Exception { String host = "new host"; int port = 8080; ByteBuffer bbs = ByteBuffer.allocate(10); @@ -910,10 +743,7 @@ public class SSLEngineTest extends TestCase { try { sse.unwrap(bbs, bbA); fail("ReadOnlyBufferException wasn't thrown"); - } catch (ReadOnlyBufferException iobe) { - //expected - } catch (Exception e) { - fail(e + " was thrown instead of ReadOnlyBufferException"); + } catch (ReadOnlyBufferException expected) { } } @@ -921,8 +751,7 @@ public class SSLEngineTest extends TestCase { * javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts) * IllegalArgumentException should be thrown. */ - @KnownFailure("Fixed on DonutBurger, Wrong Exception thrown") - public void test_unwrap_ByteBuffer$ByteBuffer_03() { + public void test_unwrap_ByteBuffer$ByteBuffer_03() throws Exception { String host = "new host"; int port = 8080; ByteBuffer[] bbA = { ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100) }; @@ -936,41 +765,25 @@ public class SSLEngineTest extends TestCase { try { sse.unwrap(bN, bbA); fail("IllegalArgumentException wasn't thrown"); - } catch (IllegalArgumentException iobe) { - //expected - } catch (NullPointerException npe) { - } catch (Exception e) { - fail(e + " was thrown instead of IllegalArgumentException"); + } catch (IllegalArgumentException expected) { } try { sse.unwrap(bb, bbAN); fail("IllegalArgumentException wasn't thrown"); - } catch (IllegalArgumentException iobe) { - //expected - } catch (NullPointerException npe) { - } catch (Exception e) { - fail(e + " was thrown instead of IllegalArgumentException"); + } catch (IllegalArgumentException expected) { } try { sse.unwrap(bb, bbN); fail("IllegalArgumentException wasn't thrown"); - } catch (IllegalArgumentException iobe) { - //expected - } catch (NullPointerException npe) { - } catch (Exception e) { - fail(e + " was thrown instead of IllegalArgumentException"); + } catch (IllegalArgumentException expected) { } try { sse.unwrap(bN, bbAN); fail("IllegalArgumentException wasn't thrown"); - } catch (IllegalArgumentException iobe) { - //expected - } catch (NullPointerException npe) { - } catch (Exception e) { - fail(e + " was thrown instead of IllegalArgumentException"); + } catch (IllegalArgumentException expected) { } } @@ -978,8 +791,7 @@ public class SSLEngineTest extends TestCase { * javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts) * IllegalStateException should be thrown. */ - @AndroidOnly("The RI doesn't throw the IllegalStateException.") - public void test_unwrap_ByteBuffer$ByteBuffer_04() { + public void test_unwrap_ByteBuffer$ByteBuffer_04() throws Exception { String host = "new host"; int port = 8080; ByteBuffer bbs = ByteBuffer.allocate(10); @@ -989,17 +801,14 @@ public class SSLEngineTest extends TestCase { try { sse.unwrap(bbs, bbd); fail("IllegalStateException wasn't thrown"); - } catch (IllegalStateException iobe) { - //expected - } catch (Exception e) { - fail(e + " was thrown instead of IllegalStateException"); + } catch (IllegalStateException expected) { } } /** * javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts) */ - public void test_unwrap_ByteBuffer$ByteBuffer_05() { + public void test_unwrap_ByteBuffer$ByteBuffer_05() throws Exception { String host = "new host"; int port = 8080; ByteBuffer bbs = ByteBuffer.allocate(10); @@ -1007,16 +816,12 @@ public class SSLEngineTest extends TestCase { SSLEngine sse = getEngine(host, port); sse.setUseClientMode(true); - try { - SSLEngineResult res = sse.unwrap(bbs, bbd); - assertEquals(0, res.bytesConsumed()); - assertEquals(0, res.bytesProduced()); - } catch (Exception ex) { - fail("Unexpected exception: " + ex); - } + SSLEngineResult res = sse.unwrap(bbs, bbd); + assertEquals(0, res.bytesConsumed()); + assertEquals(0, res.bytesProduced()); } - public void test_wrap_ByteBuffer_ByteBuffer_01() throws IOException, InterruptedException { + public void test_wrap_ByteBuffer_ByteBuffer_01() throws Exception { prepareEngines(); doHandshake(); ByteBuffer bbs = ByteBuffer.allocate(20); @@ -1028,7 +833,7 @@ public class SSLEngineTest extends TestCase { * javax.net.ssl.SSLEngine#wrap(ByteBuffer src, ByteBuffer dst) * ReadOnlyBufferException should be thrown. */ - public void test_wrap_ByteBuffer_ByteBuffer_02() { + public void test_wrap_ByteBuffer_ByteBuffer_02() throws Exception { String host = "new host"; int port = 8080; ByteBuffer bbs = ByteBuffer.allocate(10); @@ -1039,10 +844,7 @@ public class SSLEngineTest extends TestCase { try { sse.wrap(bbs, bbd); fail("ReadOnlyBufferException wasn't thrown"); - } catch (ReadOnlyBufferException iobe) { - //expected - } catch (Exception e) { - fail(e + " was thrown instead of ReadOnlyBufferException"); + } catch (ReadOnlyBufferException expected) { } } @@ -1050,8 +852,7 @@ public class SSLEngineTest extends TestCase { * javax.net.ssl.SSLEngine#wrap(ByteBuffer src, ByteBuffer dst) * IllegalArgumentException should be thrown. */ - @KnownFailure("Fixed on DonutBurger, Wrong Exception thrown") - public void test_wrap_ByteBuffer_ByteBuffer_03() { + public void test_wrap_ByteBuffer_ByteBuffer_03() throws Exception { String host = "new host"; int port = 8080; ByteBuffer bbsN = null; @@ -1064,31 +865,19 @@ public class SSLEngineTest extends TestCase { try { sse.wrap(bbsN, bbd); fail("IllegalArgumentException wasn't thrown"); - } catch (IllegalArgumentException iae) { - //expected - } catch (NullPointerException npe) { - } catch (Exception e) { - fail(e + " was thrown instead of IllegalArgumentException"); + } catch (IllegalArgumentException expected) { } try { sse.wrap(bbs, bbdN); fail("IllegalArgumentException wasn't thrown"); - } catch (IllegalArgumentException iae) { - //expected - } catch (NullPointerException npe) { - } catch (Exception e) { - fail(e + " was thrown instead of IllegalArgumentException"); + } catch (IllegalArgumentException expected) { } try { sse.wrap(bbsN, bbdN); fail("IllegalArgumentException wasn't thrown"); - } catch (IllegalArgumentException iae) { - //expected - } catch (NullPointerException npe) { - } catch (Exception e) { - fail(e + " was thrown instead of IllegalArgumentException"); + } catch (IllegalArgumentException expected) { } } @@ -1096,8 +885,7 @@ public class SSLEngineTest extends TestCase { * javax.net.ssl.SSLEngine#wrap(ByteBuffer src, ByteBuffer dst) * IllegalStateException should be thrown. */ - @AndroidOnly("The RI doesn't throw the IllegalStateException.") - public void test_wrap_ByteBuffer_ByteBuffer_04() { + public void test_wrap_ByteBuffer_ByteBuffer_04() throws Exception { String host = "new host"; int port = 8080; ByteBuffer bbs = ByteBuffer.allocate(10); @@ -1105,60 +893,46 @@ public class SSLEngineTest extends TestCase { SSLEngine sse = getEngine(host, port); try { - sse.wrap(bbs, bbd); - fail("IllegalStateException wasn't thrown"); - } catch (IllegalStateException iobe) { - //expected - } catch (Exception e) { - fail(e + " was thrown instead of IllegalStateException"); + SSLEngineResult result = sse.wrap(bbs, bbd); + } catch (IllegalStateException expected) { } } /** * javax.net.ssl.SSLEngine#wrap(ByteBuffer src, ByteBuffer dst) */ - public void test_wrap_ByteBuffer_ByteBuffer_05() { + public void test_wrap_ByteBuffer_ByteBuffer_05() throws Exception { String host = "new host"; int port = 8080; ByteBuffer bb = ByteBuffer.allocate(10); SSLEngine sse = getEngine(host, port); sse.setUseClientMode(true); - try { - SSLEngineResult res = sse.wrap(bb, ByteBuffer.allocate(10)); - assertEquals(0, res.bytesConsumed()); - assertEquals(0, res.bytesProduced()); - } catch (Exception e) { - fail("Unexpected exception: " + e); - } + SSLEngineResult res = sse.wrap(bb, ByteBuffer.allocate(10)); + assertEquals(Status.BUFFER_OVERFLOW, res.getStatus()); + assertEquals(0, res.bytesConsumed()); + assertEquals(0, res.bytesProduced()); } /** - * @throws IOException - * @throws InterruptedException * javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, ByteBuffer dst) * SSLException should be thrown. */ - public void test_wrap_ByteBuffer$ByteBuffer_01() throws IOException, InterruptedException { + public void test_wrap_ByteBuffer$ByteBuffer_01() throws Exception { prepareEngines(); doHandshake(); ByteBuffer bbs = ByteBuffer.allocate(100); ByteBuffer bbd = ByteBuffer.allocate(20000); - try { - clientEngine.engine.wrap(new ByteBuffer[] { bbs }, bbd); - serverEngine.engine.wrap(new ByteBuffer[] { bbs }, bbd); - //fail("SSLException wasn't thrown"); - } catch (SSLException ex) { - //expected - } + clientEngine.engine.wrap(new ByteBuffer[] { bbs }, bbd); + serverEngine.engine.wrap(new ByteBuffer[] { bbs }, bbd); } /** * javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, ByteBuffer dst) * ReadOnlyBufferException should be thrown. */ - public void test_wrap_ByteBuffer$ByteBuffer_02() { + public void test_wrap_ByteBuffer$ByteBuffer_02() throws Exception { String host = "new host"; int port = 8080; ByteBuffer bb = ByteBuffer.allocate(10).asReadOnlyBuffer(); @@ -1169,10 +943,7 @@ public class SSLEngineTest extends TestCase { try { sse.wrap(bbA, bb); fail("ReadOnlyBufferException wasn't thrown"); - } catch (ReadOnlyBufferException iobe) { - //expected - } catch (Exception e) { - fail(e + " was thrown instead of ReadOnlyBufferException"); + } catch (ReadOnlyBufferException expected) { } } @@ -1180,8 +951,7 @@ public class SSLEngineTest extends TestCase { * javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, ByteBuffer dst) * IllegalArgumentException should be thrown. */ - @KnownFailure("Fixed on DonutBurger, Wrong Exception thrown") - public void test_wrap_ByteBuffer$ByteBuffer_03() { + public void test_wrap_ByteBuffer$ByteBuffer_03() throws Exception { String host = "new host"; int port = 8080; ByteBuffer[] bbA = {ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100)}; @@ -1194,31 +964,19 @@ public class SSLEngineTest extends TestCase { try { sse.wrap(bbA, bN); fail("IllegalArgumentException wasn't thrown"); - } catch (IllegalArgumentException iobe) { - //expected - } catch (NullPointerException npe) { - } catch (Exception e) { - fail(e + " was thrown instead of IllegalArgumentException"); + } catch (IllegalArgumentException expected) { } try { sse.wrap(bbAN, bb); fail("IllegalArgumentException wasn't thrown"); - } catch (IllegalArgumentException iobe) { - //expected - } catch (NullPointerException npe) { - } catch (Exception e) { - fail(e + " was thrown instead of IllegalArgumentException"); + } catch (IllegalArgumentException expected) { } try { sse.wrap(bbAN, bN); fail("IllegalArgumentException wasn't thrown"); - } catch (IllegalArgumentException iobe) { - //expected - } catch (NullPointerException npe) { - } catch (Exception e) { - fail(e + " was thrown instead of IllegalArgumentException"); + } catch (IllegalArgumentException expected) { } } @@ -1226,69 +984,42 @@ public class SSLEngineTest extends TestCase { * javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, ByteBuffer dst) * IllegalStateException should be thrown. */ - @AndroidOnly("The RI doesn't throw the IllegalStateException.") - public void test_wrap_ByteBuffer$ByteBuffer_04() { + public void test_wrap_ByteBuffer$ByteBuffer_04() throws Exception { String host = "new host"; int port = 8080; ByteBuffer bb = ByteBuffer.allocate(10); ByteBuffer[] bbA = { ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5) }; SSLEngine sse = getEngine(host, port); - try { - sse.wrap(bbA, bb); - fail("IllegalStateException wasn't thrown"); - } catch (IllegalStateException iobe) { - //expected - } catch (Exception e) { - fail(e + " was thrown instead of IllegalStateException"); - } + SSLEngineResult result = sse.wrap(bbA, bb); + assertEquals(Status.BUFFER_OVERFLOW, result.getStatus()); } /** * javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, ByteBuffer dst) */ - public void test_wrap_ByteBuffer$ByteBuffer_05() { + public void test_wrap_ByteBuffer$ByteBuffer_05() throws Exception { String host = "new host"; int port = 8080; - ByteBuffer bb = ByteBuffer.allocate(10); + ByteBuffer bb = ByteBuffer.allocate(2000); ByteBuffer[] bbA = { ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5) }; SSLEngine sse = getEngine(host, port); sse.setUseClientMode(true); - try { - SSLEngineResult res = sse.wrap(bbA, bb); - assertEquals(0, res.bytesConsumed()); - assertEquals(0, res.bytesProduced()); - } catch (Exception ex) { - fail("Unexpected exception: " + ex); - } + SSLEngineResult res = sse.wrap(bbA, bb); + assertEquals(0, res.bytesConsumed()); + assertEquals(0, res.bytesProduced()); } - private SSLEngine getEngine() { - SSLContext context = null; - try { - context = SSLContext.getInstance("TLS"); - context.init(null, null, null); - } catch (KeyManagementException e) { - fail("Could not get SSLEngine: key management exception " - + e.getMessage()); - } catch (NoSuchAlgorithmException e) { - fail("Could not get SSLEngine: no such algorithm " + e.getMessage()); - } + private SSLEngine getEngine() throws Exception { + SSLContext context = SSLContext.getInstance("TLS"); + context.init(null, null, null); return context.createSSLEngine(); } - private SSLEngine getEngine(String host, int port) { - SSLContext context = null; - try { - context = SSLContext.getInstance("TLS"); - context.init(null, null, null); - } catch (KeyManagementException e) { - fail("Could not get SSLEngine: key management exception " - + e.getMessage()); - } catch (NoSuchAlgorithmException e) { - fail("Could not get SSLEngine: no such algorithm " + e.getMessage()); - } + private SSLEngine getEngine(String host, int port) throws Exception { + SSLContext context = SSLContext.getInstance("TLS"); + context.init(null, null, null); return context.createSSLEngine(host, port); } @@ -1311,8 +1042,7 @@ public class SSLEngineTest extends TestCase { private ByteBuffer writeBuffer; - HandshakeHandler(boolean clientMode, SourceChannel in, SinkChannel out) - throws SSLException { + HandshakeHandler(boolean clientMode, SourceChannel in, SinkChannel out) throws Exception { this.in = in; this.out = out; engine = getEngine(); @@ -1424,9 +1154,7 @@ public class SSLEngineTest extends TestCase { } } - @KnownFailure("Handshake Status is never finished. NPE in " - + "ClientSessionContext$HostAndPort.hashCode() when host is null") - public void testHandshake() throws IOException, InterruptedException { + public void testHandshake() throws Exception { prepareEngines(); @@ -1442,7 +1170,7 @@ public class SSLEngineTest extends TestCase { serverEngine.getStatus()); } - void prepareEngines() throws IOException { + void prepareEngines() throws Exception { Pipe clientSendPipe = Pipe.open(); Pipe serverSendPipe = Pipe.open(); |