From c637bffe1c9843b9de7366eee3584c51360e3867 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 5 Oct 2019 23:36:27 +0200 Subject: ignore gateways with invalid transports while still adding gateways with valid configurations --- .../java/se/leap/bitmaskclient/eip/GatewaySelectorTest.java | 3 ++- .../java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'app/src/test/java/se/leap') diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaySelectorTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaySelectorTest.java index 2f5ae9b6..5089de54 100644 --- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaySelectorTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaySelectorTest.java @@ -49,6 +49,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import de.blinkt.openvpn.core.ConfigParser; import se.leap.bitmaskclient.Provider; import se.leap.bitmaskclient.utils.ConfigHelper; @@ -99,7 +100,7 @@ public class GatewaySelectorTest { ArrayList gatewayList = new ArrayList<>(); @Before - public void setup() throws IOException, JSONException { + public void setup() throws IOException, JSONException, ConfigParser.ConfigParseError { mockStatic(ConfigHelper.class); eipDefinition = new JSONObject(getInputAsString(getClass().getClassLoader().getResourceAsStream("eip-service-four-gateways.json"))); JSONArray gateways = eipDefinition.getJSONArray("gateways"); 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 e4c5f390..46e166d4 100644 --- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java @@ -14,12 +14,14 @@ import org.mockito.junit.MockitoJUnitRunner; import java.io.IOException; +import de.blinkt.openvpn.core.connection.Connection; import se.leap.bitmaskclient.Constants; import se.leap.bitmaskclient.Provider; import se.leap.bitmaskclient.testutils.TestSetupHelper; import static junit.framework.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.anyInt; +import static junit.framework.Assert.assertNotNull; +import static junit.framework.Assert.assertNull; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @@ -67,6 +69,15 @@ public class GatewaysManagerTest { assertEquals(3, gatewaysManager.size()); } + @Test + public void testFromEipServiceJson_ignoreGatewaysWithMisconfiguredTransportsWhileAddingValidOnes() throws Exception { + String eipServiceJson = TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_misconfigured_mixed_gateways.json")); + gatewaysManager.fromEipServiceJson(new JSONObject(eipServiceJson)); + assertEquals(1, gatewaysManager.size()); + assertNull(gatewaysManager.select(0).getProfile(Connection.TransportType.OBFS4)); + assertNotNull(gatewaysManager.select(0).getProfile(Connection.TransportType.OPENVPN)); + } + @Test public void testFromEipServiceJson_ignoreDuplicateGateways() throws Exception { String eipServiceJson = TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("eip-service-two-gateways.json")); -- cgit v1.2.3