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

Commit 5f1a43b3 authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN
Browse files

Have test URLs replace all validation URLs

Test URLs did not apply when an overlay set multiple validation URLs
through R.array.config_captive_portal_https_urls. This was not intended
as test URLs are designed to override all URL configuration so tests can
have predictable behavior.

Bug: 163119659
Test: atest NetworkMonitorTest
Original-Change: https://android-review.googlesource.com/1406760
Merged-In: Ic39a74b41a538afefed2ca08b43cfb7d324a5b78
Change-Id: Ic39a74b41a538afefed2ca08b43cfb7d324a5b78
parent 404157a2
Loading
Loading
Loading
Loading
+10 −6
Original line number Original line Diff line number Diff line
@@ -1903,7 +1903,7 @@ public class NetworkMonitor extends StateMachine {
    }
    }


    @Nullable
    @Nullable
    private String getTestUrl(@NonNull String key) {
    private URL getTestUrl(@NonNull String key) {
        final String strExpiration = mDependencies.getDeviceConfigProperty(NAMESPACE_CONNECTIVITY,
        final String strExpiration = mDependencies.getDeviceConfigProperty(NAMESPACE_CONNECTIVITY,
                TEST_URL_EXPIRATION_TIME, null);
                TEST_URL_EXPIRATION_TIME, null);
        if (strExpiration == null) return null;
        if (strExpiration == null) return null;
@@ -1919,13 +1919,13 @@ public class NetworkMonitor extends StateMachine {
        final long now = System.currentTimeMillis();
        final long now = System.currentTimeMillis();
        if (expTime < now || (expTime - now) > TEST_URL_EXPIRATION_MS) return null;
        if (expTime < now || (expTime - now) > TEST_URL_EXPIRATION_MS) return null;


        return mDependencies.getDeviceConfigProperty(NAMESPACE_CONNECTIVITY,
        final String strUrl = mDependencies.getDeviceConfigProperty(NAMESPACE_CONNECTIVITY,
                key, null /* defaultValue */);
                key, null /* defaultValue */);
        if (!isValidTestUrl(strUrl)) return null;
        return makeURL(strUrl);
    }
    }


    private String getCaptivePortalServerHttpsUrl() {
    private String getCaptivePortalServerHttpsUrl() {
        final String testUrl = getTestUrl(TEST_CAPTIVE_PORTAL_HTTPS_URL);
        if (isValidTestUrl(testUrl)) return testUrl;
        return getSettingFromResource(mCustomizedContext,
        return getSettingFromResource(mCustomizedContext,
                R.string.config_captive_portal_https_url, CAPTIVE_PORTAL_HTTPS_URL,
                R.string.config_captive_portal_https_url, CAPTIVE_PORTAL_HTTPS_URL,
                mCustomizedContext.getResources().getString(
                mCustomizedContext.getResources().getString(
@@ -2006,8 +2006,6 @@ public class NetworkMonitor extends StateMachine {
     * on one URL that can be used, while NetworkMonitor may implement more complex logic.
     * on one URL that can be used, while NetworkMonitor may implement more complex logic.
     */
     */
    public String getCaptivePortalServerHttpUrl() {
    public String getCaptivePortalServerHttpUrl() {
        final String testUrl = getTestUrl(TEST_CAPTIVE_PORTAL_HTTP_URL);
        if (isValidTestUrl(testUrl)) return testUrl;
        return getSettingFromResource(mCustomizedContext,
        return getSettingFromResource(mCustomizedContext,
                R.string.config_captive_portal_http_url, CAPTIVE_PORTAL_HTTP_URL,
                R.string.config_captive_portal_http_url, CAPTIVE_PORTAL_HTTP_URL,
                mCustomizedContext.getResources().getString(
                mCustomizedContext.getResources().getString(
@@ -2085,6 +2083,9 @@ public class NetworkMonitor extends StateMachine {
    }
    }


    private URL[] makeCaptivePortalHttpsUrls() {
    private URL[] makeCaptivePortalHttpsUrls() {
        final URL testUrl = getTestUrl(TEST_CAPTIVE_PORTAL_HTTPS_URL);
        if (testUrl != null) return new URL[] { testUrl };

        final String firstUrl = getCaptivePortalServerHttpsUrl();
        final String firstUrl = getCaptivePortalServerHttpsUrl();
        try {
        try {
            final URL[] settingProviderUrls =
            final URL[] settingProviderUrls =
@@ -2103,6 +2104,9 @@ public class NetworkMonitor extends StateMachine {
    }
    }


    private URL[] makeCaptivePortalHttpUrls() {
    private URL[] makeCaptivePortalHttpUrls() {
        final URL testUrl = getTestUrl(TEST_CAPTIVE_PORTAL_HTTP_URL);
        if (testUrl != null) return new URL[] { testUrl };

        final String firstUrl = getCaptivePortalServerHttpUrl();
        final String firstUrl = getCaptivePortalServerHttpUrl();
        try {
        try {
            final URL[] settingProviderUrls =
            final URL[] settingProviderUrls =
+26 −0
Original line number Original line Diff line number Diff line
@@ -1538,6 +1538,32 @@ public class NetworkMonitorTest {
        verify(mHttpConnection).getResponseCode();
        verify(mHttpConnection).getResponseCode();
    }
    }


    @Test
    public void testIsCaptivePortal_TestUrlsWithUrlOverlays() throws Exception {
        setupResourceForMultipleProbes();
        doReturn(TEST_HTTPS_URL).when(mResources)
                .getString(R.string.config_captive_portal_https_url);
        doReturn(TEST_HTTP_URL).when(mResources)
                .getString(R.string.config_captive_portal_http_url);

        setDeviceConfig(TEST_URL_EXPIRATION_TIME,
                String.valueOf(currentTimeMillis() + TimeUnit.MINUTES.toMillis(9)));
        setDeviceConfig(TEST_CAPTIVE_PORTAL_HTTPS_URL, TEST_OVERRIDE_URL);
        setDeviceConfig(TEST_CAPTIVE_PORTAL_HTTP_URL, TEST_OVERRIDE_URL);
        setStatus(mTestOverriddenUrlConnection, 204);

        runValidatedNetworkTest();
        verify(mHttpsConnection, never()).getResponseCode();
        verify(mHttpConnection, never()).getResponseCode();
        verify(mOtherHttpsConnection1, never()).getResponseCode();
        verify(mOtherHttpsConnection2, never()).getResponseCode();
        verify(mOtherHttpConnection1, never()).getResponseCode();
        verify(mOtherHttpConnection2, never()).getResponseCode();

        // Used for both HTTP and HTTPS: can be called once (if HTTPS validates first) or twice
        verify(mTestOverriddenUrlConnection, atLeastOnce()).getResponseCode();
    }

    @Test
    @Test
    public void testIsDataStall_EvaluationDisabled() {
    public void testIsDataStall_EvaluationDisabled() {
        setDataStallEvaluationType(0);
        setDataStallEvaluationType(0);