diff options
-rw-r--r-- | core/java/android/net/SSLCertificateSocketFactory.java | 7 | ||||
-rw-r--r-- | core/tests/coretests/src/android/net/SSLCertificateSocketFactoryTest.java (renamed from core/tests/coretests/src/android/net/SSLTest.java) | 41 |
2 files changed, 18 insertions, 30 deletions
diff --git a/core/java/android/net/SSLCertificateSocketFactory.java b/core/java/android/net/SSLCertificateSocketFactory.java index 0b1569ca4ff5..a7aa380214d5 100644 --- a/core/java/android/net/SSLCertificateSocketFactory.java +++ b/core/java/android/net/SSLCertificateSocketFactory.java @@ -19,11 +19,13 @@ package android.net; import android.os.SystemProperties; import android.util.Log; +import com.android.internal.annotations.VisibleForTesting; import com.android.internal.os.RoSystemProperties; import com.android.org.conscrypt.Conscrypt; import com.android.org.conscrypt.OpenSSLContextImpl; import com.android.org.conscrypt.OpenSSLSocketImpl; import com.android.org.conscrypt.SSLClientSessionCache; + import java.io.IOException; import java.net.InetAddress; import java.net.Socket; @@ -31,6 +33,7 @@ import java.net.SocketException; import java.security.KeyManagementException; import java.security.PrivateKey; import java.security.cert.X509Certificate; + import javax.net.SocketFactory; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; @@ -306,8 +309,10 @@ public class SSLCertificateSocketFactory extends SSLSocketFactory { /** * Returns an array containing the concatenation of length-prefixed byte * strings. + * @hide */ - static byte[] toLengthPrefixedList(byte[]... items) { + @VisibleForTesting + public static byte[] toLengthPrefixedList(byte[]... items) { if (items.length == 0) { throw new IllegalArgumentException("items.length == 0"); } diff --git a/core/tests/coretests/src/android/net/SSLTest.java b/core/tests/coretests/src/android/net/SSLCertificateSocketFactoryTest.java index 45d28aef7974..5cbf02a79083 100644 --- a/core/tests/coretests/src/android/net/SSLTest.java +++ b/core/tests/coretests/src/android/net/SSLCertificateSocketFactoryTest.java @@ -16,39 +16,19 @@ package android.net; -import android.test.suitebuilder.annotation.Suppress; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.Socket; -import java.util.Arrays; -import junit.framework.TestCase; - -public class SSLTest extends TestCase { - //This test relies on network resources. - @Suppress - public void testCertificate() throws Exception { - // test www.fortify.net/sslcheck.html - Socket ssl = SSLCertificateSocketFactory.getDefault().createSocket("www.fortify.net",443); - assertNotNull(ssl); - - OutputStream out = ssl.getOutputStream(); - assertNotNull(out); - - InputStream in = ssl.getInputStream(); - assertNotNull(in); +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; - String get = "GET /sslcheck.html HTTP/1.1\r\nHost: 68.178.217.222\r\n\r\n"; +import android.support.test.runner.AndroidJUnit4; - // System.out.println("going for write..."); - out.write(get.getBytes()); +import org.junit.Test; +import org.junit.runner.RunWith; - byte[] b = new byte[1024]; - // System.out.println("going for read..."); - int ret = in.read(b); - - // System.out.println(new String(b)); - } +import java.util.Arrays; +@RunWith(AndroidJUnit4.class) +public class SSLCertificateSocketFactoryTest { + @Test public void testStringsToLengthPrefixedBytes() { byte[] expected = { 6, 's', 'p', 'd', 'y', '/', '2', @@ -59,6 +39,7 @@ public class SSLTest extends TestCase { new byte[] { 'h', 't', 't', 'p', '/', '1', '.', '1' }))); } + @Test public void testStringsToLengthPrefixedBytesEmptyArray() { try { SSLCertificateSocketFactory.toLengthPrefixedList(); @@ -67,6 +48,7 @@ public class SSLTest extends TestCase { } } + @Test public void testStringsToLengthPrefixedBytesEmptyByteArray() { try { SSLCertificateSocketFactory.toLengthPrefixedList(new byte[0]); @@ -75,6 +57,7 @@ public class SSLTest extends TestCase { } } + @Test public void testStringsToLengthPrefixedBytesOversizedInput() { try { SSLCertificateSocketFactory.toLengthPrefixedList(new byte[256]); |