summaryrefslogtreecommitdiff
path: root/app/src/test
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2021-11-23 14:51:33 +0100
committercyBerta <cyberta@riseup.net>2021-11-23 14:51:33 +0100
commitf29ee8ac7378408e070be1130c9cadc8e947ddb3 (patch)
tree5b6cf94738065434a41ca5a69be049d3b261d3cf /app/src/test
parent438b2b866b64f63dc1346ca89cf3e56847def6da (diff)
sort locations by transport
Diffstat (limited to 'app/src/test')
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java57
-rw-r--r--app/src/test/resources/v4/riseup_geoip_v4_bad_obfs4_gateway.json41
2 files changed, 98 insertions, 0 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 33abfbed..43a6a496 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
@@ -451,6 +451,63 @@ public class GatewaysManagerTest {
}
}
+
+ @Test
+ public void testGetSortedLocations_openvpn() {
+ Provider provider = getProvider(null, null, null, null, null, null, "v4/riseup_eipservice_for_geoip_v4.json", "v4/riseup_geoip_v4_bad_obfs4_gateway.json");
+
+ MockHelper.mockProviderObservable(provider);
+ mockStatic(PreferenceHelper.class);
+ when(PreferenceHelper.getUseBridges(any(Context.class))).thenReturn(false);
+ GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
+ List<Location> locations = gatewaysManager.getSortedGatewayLocations(OPENVPN);
+
+ assertEquals(3, locations.size());
+
+ /** -> v4/riseup_geoip_v4_bad_obfs4_gateway.json OPENVPN
+ * Paris = 0.527
+ * 0.36 - zarapito
+ * 0.92 - hoazin
+ * 0.3 - mouette
+ *
+ * Montreal = 0.59
+ * 0.59 - yal
+ *
+ * Amsterdam = 0.8
+ * 0.8 - redshank
+ */
+ assertEquals("Paris", locations.get(0).getName());
+ assertEquals("Montreal", locations.get(1).getName());
+ assertEquals("Amsterdam", locations.get(2).getName());
+ }
+
+ @Test
+ public void testGetSortedLocations_obfs4() {
+ Provider provider = getProvider(null, null, null, null, null, null, "v4/riseup_eipservice_for_geoip_v4.json", "v4/riseup_geoip_v4_bad_obfs4_gateway.json");
+
+ MockHelper.mockProviderObservable(provider);
+ mockStatic(PreferenceHelper.class);
+ when(PreferenceHelper.getUseBridges(any(Context.class))).thenReturn(false);
+ GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
+ List<Location> locations = gatewaysManager.getSortedGatewayLocations(OBFS4);
+
+ assertEquals(3, locations.size());
+
+ /** -> v4/riseup_geoip_v4_bad_obfs4_gateway.json OBFS4
+ * Paris = 0.92
+ * 0.92 - hoazin
+ *
+ * Montreal = 0.59
+ * 0.59 - yal
+ *
+ * Amsterdam = 0.0 - no obfs4
+ * 0.0 - redshank
+ */
+ assertEquals("Montreal", locations.get(0).getName());
+ assertEquals("Paris", locations.get(1).getName());
+ assertEquals("Amsterdam", locations.get(2).getName());
+ }
+
private String getJsonStringFor(String filename) throws IOException {
return TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream(filename));
}
diff --git a/app/src/test/resources/v4/riseup_geoip_v4_bad_obfs4_gateway.json b/app/src/test/resources/v4/riseup_geoip_v4_bad_obfs4_gateway.json
new file mode 100644
index 00000000..fcbc0d85
--- /dev/null
+++ b/app/src/test/resources/v4/riseup_geoip_v4_bad_obfs4_gateway.json
@@ -0,0 +1,41 @@
+{
+ "ip":"51.158.144.32",
+ "cc":"FR",
+ "city":"Paris",
+ "lat":48.8628,
+ "lon":2.3292,
+ "gateways":[
+ "mouette.riseup.net",
+ "hoatzin.riseup.net",
+ "yal.riseup.net",
+ "redshank.riseup.net",
+ "zarapito.riseup.net"
+ ],
+ "sortedGateways": [
+ {
+ "host": "mouette.riseup.net",
+ "fullness": 0.3,
+ "overload": false
+ },
+ {
+ "host": "hoatzin.riseup.net",
+ "fullness": 0.92,
+ "overload": false
+ },
+ {
+ "host": "yal.riseup.net",
+ "fullness": 0.59,
+ "overload": false
+ },
+ {
+ "host": "redshank.riseup.net",
+ "fullness": 0.8,
+ "overload": false
+ },
+ {
+ "host": "zarapito.riseup.net",
+ "fullness": 0.36,
+ "overload": true
+ }
+ ]
+} \ No newline at end of file