Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c9a89aa3 authored by Chiachang Wang's avatar Chiachang Wang
Browse files

Fallback probe result should not be considered as HTTP success

The fallback probe is not intended for network validation. It's
intended to detect a captive portal even if the HTTPS probe
succeeds. Thus, ignore the fallback probe result from HTTP
result.

Bug: 171604280
Test: atest NetworkStackTests
Change-Id: Idceb69baff392610eacdb428010aeae50f90062d
parent 9eefc742
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -2984,10 +2984,7 @@ public class NetworkMonitor extends StateMachine {
            httpsProbe.join();
            reportHttpProbeResult(NETWORK_VALIDATION_PROBE_HTTPS, httpsProbe.result());

            final boolean isHttpSuccessful =
                    (httpProbe.result().isSuccessful()
                    || (fallbackProbeResult != null && fallbackProbeResult.isSuccessful()));
            if (httpsProbe.result().isFailed() && isHttpSuccessful) {
            if (httpsProbe.result().isFailed() && httpProbe.result().isSuccessful()) {
                return CaptivePortalProbeResult.PARTIAL;
            }
            return httpsProbe.result();
+21 −9
Original line number Diff line number Diff line
@@ -1109,6 +1109,14 @@ public class NetworkMonitorTest {
        runPortalNetworkTest();
    }

    @Test
    public void testIsCaptivePortal_HttpSucceedFallbackProbeIsPortal() throws Exception {
        setSslException(mHttpsConnection);
        setStatus(mHttpConnection, 204);
        setPortal302(mFallbackConnection);
        runPortalNetworkTest();
    }

    @Test
    public void testIsCaptivePortal_FallbackProbeIsNotPortal() throws Exception {
        setSslException(mHttpsConnection);
@@ -1435,13 +1443,13 @@ public class NetworkMonitorTest {
    }

    @Test
    public void testIsCaptivePortal_FallbackSpecIsPartial() throws Exception {
    public void testIsCaptivePortal_FallbackSpecIsFail() throws Exception {
        setupFallbackSpec();
        set302(mOtherFallbackConnection, "https://www.google.com/test?q=3");

        // HTTPS failed, fallback spec went through -> partial connectivity
        runPartialConnectivityNetworkTest(
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_FALLBACK);
        runNetworkTest(VALIDATION_RESULT_INVALID,
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_FALLBACK,
                null /* redirectUrl */);
        verify(mOtherFallbackConnection, times(1)).getResponseCode();
        verify(mFallbackConnection, never()).getResponseCode();
    }
@@ -2208,13 +2216,16 @@ public class NetworkMonitorTest {
        setStatus(mFallbackConnection, 500);
        runPartialConnectivityNetworkTest(
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTP);
    }

        resetCallbacks();
    @Test
    public void testIsCaptivePortal_OnlyFallbackSucceed() throws Exception {
        setStatus(mHttpsConnection, 500);
        setStatus(mHttpConnection, 500);
        setStatus(mFallbackConnection, 204);
        runPartialConnectivityNetworkTest(
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_FALLBACK);
        runNetworkTest(VALIDATION_RESULT_INVALID,
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_FALLBACK,
                null /* redirectUrl */);
    }

    private void assertIpAddressArrayEquals(String[] expected, InetAddress[] actual) {
@@ -2274,8 +2285,9 @@ public class NetworkMonitorTest {
        setStatus(mFallbackConnection, 204);
        nm.forceReevaluation(Process.myUid());
        // Expect to send HTTP, HTTPs, FALLBACK and evaluation results.
        verifyNetworkTested(NETWORK_VALIDATION_RESULT_PARTIAL,
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_FALLBACK);
        runNetworkTest(VALIDATION_RESULT_INVALID,
                NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_FALLBACK,
                null /* redirectUrl */);
    }

    @Test