From f29ee8ac7378408e070be1130c9cadc8e947ddb3 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Tue, 23 Nov 2021 14:51:33 +0100 Subject: sort locations by transport --- .../bitmaskclient/eip/GatewaysManagerTest.java | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'app/src/test/java') 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 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 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)); } -- cgit v1.2.3