diff options
author | cyBerta <cyberta@riseup.net> | 2021-11-12 01:36:34 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2021-11-12 01:36:34 +0100 |
commit | d391c8dbf8fff278c7c18d60778a464f67f3726c (patch) | |
tree | 1f1126034e7059d5ce12702f8643337d3057f7aa /app | |
parent | 1629284074ed2dc3080a676b65b189cda4a02ed7 (diff) |
add an test for no network error handling
Diffstat (limited to 'app')
4 files changed, 38 insertions, 11 deletions
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 298f4038..22696c12 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -179,7 +179,7 @@ <string name="error_tor_timeout">Starting bridges failed. Do you want to retry or continue with an unobfuscated secure connection to configure %s?</string> <string name="retry_unobfuscated">Retry unobfuscated</string> <string name="hide_connection_details">Hide connection details</string> - <string name="error_network_connection">It seems you have no working internet connection. You should check your WiFi or cellular data connection.</string> + <string name="error_network_connection">%s has no internet connection. Please check your WiFi and cellular data settings.</string> </resources> diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java index 33e727c9..2b1dc2ef 100644 --- a/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java @@ -62,6 +62,7 @@ import static se.leap.bitmaskclient.base.models.Constants.USE_TOR; import static se.leap.bitmaskclient.providersetup.ProviderAPI.CORRECTLY_DOWNLOADED_GEOIP_JSON; import static se.leap.bitmaskclient.providersetup.ProviderAPI.ERRORS; import static se.leap.bitmaskclient.providersetup.ProviderAPI.INCORRECTLY_DOWNLOADED_GEOIP_JSON; +import static se.leap.bitmaskclient.providersetup.ProviderAPI.MISSING_NETWORK_CONNECTION; import static se.leap.bitmaskclient.providersetup.ProviderAPI.PARAMETERS; import static se.leap.bitmaskclient.providersetup.ProviderAPI.PROVIDER_NOK; import static se.leap.bitmaskclient.providersetup.ProviderAPI.PROVIDER_OK; @@ -109,10 +110,11 @@ public class ProviderApiManagerTest { static class TestProviderApiServiceCallback implements ProviderApiManagerBase.ProviderApiServiceCallback { Throwable startTorServiceException; + boolean hasNetworkConnection; TestProviderApiServiceCallback() { - new TestProviderApiServiceCallback(null); + new TestProviderApiServiceCallback(null, true); } - TestProviderApiServiceCallback(@Nullable Throwable startTorServiceException) { + TestProviderApiServiceCallback(@Nullable Throwable startTorServiceException, boolean hasNetworkConnection) { this.startTorServiceException = startTorServiceException; } @@ -144,7 +146,7 @@ public class ProviderApiManagerTest { @Override public boolean hasNetworkConnection() { - return true; + return hasNetworkConnection; } } @@ -661,7 +663,7 @@ public class ProviderApiManagerTest { mockFingerprintForCertificate(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494"); mockProviderApiConnector(ERROR_DNS_RESUOLUTION_TOR_FALLBACK); - providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(null)); + providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback()); Intent providerApiCommand = mockIntent(); providerApiCommand.putExtra(PROVIDER_KEY, provider); @@ -680,7 +682,7 @@ public class ProviderApiManagerTest { mockFingerprintForCertificate(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494"); mockProviderApiConnector(ERROR_DNS_RESUOLUTION_TOR_FALLBACK); - providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(new IllegalStateException("Tor service start not failed."))); + providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(new IllegalStateException("Tor service start not failed."), true)); Intent providerApiCommand = mockIntent(); providerApiCommand.putExtra(PROVIDER_KEY, provider); @@ -699,7 +701,7 @@ public class ProviderApiManagerTest { mockFingerprintForCertificate(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494"); mockProviderApiConnector(ERROR_DNS_RESUOLUTION_TOR_FALLBACK); - providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(null)); + providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback()); Intent providerApiCommand = mockIntent(); providerApiCommand.putExtra(PROVIDER_KEY, provider); @@ -720,7 +722,7 @@ public class ProviderApiManagerTest { mockProviderApiConnector(NO_ERROR_API_V4); mockPreferences.edit().putBoolean(USE_BRIDGES, true).putBoolean(USE_TOR, true).commit(); - providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(null)); + providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback()); Intent providerApiCommand = mockIntent(); providerApiCommand.putExtra(PROVIDER_KEY, provider); @@ -741,7 +743,7 @@ public class ProviderApiManagerTest { mockProviderApiConnector(NO_ERROR_API_V4); mockPreferences.edit().putBoolean(USE_BRIDGES, false).putBoolean(USE_TOR, false).commit(); - providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(null)); + providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback()); Intent providerApiCommand = mockIntent(); providerApiCommand.putExtra(PROVIDER_KEY, provider); @@ -759,7 +761,7 @@ public class ProviderApiManagerTest { Provider provider = getConfiguredProviderAPIv4(); mockPreferences.edit().putBoolean(USE_BRIDGES, true).putBoolean(USE_TOR, true).commit(); - providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(null)); + providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback()); Bundle expectedResult = mockBundle(); expectedResult.putBoolean(BROADCAST_RESULT_KEY, false); @@ -777,4 +779,26 @@ public class ProviderApiManagerTest { assertEquals(-1, TorStatusObservable.getProxyPort()); } + @Test + public void test_handleIntentSetupProvider_noNetwork_NetworkError() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, JSONException { + Provider provider = getConfiguredProvider(); + + mockFingerprintForCertificate("a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494"); + mockProviderApiConnector(NO_ERROR); + providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(null, false)); + Bundle expectedResult = mockBundle(); + + expectedResult.putBoolean(BROADCAST_RESULT_KEY, false); + expectedResult.putString(ERRORS, "{\"errors\":\"Bitmask has no internet connection. Please check your WiFi and cellular data settings.\"}"); + expectedResult.putParcelable(PROVIDER_KEY, provider); + + Intent providerApiCommand = mockIntent(); + + providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER); + providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(MISSING_NETWORK_CONNECTION, expectedResult)); + providerApiCommand.putExtra(PROVIDER_KEY, provider); + + providerApiManager.handleIntent(providerApiCommand); + } + } diff --git a/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java b/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java index efb49693..0086e4c2 100644 --- a/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java +++ b/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java @@ -571,6 +571,8 @@ public class MockHelper { thenReturn("Bitmask"); when(mockedResources.getString(eq(R.string.error_tor_timeout), anyString())). thenReturn(String.format(errorMessages.getString("error_tor_timeout"), "Bitmask")); + when(mockedResources.getString(eq(R.string.error_network_connection), anyString())). + thenReturn(String.format(errorMessages.getString("error_network_connection"), "Bitmask")); return mockedResources; } diff --git a/app/src/test/resources/error_messages.json b/app/src/test/resources/error_messages.json index c5e17683..ae04bdb0 100644 --- a/app/src/test/resources/error_messages.json +++ b/app/src/test/resources/error_messages.json @@ -14,5 +14,6 @@ "warning_corrupted_provider_cert": "Stored provider certificate is invalid. You can either update %s (recommended) or update the provider certificate using a commercial CA certificate.", "warning_expired_provider_cert": "Stored provider certificate is expired. You can either update %s (recommended) or update the provider certificate using a commercial CA certificate.", "setup_error_text": "There was an error configuring %s with your chosen provider.", - "error_tor_timeout": "Starting bridges failed. Do you want to retry or continue with an unobfuscated secure connection to configure %s?" + "error_tor_timeout": "Starting bridges failed. Do you want to retry or continue with an unobfuscated secure connection to configure %s?", + "error_network_connection": "%s has no internet connection. Please check your WiFi and cellular data settings." }
\ No newline at end of file |