summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRemi NGUYEN VAN <reminv@google.com>2020-05-29 08:24:08 +0000
committerRemi NGUYEN VAN <reminv@google.com>2020-06-01 01:55:43 +0000
commite443dd652fbbdfc95c7138ea4fe25a37fe242351 (patch)
treef5f91fcd3f3e741569aa6cc35c5ea824888669c4 /tests
parent6bed0e594128b129d8b4efc427dbed546e3e420f (diff)
Only allow HTTP capport URLs on test networks
HTTP URLs on localhost for the capport API should only be accepted on networks with TRANSPORT_TEST. This change also introduces the first changes to fix thread safety issues in NetworkMonitor, where LinkProperties or NetworkCapabilities are read from the evaluation thread, even though they are updated from the StateMachine thread. The EvaluationThreadDeps class should be augmented in later changes to hold thread-safe copies of what the evaluation thread needs. Bug: 156062304 Bug: 155455470 Test: atest NetworkMonitorTest Original-Change: https://android-review.googlesource.com/1315226 Merged-In: I65bb54c581965159b99d7ac8596304ceb6b5f2cb Change-Id: I65bb54c581965159b99d7ac8596304ceb6b5f2cb
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java12
1 files changed, 8 insertions, 4 deletions
diff --git a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
index 4b249ce..8734e9e 100644
--- a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
+++ b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
@@ -52,6 +52,7 @@ import static android.net.util.NetworkStackUtils.TEST_URL_EXPIRATION_TIME;
import static android.provider.DeviceConfig.NAMESPACE_CONNECTIVITY;
import static com.android.networkstack.util.DnsUtils.PRIVATE_DNS_PROBE_HOST_SUFFIX;
+import static com.android.server.connectivity.NetworkMonitor.INITIAL_REEVALUATE_DELAY_MS;
import static com.android.server.connectivity.NetworkMonitor.extractCharset;
import static junit.framework.Assert.assertEquals;
@@ -1112,10 +1113,13 @@ public class NetworkMonitorTest {
verify(mFallbackConnection, times(1)).getResponseCode();
verify(mOtherFallbackConnection, never()).getResponseCode();
- // Second check uses the URL chosen by Random
- final CaptivePortalProbeResult result = monitor.isCaptivePortal();
- assertTrue(result.isPortal());
- verify(mOtherFallbackConnection, times(1)).getResponseCode();
+ // Second check should be triggered automatically after the reevaluate delay, and uses the
+ // URL chosen by mRandom
+ // This test is appropriate to cover reevaluate behavior as long as the timeout is short
+ assertTrue(INITIAL_REEVALUATE_DELAY_MS < 2000);
+ verify(mOtherFallbackConnection, timeout(INITIAL_REEVALUATE_DELAY_MS + HANDLER_TIMEOUT_MS))
+ .getResponseCode();
+ verifyNetworkTested(VALIDATION_RESULT_PORTAL, 0 /* probesSucceeded */, TEST_LOGIN_URL);
}
@Test