diff options
author | Adam Vartanian <flooey@google.com> | 2018-09-12 11:32:53 +0100 |
---|---|---|
committer | Adam Vartanian <flooey@google.com> | 2018-09-13 10:55:55 +0100 |
commit | d2d3cddb90929ef0bfee37433282bc1e7b13c094 (patch) | |
tree | bfb918a5034cd3821ef5960d1dd77992271cd694 /harmony-tests | |
parent | 0a4a4d8c4d4cc5c5737d969491f924578c33d10e (diff) |
Update tests for Conscrypt update
This mainly updates the tests to account for the existence of TLS 1.3.
In particular, add the new TLS 1.3-related constants to StandardNames
and update some old harmony tests to handle the fact that we now
report TLS 1.3 cipher suites as being supported.
Bug: 110403171
Test: cts -m CtsLibcoreTestCases
Test: cts -m CtsLibcoreOkHttpTestCases
Test: cts -m CtsLibcoreWycheproofConscryptTestCases
Change-Id: I1ff6aa5961438527b0eb882488a5dbfaaeaacc6c
Diffstat (limited to 'harmony-tests')
3 files changed, 31 insertions, 6 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 f8d2847cf7..930fa3fb05 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 @@ -25,8 +25,10 @@ import java.nio.channels.Pipe.SinkChannel; import java.nio.channels.Pipe.SourceChannel; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Set; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; @@ -62,7 +64,10 @@ public class SSLEngineTest extends TestCase { assertEquals(-1, e.getPeerPort()); String[] suites = e.getSupportedCipherSuites(); e.setEnabledCipherSuites(suites); - assertEquals(e.getEnabledCipherSuites().length, suites.length); + // By default, the engine only supports TLS 1.2, so the TLS 1.3 cipher suites + // shouldn't be enabled. + assertEquals(suites.length - StandardNames.CIPHER_SUITES_TLS13.size(), + e.getEnabledCipherSuites().length); } /** @@ -99,7 +104,10 @@ public class SSLEngineTest extends TestCase { assertEquals(e.getPeerPort(), port); String[] suites = e.getSupportedCipherSuites(); e.setEnabledCipherSuites(suites); - assertEquals(e.getEnabledCipherSuites().length, suites.length); + // By default, the engine only supports TLS 1.2, so the TLS 1.3 cipher suites + // shouldn't be enabled. + assertEquals(suites.length - StandardNames.CIPHER_SUITES_TLS13.size(), + e.getEnabledCipherSuites().length); e.setUseClientMode(true); assertTrue(e.getUseClientMode()); } @@ -176,8 +184,12 @@ public class SSLEngineTest extends TestCase { 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)); + // By default, the engine only supports TLS 1.2, so the TLS 1.3 cipher suites + // shouldn't be enabled. + List<String> supported = new ArrayList<>(Arrays.asList(st)); + supported.removeAll(StandardNames.CIPHER_SUITES_TLS13); + assertEquals("Incorrect array length", res.length, supported.size()); + assertEquals("Incorrect array was returned", Arrays.asList(res), supported); try { sse.setEnabledCipherSuites(null); diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLServerSocketTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLServerSocketTest.java index 117a1a0784..247b4e43e8 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLServerSocketTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLServerSocketTest.java @@ -16,6 +16,8 @@ package org.apache.harmony.tests.javax.net.ssl; +import java.util.ArrayList; +import java.util.List; import junit.framework.TestCase; import java.io.ByteArrayInputStream; @@ -31,6 +33,7 @@ import javax.net.ssl.KeyManager; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLServerSocket; +import libcore.java.security.StandardNames; public class SSLServerSocketTest extends TestCase { @@ -226,8 +229,12 @@ public class SSLServerSocketTest extends TestCase { sss.setEnabledCipherSuites(sss.getSupportedCipherSuites()); String[] res = sss.getEnabledCipherSuites(); assertNotNull("NULL result", res); + // By default, the socket only supports TLS 1.2, so the TLS 1.3 cipher suites + // shouldn't be enabled. + List<String> supported = new ArrayList<>(Arrays.asList(sss.getSupportedCipherSuites())); + supported.removeAll(StandardNames.CIPHER_SUITES_TLS13); assertEquals("not all supported cipher suites were enabled", - Arrays.asList(sss.getSupportedCipherSuites()), + supported, Arrays.asList(res)); } diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java index 5712a48bd2..d30ae53a6b 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java @@ -23,8 +23,10 @@ import java.net.InetSocketAddress; import java.net.UnknownHostException; import java.security.KeyStore; import java.security.SecureRandom; +import java.util.ArrayList; import java.util.Arrays; import java.util.Base64; +import java.util.List; import javax.net.ssl.HandshakeCompletedEvent; import javax.net.ssl.HandshakeCompletedListener; import javax.net.ssl.KeyManager; @@ -371,8 +373,12 @@ public class SSLSocketTest extends TestCase { ssl.setEnabledCipherSuites(ssl.getSupportedCipherSuites()); String[] res = ssl.getEnabledCipherSuites(); assertNotNull("NULL result", res); + // By default, the socket only supports TLS 1.2, so the TLS 1.3 cipher suites + // shouldn't be enabled. + List<String> supported = new ArrayList<>(Arrays.asList(ssl.getSupportedCipherSuites())); + supported.removeAll(StandardNames.CIPHER_SUITES_TLS13); assertEquals("not all supported cipher suites were enabled", - Arrays.asList(ssl.getSupportedCipherSuites()), + supported, Arrays.asList(res)); ssl.close(); } |