summaryrefslogtreecommitdiff
path: root/app/src/test/java/se
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2020-07-24 16:30:02 +0200
committercyBerta <cyberta@riseup.net>2020-07-24 16:30:02 +0200
commite986a294ec3e328bd48bb4c423fe835d1aa2dc69 (patch)
treea2c13ab9d29c27da15c191f65b013e8d515a6a88 /app/src/test/java/se
parent501a451b8b932e1f0e001599dbfe53810cb9ead0 (diff)
fix bug in gateway selection - always iterate through all gateways and count those supporting the requested transport in order to get the nClosest gateway; adding more tests
Diffstat (limited to 'app/src/test/java/se')
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java33
1 files changed, 31 insertions, 2 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
index dd5eb00c..5c5ebbfe 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
@@ -161,8 +161,6 @@ public class GatewaysManagerTest {
@Test
public void TestSelectN_selectFirstObfs4Connection_returnThirdGateway() throws JSONException, ConfigParser.ConfigParseError, IOException {
Provider provider = getProvider(null, null, null, null, null, null, "ptdemo_two_openvpn_one_pt_gateways.json", null);
- JSONObject eipServiceJson = provider.getEipServiceJson();
- JSONObject gateway3 = eipServiceJson.getJSONArray(GATEWAYS).getJSONObject(2);
MockHelper.mockProviderObserver(provider);
mockStatic(PreferenceHelper.class);
@@ -172,6 +170,37 @@ public class GatewaysManagerTest {
assertEquals("37.12.247.10", gatewaysManager.select(0).getRemoteIP());
}
+ @Test
+ public void testSelectN_selectFromPresortedGateways_returnsGatewaysInPresortedOrder() throws JSONException {
+ Provider provider = getProvider(null, null, null, null, null, null, "ptdemo_three_mixed_gateways.json", "ptdemo_three_mixed_gateways.geoip.json");
+
+ MockHelper.mockProviderObserver(provider);
+ //use openvpn, not pluggable transports
+ mockStatic(PreferenceHelper.class);
+ when(PreferenceHelper.getUsePluggableTransports(any(Context.class))).thenReturn(false);
+ GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
+
+ assertEquals("manila.bitmask.net", gatewaysManager.select(0).getHost());
+ assertEquals("moscow.bitmask.net", gatewaysManager.select(1).getHost());
+ assertEquals("pt.demo.bitmask.net", gatewaysManager.select(2).getHost());
+ }
+
+ @Test
+ public void testSelectN_selectObfs4FromPresortedGateways_returnsObfs4GatewaysInPresortedOrder() throws JSONException {
+ Provider provider = getProvider(null, null, null, null, null, null, "ptdemo_three_mixed_gateways.json", "ptdemo_three_mixed_gateways.geoip.json");
+
+ MockHelper.mockProviderObserver(provider);
+ //use openvpn, not pluggable transports
+ mockStatic(PreferenceHelper.class);
+ when(PreferenceHelper.getUsePluggableTransports(any(Context.class))).thenReturn(true);
+ GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
+
+ assertEquals("moscow.bitmask.net", gatewaysManager.select(0).getHost());
+ assertEquals("pt.demo.bitmask.net", gatewaysManager.select(1).getHost());
+ assertNull(gatewaysManager.select(2));
+ }
+
+
private String getJsonStringFor(String filename) throws IOException {
return TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream(filename));
}