Merge "Fix android.net.SSLTest"
diff --git a/core/java/android/net/SSLCertificateSocketFactory.java b/core/java/android/net/SSLCertificateSocketFactory.java
index 0b1569c..a7aa380 100644
--- a/core/java/android/net/SSLCertificateSocketFactory.java
+++ b/core/java/android/net/SSLCertificateSocketFactory.java
@@ -19,11 +19,13 @@
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.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 @@
/**
* 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
similarity index 64%
rename from core/tests/coretests/src/android/net/SSLTest.java
rename to core/tests/coretests/src/android/net/SSLCertificateSocketFactoryTest.java
index 45d28ae..5cbf02a 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 static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
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);
-
- String get = "GET /sslcheck.html HTTP/1.1\r\nHost: 68.178.217.222\r\n\r\n";
-
- // System.out.println("going for write...");
- out.write(get.getBytes());
-
- byte[] b = new byte[1024];
- // System.out.println("going for read...");
- int ret = in.read(b);
-
- // System.out.println(new String(b));
- }
-
+@RunWith(AndroidJUnit4.class)
+public class SSLCertificateSocketFactoryTest {
+ @Test
public void testStringsToLengthPrefixedBytes() {
byte[] expected = {
6, 's', 'p', 'd', 'y', '/', '2',
@@ -59,6 +39,7 @@
new byte[] { 'h', 't', 't', 'p', '/', '1', '.', '1' })));
}
+ @Test
public void testStringsToLengthPrefixedBytesEmptyArray() {
try {
SSLCertificateSocketFactory.toLengthPrefixedList();
@@ -67,6 +48,7 @@
}
}
+ @Test
public void testStringsToLengthPrefixedBytesEmptyByteArray() {
try {
SSLCertificateSocketFactory.toLengthPrefixedList(new byte[0]);
@@ -75,6 +57,7 @@
}
}
+ @Test
public void testStringsToLengthPrefixedBytesOversizedInput() {
try {
SSLCertificateSocketFactory.toLengthPrefixedList(new byte[256]);