diff options
author | cyBerta <cyberta@riseup.net> | 2020-07-24 18:38:45 +0200 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2020-07-24 18:38:45 +0200 |
commit | 38f5720502fda7b89ce204fe4afdffa67ac0ae82 (patch) | |
tree | c3266b79c930a6a902814e6c58c457280ed67c2a /app | |
parent | fa0ff0970173908acc9ab2b37d4d4cc2d67c1597 (diff) |
try to fetch geoip service only if non-default url exists
Diffstat (limited to 'app')
3 files changed, 33 insertions, 3 deletions
diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ProviderApiManager.java b/app/src/insecure/java/se/leap/bitmaskclient/ProviderApiManager.java index ba226957..a111e907 100644 --- a/app/src/insecure/java/se/leap/bitmaskclient/ProviderApiManager.java +++ b/app/src/insecure/java/se/leap/bitmaskclient/ProviderApiManager.java @@ -239,7 +239,7 @@ public class ProviderApiManager extends ProviderApiManagerBase { protected Bundle getGeoIPJson(Provider provider) { Bundle result = new Bundle(); - if (!provider.shouldUpdateGeoIpJson()) { + if (!provider.shouldUpdateGeoIpJson() || provider.getGeoipUrl().isDefault()) { result.putBoolean(BROADCAST_RESULT_KEY, false); return result; } diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderApiManager.java b/app/src/production/java/se/leap/bitmaskclient/ProviderApiManager.java index e5d5bd0e..04ffe9e6 100644 --- a/app/src/production/java/se/leap/bitmaskclient/ProviderApiManager.java +++ b/app/src/production/java/se/leap/bitmaskclient/ProviderApiManager.java @@ -225,7 +225,7 @@ public class ProviderApiManager extends ProviderApiManagerBase { protected Bundle getGeoIPJson(Provider provider) { Bundle result = new Bundle(); - if (!provider.shouldUpdateGeoIpJson()) { + if (!provider.shouldUpdateGeoIpJson() || provider.getGeoipUrl().isDefault()) { result.putBoolean(BROADCAST_RESULT_KEY, false); return result; } 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 60a60580..efa6f78c 100644 --- a/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java @@ -502,7 +502,7 @@ public class ProviderApiManagerTest { } @Test - public void test_handleIntentGetGeoip_noNeedToUpdate_returnsFailure() throws IOException, NoSuchAlgorithmException, CertificateEncodingException, JSONException { + public void test_handleIntentGetGeoip_didNotReachTimeoutToFetchNew_returnsFailure() throws IOException, NoSuchAlgorithmException, CertificateEncodingException, JSONException { if ("insecure".equals(BuildConfig.FLAVOR_implementation)) { return; } @@ -530,4 +530,34 @@ public class ProviderApiManagerTest { providerApiManager.handleIntent(providerApiCommand); } + @Test + public void test_handleIntentGetGeoip_noGeoipServiceURLDefined_returnsFailure() throws IOException, NoSuchAlgorithmException, CertificateEncodingException, JSONException { + if ("insecure".equals(BuildConfig.FLAVOR_implementation)) { + return; + } + + Provider provider = getConfiguredProvider(); + provider.setGeoipUrl(null); + provider.setGeoIpJson(new JSONObject()); + mockFingerprintForCertificate("a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494"); + mockProviderApiConnector(NO_ERROR); + providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback()); + + Bundle expectedResult = mockBundle(); + expectedResult.putBoolean(EIP_ACTION_START, true); + expectedResult.putBoolean(BROADCAST_RESULT_KEY, false); + expectedResult.putParcelable(PROVIDER_KEY, provider); + + Intent providerApiCommand = mockIntent(); + + providerApiCommand.setAction(ProviderAPI.DOWNLOAD_GEOIP_JSON); + Bundle extrasBundle = mockBundle(); + extrasBundle.putBoolean(EIP_ACTION_START, true); + providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(INCORRECTLY_DOWNLOADED_GEOIP_JSON, expectedResult)); + providerApiCommand.putExtra(PROVIDER_KEY, provider); + providerApiCommand.putExtra(PARAMETERS, extrasBundle); + + providerApiManager.handleIntent(providerApiCommand); + } + } |