summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChiachang Wang <chiachangwang@google.com>2020-06-02 01:18:56 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-06-02 01:18:56 +0000
commit99a74591af7bb77e928bebab3a88916db57f768b (patch)
tree777a4b794c361a90bb71c313e2569f3147efd0f7
parentf72cb2a38ea6b2fa3973bd1deb191bc3bf6b64ee (diff)
parent55971628bcb8c3ecf6d6037f5a6c614918956ddf (diff)
Merge "Fallback if redirect url is not valid for captive portal login" into rvc-dev am: 72b7075e12 am: 55971628bc
Original change: undetermined Change-Id: Ieb93cd7def22d721547f2a1ce7b980e697acdfde
-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 bee3634..4e56842 100755
--- a/src/com/android/server/connectivity/NetworkMonitor.java
+++ b/src/com/android/server/connectivity/NetworkMonitor.java
@@ -1092,7 +1092,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 e72bcda..c02d968 100644
--- a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
+++ b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
@@ -258,6 +258,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};
@@ -2185,20 +2186,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);
@@ -2223,7 +2239,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