Fix a bug where private DNS to v4-only servers don't validate.

Bug: 132670008
Test: Manual
Test: atest NetworkStackTests
Change-Id: I8ae6fa6f3800f5f6c9ee88ffe3b8ada34b96dee6
Merged-In: I362d43ee6af318694a4038a257e1ebb3f577863c
This commit is contained in:
Chiachang Wang
2019-05-15 15:33:46 +08:00
parent 0ef7b0d46e
commit 3134eb413f
2 changed files with 20 additions and 8 deletions

View File

@@ -55,12 +55,23 @@ public class DnsUtils {
throws UnknownHostException {
final List<InetAddress> result = new ArrayList<InetAddress>();
result.addAll(Arrays.asList(
getAllByName(dnsResolver, network, host, TYPE_AAAA, FLAG_NO_CACHE_LOOKUP,
timeout)));
result.addAll(Arrays.asList(
getAllByName(dnsResolver, network, host, TYPE_A, FLAG_NO_CACHE_LOOKUP,
timeout)));
try {
result.addAll(Arrays.asList(
getAllByName(dnsResolver, network, host, TYPE_AAAA, FLAG_NO_CACHE_LOOKUP,
timeout)));
} catch (UnknownHostException e) {
// Might happen if the host is v4-only, still need to query TYPE_A
}
try {
result.addAll(Arrays.asList(
getAllByName(dnsResolver, network, host, TYPE_A, FLAG_NO_CACHE_LOOKUP,
timeout)));
} catch (UnknownHostException e) {
// Might happen if the host is v6-only, still need to return AAAA answers
}
if (result.size() == 0) {
throw new UnknownHostException(host);
}
return result.toArray(new InetAddress[0]);
}

View File

@@ -297,9 +297,10 @@ public class NetworkMonitorTest {
setOtherFallbackUrls(TEST_OTHER_FALLBACK_URL);
setFallbackSpecs(null); // Test with no fallback spec by default
when(mRandom.nextInt()).thenReturn(0);
// DNS probe timeout should not be defined more than half of HANDLER_TIMEOUT_MS. Otherwise,
// it will fail the test because of timeout expired for querying AAAA and A sequentially.
when(mResources.getInteger(eq(R.integer.config_captive_portal_dns_probe_timeout)))
.thenReturn(500);
.thenReturn(200);
doAnswer((invocation) -> {
URL url = invocation.getArgument(0);