Use consistent addresses in SSLCertificateSocketFactoryTest.
Prior to this change, the expected local and remote
InetAddresses for connecting to the test host were determined
differently, the peer address arbitraily chosen from
InetAddress.getAllByName(), but the local address determined
by actually makeing a test connection with a plain socket.
This could potentially lead to one being an IPv4 address and
the other an IPv6 one, leading to connection failures.
Bug: 254385400
Test: atest CtsNetTestCasesLatestSdk:android.net.cts.SSLCertificateSocketFactoryTest
Change-Id: Ib3ec5d4881a5db2c5141e2dd9d6053f698d1ca85
diff --git a/tests/cts/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java b/tests/cts/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java
index cbe54f8..1a780a7 100644
--- a/tests/cts/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java
+++ b/tests/cts/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java
@@ -66,7 +66,6 @@
InetAddress[] addresses;
try {
addresses = InetAddress.getAllByName(TEST_HOST);
- mTestHostAddress = addresses[0];
} catch (UnknownHostException uhe) {
throw new AssertionError(
"Unable to test SSLCertificateSocketFactory: cannot resolve " + TEST_HOST, uhe);
@@ -76,10 +75,11 @@
.map(addr -> new InetSocketAddress(addr, HTTPS_PORT))
.collect(Collectors.toList());
- // Find the local IP address which will be used to connect to TEST_HOST.
+ // Find the local and remote IP addresses which will be used to connect to TEST_HOST.
try {
Socket testSocket = new Socket(TEST_HOST, HTTPS_PORT);
mLocalAddress = testSocket.getLocalAddress();
+ mTestHostAddress = testSocket.getInetAddress();
testSocket.close();
} catch (IOException ioe) {
throw new AssertionError(""