aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Vartanian <flooey@google.com>2018-02-21 14:11:16 +0000
committerJP Sugarbroad <jpsugar@google.com>2018-03-15 13:03:19 -0700
commit51a02601436ef9736aeed808806acb59c8634a88 (patch)
tree5f21b80cd9b77d2f0f47793baf55448724ddf2ea
parent6b815ed6cde82df78ed12a60e4b9acfcc3fe9412 (diff)
downloadlibcore-51a02601436ef9736aeed808806acb59c8634a88.tar.gz
DO NOT MERGE Add test for calling SSLEngine with multiple inputs.
Bug: 73251618 Test: cts -m CtsLibcoreTestCases -t libcore.javax.net.ssl Change-Id: I021ef1bd21d9046e132111221d8f7e94b7e83a4d (cherry picked from commit 95c2d02257246e0b87f38efc56fa325a94388c32)
-rw-r--r--luni/src/test/java/libcore/javax/net/ssl/SSLEngineTest.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/luni/src/test/java/libcore/javax/net/ssl/SSLEngineTest.java b/luni/src/test/java/libcore/javax/net/ssl/SSLEngineTest.java
index d9a7b4fadc8..a4d3e5f4c02 100644
--- a/luni/src/test/java/libcore/javax/net/ssl/SSLEngineTest.java
+++ b/luni/src/test/java/libcore/javax/net/ssl/SSLEngineTest.java
@@ -317,9 +317,49 @@ public class SSLEngineTest extends TestCase {
assertEquals(sourceCipherSuite, 2, numUnwrapCalls);
} else {
assertEquals(sourceCipherSuite, 1, numUnwrapCalls);
+ assertSendsCorrectlyWhenSplit(sourceBytes, source, dest);
}
}
+ private static void assertSendsCorrectlyWhenSplit(final byte[] sourceBytes, SSLEngine source,
+ SSLEngine dest) throws SSLException {
+ // Split the input into three to test the version that accepts ByteBuffer[]. Three
+ // is chosen somewhat arbitrarily as a number larger than the minimum of 2 but small
+ // enough that it's not unwieldy.
+ ByteBuffer[] sourceBufs = new ByteBuffer[3];
+ int sourceLen = sourceBytes.length;
+ sourceBufs[0] = ByteBuffer.wrap(sourceBytes, 0, sourceLen / 3);
+ sourceBufs[1] = ByteBuffer.wrap(sourceBytes, sourceLen / 3, sourceLen / 3);
+ sourceBufs[2] = ByteBuffer.wrap(
+ sourceBytes, 2 * (sourceLen / 3), sourceLen - 2 * (sourceLen / 3));
+ SSLSession sourceSession = source.getSession();
+ ByteBuffer sourceToDest = ByteBuffer.allocate(sourceSession.getPacketBufferSize());
+ SSLEngineResult sourceOutRes = source.wrap(sourceBufs, sourceToDest);
+ sourceToDest.flip();
+
+ String sourceCipherSuite = source.getSession().getCipherSuite();
+ assertEquals(sourceCipherSuite, sourceBytes.length, sourceOutRes.bytesConsumed());
+ assertEquals(sourceCipherSuite, HandshakeStatus.NOT_HANDSHAKING,
+ sourceOutRes.getHandshakeStatus());
+
+ SSLSession destSession = dest.getSession();
+ ByteBuffer destIn = ByteBuffer.allocate(destSession.getApplicationBufferSize());
+
+ int numUnwrapCalls = 0;
+ while (destIn.position() != sourceBytes.length) {
+ SSLEngineResult destRes = dest.unwrap(sourceToDest, destIn);
+ assertEquals(sourceCipherSuite, HandshakeStatus.NOT_HANDSHAKING,
+ destRes.getHandshakeStatus());
+ numUnwrapCalls++;
+ }
+
+ destIn.flip();
+ byte[] actual = new byte[destIn.remaining()];
+ destIn.get(actual);
+ assertEquals(sourceCipherSuite, Arrays.toString(sourceBytes), Arrays.toString(actual));
+ assertEquals(sourceCipherSuite, 3, numUnwrapCalls);
+ }
+
public void test_SSLEngine_getEnabledCipherSuites_returnsCopies() throws Exception {
TestSSLContext c = TestSSLContext.create();
SSLEngine e = c.clientContext.createSSLEngine();