summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChiachang Wang <chiachangwang@google.com>2020-05-29 22:38:12 +0000
committerChiachang Wang <chiachangwang@google.com>2020-06-01 00:48:58 +0000
commitffaef4931580b63c3df88b98b54d47012ada70d0 (patch)
tree20008b073f5ca6afea42846597616319e6cabcf2
parent1e2e741071140b5f911db91b2008bda8dbdb732e (diff)
Fallback if redirect url is not valid for captive portal login
Wifi AP may send a relative URL or other invalid URL if any network issue or configuration issue happen. In this kind of case, sending a redirect url to captive portal app will fail to open the login page. Thus, fallback to send detection url if the redirect url is a malformed URL. Bug: 157433005 Test: atest NetworkStackTest Merged-In: I6126f5aeb4709a09ec249947b5e59f1310ec7a4b Change-Id: I6126f5aeb4709a09ec249947b5e59f1310ec7a4b
-rwxr-xr-xsrc/com/android/server/connectivity/NetworkMonitor.java2
-rw-r--r--tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java26
2 files changed, 22 insertions, 6 deletions
diff --git a/src/com/android/server/connectivity/NetworkMonitor.java b/src/com/android/server/connectivity/NetworkMonitor.java
index 8a1b0c7..3298b03 100755
--- a/src/com/android/server/connectivity/NetworkMonitor.java
+++ b/src/com/android/server/connectivity/NetworkMonitor.java
@@ -1090,7 +1090,7 @@ public class NetworkMonitor extends StateMachine {
final CaptivePortalProbeResult probeRes = mLastPortalProbeResult;
// Use redirect URL from AP if exists.
final String portalUrl =
- (useRedirectUrlForPortal() && probeRes.redirectUrl != null)
+ (useRedirectUrlForPortal() && makeURL(probeRes.redirectUrl) != null)
? probeRes.redirectUrl : probeRes.detectUrl;
appExtras.putString(EXTRA_CAPTIVE_PORTAL_URL, portalUrl);
if (probeRes.probeSpec != null) {
diff --git a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
index f0a7bfb..c9626f0 100644
--- a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
+++ b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
@@ -257,6 +257,7 @@ public class NetworkMonitorTest {
private static final String TEST_LOGIN_URL = "https://testportal.example.com/login";
private static final String TEST_VENUE_INFO_URL = "https://venue.example.com/info";
private static final String TEST_SPEED_TEST_URL = "https://speedtest.example.com";
+ private static final String TEST_RELATIVE_URL = "/test/relative/gen_204";
private static final String TEST_MCCMNC = "123456";
private static final String[] TEST_HTTP_URLS = {TEST_HTTP_OTHER_URL1, TEST_HTTP_OTHER_URL2};
private static final String[] TEST_HTTPS_URLS = {TEST_HTTPS_OTHER_URL1, TEST_HTTPS_OTHER_URL2};
@@ -2150,20 +2151,35 @@ public class NetworkMonitorTest {
@Test
public void testDismissPortalInValidatedNetworkEnabledOsSupported() throws Exception {
assumeTrue(ShimUtils.isAtLeastR());
- testDismissPortalInValidatedNetworkEnabled(TEST_LOGIN_URL);
+ testDismissPortalInValidatedNetworkEnabled(TEST_LOGIN_URL, TEST_LOGIN_URL);
+ }
+
+ @Test
+ public void testDismissPortalInValidatedNetworkEnabledOsSupported_NullLocationUrl()
+ throws Exception {
+ assumeTrue(ShimUtils.isAtLeastR());
+ testDismissPortalInValidatedNetworkEnabled(TEST_HTTP_URL, null /* locationUrl */);
+ }
+
+ @Test
+ public void testDismissPortalInValidatedNetworkEnabledOsSupported_InvalidLocationUrl()
+ throws Exception {
+ assumeTrue(ShimUtils.isAtLeastR());
+ testDismissPortalInValidatedNetworkEnabled(TEST_HTTP_URL, TEST_RELATIVE_URL);
}
@Test
public void testDismissPortalInValidatedNetworkEnabledOsNotSupported() throws Exception {
assumeFalse(ShimUtils.isAtLeastR());
- testDismissPortalInValidatedNetworkEnabled(TEST_HTTP_URL);
+ testDismissPortalInValidatedNetworkEnabled(TEST_HTTP_URL, TEST_LOGIN_URL);
}
- private void testDismissPortalInValidatedNetworkEnabled(String portalUrl) throws Exception {
+ private void testDismissPortalInValidatedNetworkEnabled(String expectedUrl, String locationUrl)
+ throws Exception {
setDismissPortalInValidatedNetwork(true);
setSslException(mHttpsConnection);
setPortal302(mHttpConnection);
- when(mHttpConnection.getHeaderField(eq("location"))).thenReturn(TEST_LOGIN_URL);
+ when(mHttpConnection.getHeaderField(eq("location"))).thenReturn(locationUrl);
final NetworkMonitor nm = makeMonitor(CELL_METERED_CAPABILITIES);
notifyNetworkConnected(nm, CELL_METERED_CAPABILITIES);
@@ -2188,7 +2204,7 @@ public class NetworkMonitorTest {
assertEquals(TEST_NETID, networkCaptor.getValue().netId);
// Portal URL should be redirect URL.
final String redirectUrl = bundle.getString(ConnectivityManager.EXTRA_CAPTIVE_PORTAL_URL);
- assertEquals(portalUrl, redirectUrl);
+ assertEquals(expectedUrl, redirectUrl);
}
@Test