summaryrefslogtreecommitdiff
path: root/app/src/test/java/se
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2023-03-31 15:46:09 +0200
committercyBerta <cyberta@riseup.net>2023-04-13 16:47:13 +0200
commitf6017ab12d0c472ab4f22e81d9a768ad2510b134 (patch)
tree8a38157b4218b54a12f3990beaa2852917f4de1d /app/src/test/java/se
parenta4deca391ce064510002e24ba9f18d965f0dee59 (diff)
don't handle obfs4 over kcp as a separate pluggable transport, instead 'tcp' and 'kcp' become valid protocols for obfs4
Diffstat (limited to 'app/src/test/java/se')
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java52
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java29
2 files changed, 40 insertions, 41 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 3b0d5552..1b42b5d2 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
@@ -32,7 +32,6 @@ import se.leap.bitmaskclient.testutils.MockSharedPreferences;
import se.leap.bitmaskclient.testutils.TestSetupHelper;
import static de.blinkt.openvpn.core.connection.Connection.TransportType.OBFS4;
-import static de.blinkt.openvpn.core.connection.Connection.TransportType.OBFS4_KCP;
import static de.blinkt.openvpn.core.connection.Connection.TransportType.OPENVPN;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
@@ -220,7 +219,7 @@ public class GatewaysManagerTest {
when(PreferenceHelper.getUseBridges(any(Context.class))).thenReturn(true);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
- assertEquals("37.12.247.10", gatewaysManager.select(0).first.getRemoteIP());
+ assertEquals("37.12.247.10", gatewaysManager.select(0).gateway.getRemoteIP());
}
@Test
@@ -233,9 +232,9 @@ public class GatewaysManagerTest {
when(PreferenceHelper.getUseBridges(any(Context.class))).thenReturn(false);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
- assertEquals("manila.bitmask.net", gatewaysManager.select(0).first.getHost());
- assertEquals("moscow.bitmask.net", gatewaysManager.select(1).first.getHost());
- assertEquals("pt.demo.bitmask.net", gatewaysManager.select(2).first.getHost());
+ assertEquals("manila.bitmask.net", gatewaysManager.select(0).gateway.getHost());
+ assertEquals("moscow.bitmask.net", gatewaysManager.select(1).gateway.getHost());
+ assertEquals("pt.demo.bitmask.net", gatewaysManager.select(2).gateway.getHost());
}
@Test
@@ -248,8 +247,8 @@ public class GatewaysManagerTest {
when(PreferenceHelper.getUseBridges(any(Context.class))).thenReturn(true);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
- assertEquals("moscow.bitmask.net", gatewaysManager.select(0).first.getHost());
- assertEquals("pt.demo.bitmask.net", gatewaysManager.select(1).first.getHost());
+ assertEquals("moscow.bitmask.net", gatewaysManager.select(0).gateway.getHost());
+ assertEquals("pt.demo.bitmask.net", gatewaysManager.select(1).gateway.getHost());
assertNull(gatewaysManager.select(2));
}
@@ -265,9 +264,9 @@ public class GatewaysManagerTest {
when(PreferenceHelper.getPreferredCity(any(Context.class))).thenReturn("Paris");
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
- assertEquals("mouette.riseup.net", gatewaysManager.select(0).first.getHost());
- assertEquals("hoatzin.riseup.net", gatewaysManager.select(1).first.getHost());
- assertEquals("zarapito.riseup.net", gatewaysManager.select(2).first.getHost());
+ assertEquals("mouette.riseup.net", gatewaysManager.select(0).gateway.getHost());
+ assertEquals("hoatzin.riseup.net", gatewaysManager.select(1).gateway.getHost());
+ assertEquals("zarapito.riseup.net", gatewaysManager.select(2).gateway.getHost());
}
@Test
@@ -281,9 +280,9 @@ public class GatewaysManagerTest {
when(PreferenceHelper.getPreferredCity(any(Context.class))).thenReturn("Paris");
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
- assertEquals("mouette.riseup.net", gatewaysManager.select(0).first.getHost());
- assertEquals("hoatzin.riseup.net", gatewaysManager.select(1).first.getHost());
- assertEquals("zarapito.riseup.net", gatewaysManager.select(2).first.getHost());
+ assertEquals("mouette.riseup.net", gatewaysManager.select(0).gateway.getHost());
+ assertEquals("hoatzin.riseup.net", gatewaysManager.select(1).gateway.getHost());
+ assertEquals("zarapito.riseup.net", gatewaysManager.select(2).gateway.getHost());
}
@Test
@@ -298,9 +297,9 @@ public class GatewaysManagerTest {
when(PreferenceHelper.getPreferredCity(any(Context.class))).thenReturn("Paris");
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
- assertEquals("Paris", gatewaysManager.select(0).first.getName());
- assertEquals("Paris", gatewaysManager.select(1).first.getName());
- assertEquals("Paris", gatewaysManager.select(2).first.getName());
+ assertEquals("Paris", gatewaysManager.select(0).gateway.getName());
+ assertEquals("Paris", gatewaysManager.select(1).gateway.getName());
+ assertEquals("Paris", gatewaysManager.select(2).gateway.getName());
assertEquals(null, gatewaysManager.select(3));
}
@@ -314,9 +313,9 @@ public class GatewaysManagerTest {
when(PreferenceHelper.getUseBridges(any(Context.class))).thenReturn(false);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
- assertEquals("mouette.riseup.net", gatewaysManager.select(0, "Paris").first.getHost());
- assertEquals("hoatzin.riseup.net", gatewaysManager.select(1, "Paris").first.getHost());
- assertEquals("zarapito.riseup.net", gatewaysManager.select(2, "Paris").first.getHost());
+ assertEquals("mouette.riseup.net", gatewaysManager.select(0, "Paris").gateway.getHost());
+ assertEquals("hoatzin.riseup.net", gatewaysManager.select(1, "Paris").gateway.getHost());
+ assertEquals("zarapito.riseup.net", gatewaysManager.select(2, "Paris").gateway.getHost());
}
@Test
@@ -329,9 +328,9 @@ public class GatewaysManagerTest {
when(PreferenceHelper.getUseBridges(any(Context.class))).thenReturn(false);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
- assertEquals("mouette.riseup.net", gatewaysManager.select(0, "Paris").first.getHost());
- assertEquals("hoatzin.riseup.net", gatewaysManager.select(1, "Paris").first.getHost());
- assertEquals("zarapito.riseup.net", gatewaysManager.select(2, "Paris").first.getHost());
+ assertEquals("mouette.riseup.net", gatewaysManager.select(0, "Paris").gateway.getHost());
+ assertEquals("hoatzin.riseup.net", gatewaysManager.select(1, "Paris").gateway.getHost());
+ assertEquals("zarapito.riseup.net", gatewaysManager.select(2, "Paris").gateway.getHost());
}
@Test
@@ -345,9 +344,9 @@ public class GatewaysManagerTest {
when(PreferenceHelper.getUseBridges(any(Context.class))).thenReturn(false);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
- assertEquals("Paris", gatewaysManager.select(0, "Paris").first.getName());
- assertEquals("Paris", gatewaysManager.select(1, "Paris").first.getName());
- assertEquals("Paris", gatewaysManager.select(2, "Paris").first.getName());
+ assertEquals("Paris", gatewaysManager.select(0, "Paris").gateway.getName());
+ assertEquals("Paris", gatewaysManager.select(1, "Paris").gateway.getName());
+ assertEquals("Paris", gatewaysManager.select(2, "Paris").gateway.getName());
assertEquals(null, gatewaysManager.select(3, "Paris"));
}
@@ -534,7 +533,7 @@ public class GatewaysManagerTest {
mockStatic(PreferenceHelper.class);
when(PreferenceHelper.getUseBridges(any(Context.class))).thenReturn(false);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
- List<Location> locations = gatewaysManager.getSortedGatewayLocations(OBFS4_KCP);
+ List<Location> locations = gatewaysManager.getSortedGatewayLocations(OBFS4);
assertEquals(3, locations.size());
}
@@ -548,7 +547,6 @@ public class GatewaysManagerTest {
when(PreferenceHelper.getUseBridges(any(Context.class))).thenReturn(false);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
- assertEquals(0.3, gatewaysManager.getLocation("Amsterdam").getAverageLoad(OBFS4_KCP));
assertEquals(0.3, gatewaysManager.getLocation("Amsterdam").getAverageLoad(OBFS4));
assertEquals(0.3, gatewaysManager.getLocation("Amsterdam").getAverageLoad(OPENVPN));
}
diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java
index 4fb178fc..6b1c5bf3 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java
@@ -9,7 +9,6 @@ import static org.mockito.Mockito.mock;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.when;
import static de.blinkt.openvpn.core.connection.Connection.TransportType.OBFS4;
-import static de.blinkt.openvpn.core.connection.Connection.TransportType.OBFS4_KCP;
import static de.blinkt.openvpn.core.connection.Connection.TransportType.OPENVPN;
import static se.leap.bitmaskclient.base.models.Constants.OPENVPN_CONFIGURATION;
import static se.leap.bitmaskclient.testutils.MockHelper.mockTextUtils;
@@ -34,6 +33,7 @@ import java.util.HashMap;
import de.blinkt.openvpn.VpnProfile;
import de.blinkt.openvpn.core.connection.Connection;
+import de.blinkt.openvpn.core.connection.Obfs4Connection;
import se.leap.bitmaskclient.base.utils.ConfigHelper;
import se.leap.bitmaskclient.testutils.MockHelper;
import se.leap.bitmaskclient.testutils.TestSetupHelper;
@@ -1688,7 +1688,7 @@ public class VpnConfigGeneratorTest {
@Test
public void testGenerateVpnProfileExperimentalTransportsEnabled () throws Exception {
- gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_kcp_gateways.json"))).getJSONArray("gateways").getJSONObject(0);
+ gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_kcp_gateways.json"))).getJSONArray("gateways").getJSONObject(2);
generalConfig = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_kcp_gateways.json"))).getJSONObject(OPENVPN_CONFIGURATION);
VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration();
configuration.apiVersion = 3;
@@ -1696,29 +1696,27 @@ public class VpnConfigGeneratorTest {
configuration.preferUDP = true;
vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
- assertTrue(vpnProfiles.containsKey(OBFS4));
- assertTrue(vpnProfiles.containsKey(OBFS4_KCP));
+ assertTrue(vpnProfiles.containsKey(OBFS4) && ((Obfs4Connection)vpnProfiles.get(OBFS4).mConnections[0]).getDispatcherOptions().udp);
assertTrue(vpnProfiles.containsKey(OPENVPN));
}
@Test
public void testGenerateVpnProfile_experimentalTransportsEnabled_KCPMisconfiguredWithUDP_SkippingObfsKCP () throws Exception {
- gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_misconfigured_kcp_gateways.json"))).getJSONArray("gateways").getJSONObject(0);
+ gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_misconfigured_kcp_gateways.json"))).getJSONArray("gateways").getJSONObject(2);
generalConfig = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_misconfigured_kcp_gateways.json"))).getJSONObject(OPENVPN_CONFIGURATION);
VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration();
configuration.apiVersion = 3;
configuration.experimentalTransports = true;
vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
- assertTrue(vpnProfiles.containsKey(OBFS4));
- assertFalse(vpnProfiles.containsKey(OBFS4_KCP));
+ assertFalse(vpnProfiles.containsKey(OBFS4));
assertTrue(vpnProfiles.containsKey(OPENVPN));
}
@Test
public void testGenerateVpnProfile_ObfuscationPinningEnabled_obfs4AndOpenvpnProfile () throws Exception {
- gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_kcp_gateways.json"))).getJSONArray("gateways").getJSONObject(0);
+ gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_kcp_gateways.json"))).getJSONArray("gateways").getJSONObject(1);
generalConfig = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_kcp_gateways.json"))).getJSONObject(OPENVPN_CONFIGURATION);
VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration();
configuration.apiVersion = 3;
@@ -1728,7 +1726,8 @@ public class VpnConfigGeneratorTest {
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
assertFalse("has no openvpn profile", vpnProfiles.containsKey(OPENVPN));
assertTrue("has obfs4 profile", vpnProfiles.containsKey(OBFS4));
- assertFalse("has no obfs4 kcp profile", vpnProfiles.containsKey(OBFS4_KCP));
+ assertTrue("bridge is running KCP", vpnProfiles.get(OBFS4).mGatewayIp.equals("1.2.3.4"));
+
}
@Test
@@ -1738,16 +1737,17 @@ public class VpnConfigGeneratorTest {
VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration();
configuration.apiVersion = 3;
configuration.useObfuscationPinning = true;
- configuration.obfuscationProxyKCP = true;
+ configuration.obfuscationProxyKCP = false;
configuration.obfuscationProxyPort = "443";
configuration.obfuscationProxyIP = "5.6.7.8";
configuration.obfuscationProxyCert = "asdfasdf";
configuration.remoteGatewayIP = "1.2.3.4";
vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
- assertTrue("has obfs4_kcp profile", vpnProfiles.containsKey(OBFS4_KCP));
assertFalse("has openvpn profile", vpnProfiles.containsKey(OPENVPN));
- assertFalse("has no obfs4 profile", vpnProfiles.containsKey(OBFS4));
+ assertTrue("has obfs4 profile", vpnProfiles.containsKey(OBFS4));
+ assertTrue("bridge is pinned one", vpnProfiles.get(OBFS4).getTransportType() == OBFS4 && !vpnProfiles.get(OBFS4).mConnections[0].isUseUdp() );
+ assertTrue("bridge is running KCP", ((Obfs4Connection) vpnProfiles.get(OBFS4).mConnections[0]).getDispatcherOptions().udp == false);
}
@Test
@@ -1765,9 +1765,10 @@ public class VpnConfigGeneratorTest {
vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
- assertTrue("has obfs4_kcp profile", vpnProfiles.containsKey(OBFS4_KCP));
assertFalse("has openvpn profile", vpnProfiles.containsKey(OPENVPN));
- assertFalse("has no obfs4 profile", vpnProfiles.containsKey(OBFS4));
+ assertTrue("has no obfs4 profile", vpnProfiles.containsKey(OBFS4));
+ assertTrue("bridge is pinned one", vpnProfiles.get(OBFS4).getTransportType() == OBFS4 && vpnProfiles.get(OBFS4).mGatewayIp.equals("1.2.3.4"));
+ assertTrue("bridge is running KCP", ((Obfs4Connection) vpnProfiles.get(OBFS4).mConnections[0]).getDispatcherOptions().udp == true);
}
} \ No newline at end of file