summaryrefslogtreecommitdiff
path: root/app/src/test
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2021-11-25 12:23:04 +0100
committercyBerta <cyberta@riseup.net>2021-11-25 12:23:04 +0100
commit0ccec2d3bd7c7f890f7b651110ea10a8933eab29 (patch)
tree6809b31be22162523a187ad65b2d18048b7e2e0f /app/src/test
parentdcee5f2fa1dc67e5b08223db3441da8bd38e8b20 (diff)
implement UI, logic and test for prefer UDP preferences
Diffstat (limited to 'app/src/test')
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java12
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java182
-rw-r--r--app/src/test/resources/v4/multiport_tcpudp_eip-service.json67
3 files changed, 239 insertions, 22 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 43a6a496..a3cde58b 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
@@ -114,7 +114,7 @@ public class GatewaysManagerTest {
MockHelper.mockProviderObservable(provider);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
- VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, 3);
+ VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, 3, false);
VpnProfile profile = configGenerator.createProfile(OBFS4);
profile.mGatewayIp = "37.218.247.60";
@@ -129,7 +129,7 @@ public class GatewaysManagerTest {
MockHelper.mockProviderObservable(provider);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
- VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, 3);
+ VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, 3, false);
VpnProfile profile = configGenerator.createProfile(OPENVPN);
profile.mGatewayIp = "37.218.247.60";
@@ -144,7 +144,7 @@ public class GatewaysManagerTest {
MockHelper.mockProviderObservable(provider);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
- VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, 3);
+ VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, 3, false);
VpnProfile profile = configGenerator.createProfile(OBFS4);
profile.mGatewayIp = "37.218.247.60";
@@ -159,7 +159,7 @@ public class GatewaysManagerTest {
MockHelper.mockProviderObservable(provider);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
- VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, 3);
+ VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, 3, false);
VpnProfile profile = configGenerator.createProfile(OPENVPN);
profile.mGatewayIp = "37.218.247.60";
@@ -174,7 +174,7 @@ public class GatewaysManagerTest {
MockHelper.mockProviderObservable(provider);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
- VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, 3);
+ VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, 3, false);
VpnProfile profile = configGenerator.createProfile(OBFS4);
profile.mGatewayIp = "37.218.247.61";
@@ -189,7 +189,7 @@ public class GatewaysManagerTest {
MockHelper.mockProviderObservable(provider);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
- VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, 3);
+ VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, 3, false);
VpnProfile profile = configGenerator.createProfile(OBFS4);
profile.mGatewayIp = "3.21.247.89";
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 56575556..4bacd81a 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java
@@ -12,7 +12,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
-import org.mockito.internal.util.StringUtil;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@@ -1016,6 +1015,138 @@ public class VpnConfigGeneratorTest {
"sndbuf 0 \n" +
"rcvbuf 0 \n";
+ String expectedVPNConfig_v4_ovpn_multiport_tcpudp = "# Config for OpenVPN 2.x\n" +
+ "# Enables connection to GUI\n" +
+ "management /data/data/se.leap.bitmask/mgmtsocket unix\n" +
+ "management-client\n" +
+ "management-query-passwords\n" +
+ "management-hold\n" +
+ "\n" +
+ "setenv IV_GUI_VER \"se.leap.bitmaskclient 0.9.10\" \n" +
+ "setenv IV_PLAT_VER \"0 null JUNIT null null null\"\n" +
+ "machine-readable-output\n" +
+ "allow-recursive-routing\n" +
+ "ifconfig-nowarn\n" +
+ "client\n" +
+ "verb 4\n" +
+ "connect-retry 2 300\n" +
+ "resolv-retry 60\n" +
+ "dev tun\n" +
+ "remote 2001:db8:123::1056 53 udp\n" +
+ "remote 37.218.247.60 53 udp\n" +
+ "remote 2001:db8:123::1056 80 udp\n" +
+ "remote 37.218.247.60 80 udp\n" +
+ "remote 2001:db8:123::1056 1194 udp\n" +
+ "remote 37.218.247.60 1194 udp\n" +
+ "remote 2001:db8:123::1056 53 tcp-client\n" +
+ "remote 37.218.247.60 53 tcp-client\n" +
+ "remote 2001:db8:123::1056 80 tcp-client\n" +
+ "remote 37.218.247.60 80 tcp-client\n" +
+ "remote 2001:db8:123::1056 1194 tcp-client\n" +
+ "remote 37.218.247.60 1194 tcp-client\n" +
+ "<ca>\n" +
+ "-----BEGIN CERTIF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TS1mW7LpxfdCUMbYuLCpyxpO3A/DhAm8n47tUH\n" +
+ "lBtmo8Avdb8VdFpYiGBpB0o9kTFcsWFb2GkWFBduGfSEB8jUI7QtqhgZqocAKK/cweSRV8FwyUcn\n" +
+ "R0prRm3QEi9fbXqEddzjSY9y/lqWYzT7u+IOAQpKroeZ4wzgYperDNOUFuYk1rP7yuvjP2pV5rcN\n" +
+ "yPoBP60TPVWMRM4WJm6nTogAz2qBrFsf/XwT/ajzbsjT6HNB7QbRE+wkFkqspoXG5Agp7KQ8lW3L\n" +
+ "SKCDGOQJz7VIE85pD0tg7QEXBEw8oaRZtMjQ0Gvs25mxXAKka4wGasaWfYH6d0E+iKYcWn86V1rH\n" +
+ "K2ZoknT+Nno5jgjFuUR3fZseNizEfx7BteooKQ==\n" +
+ "-----END CERTIFICATE-----\n" +
+ "</cert>\n" +
+ "crl-verify file missing in config profile\n" +
+ "comp-lzo\n" +
+ "nobind\n"+
+ "remote-cert-tls server\n" +
+ "data-ciphers AES-256-GCM:AES-128-GCM:AES-256-CBC\n" +
+ "cipher AES-256-CBC\n" +
+ "auth SHA1\n" +
+ "persist-tun\n" +
+ "# persist-tun also enables pre resolving to avoid DNS resolve problem\n" +
+ "preresolve\n" +
+ "# Custom configuration options\n" +
+ "# You are on your on own here :)\n" +
+ "# These options found in the config file do not map to config settings:\n" +
+ "keepalive 10 30 \n" +
+ "tls-cipher DHE-RSA-AES128-SHA \n" +
+ "sndbuf 0 \n" +
+ "rcvbuf 0 \n";
@Before
@@ -1035,7 +1166,7 @@ public class VpnConfigGeneratorTest {
@Test
public void testGenerateVpnProfile_v1_tcp_udp() throws Exception {
gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("gateway_tcp_udp.json")));
- vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 1);
+ vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 1, false);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
assertFalse(vpnProfiles.containsKey(OBFS4));
assertTrue(vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim().equals(expectedVPNConfig_v1_tcp_udp.trim()));
@@ -1044,7 +1175,7 @@ public class VpnConfigGeneratorTest {
@Test
public void testGenerateVpnProfile_v1_udp_tcp() throws Exception {
gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("gateway_udp_tcp.json")));
- vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 1);
+ vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 1, false);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
assertFalse(vpnProfiles.containsKey(OBFS4));
assertTrue(vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim().equals(expectedVPNConfig_v1_udp_tcp.trim()));
@@ -1053,7 +1184,7 @@ public class VpnConfigGeneratorTest {
@Test
public void testGenerateVpnProfile_v2_tcp_udp() throws Exception {
gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("gateway_tcp_udp.json")));
- vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 2);
+ vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 2, false);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
assertFalse(vpnProfiles.containsKey(OBFS4));
assertTrue(vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim().equals(expectedVPNConfig_v1_tcp_udp.trim()));
@@ -1062,7 +1193,7 @@ public class VpnConfigGeneratorTest {
@Test
public void testGenerateVpnProfile_v2_udp_tcp() throws Exception {
gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("gateway_udp_tcp.json")));
- vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 2);
+ vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 2, false);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
assertFalse(vpnProfiles.containsKey(OBFS4));
assertTrue(vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim().equals(expectedVPNConfig_v1_udp_tcp.trim()));
@@ -1072,7 +1203,7 @@ public class VpnConfigGeneratorTest {
@Test
public void testGenerateVpnProfile_v3_obfs4() throws Exception {
gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo.bitmask.eip-service.json"))).getJSONArray("gateways").getJSONObject(0);
- vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3);
+ vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3, false);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
assertTrue(vpnProfiles.containsKey(OBFS4));
assertTrue(vpnProfiles.containsKey(OPENVPN));
@@ -1083,7 +1214,7 @@ public class VpnConfigGeneratorTest {
@Test
public void testGenerateVpnProfile_v3_ovpn_tcp_udp() throws Exception {
gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_pt_tcp_udp.eip-service.json"))).getJSONArray("gateways").getJSONObject(0);
- vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3);
+ vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3, false);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
assertTrue(vpnProfiles.containsKey(OBFS4));
assertTrue(vpnProfiles.containsKey(OPENVPN));
@@ -1094,7 +1225,7 @@ public class VpnConfigGeneratorTest {
@Test
public void testGenerateVpnProfile_v3_ovpn_udp_tcp() throws Exception {
gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_pt_udp_tcp.eip-service.json"))).getJSONArray("gateways").getJSONObject(0);
- vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3);
+ vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3, false);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
assertTrue(vpnProfiles.containsKey(OBFS4));
assertTrue(vpnProfiles.containsKey(OPENVPN));
@@ -1107,7 +1238,7 @@ public class VpnConfigGeneratorTest {
gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_pt_udp_tcp.eip-service.json"))).getJSONArray("gateways").getJSONObject(0);
//delete "data-ciphers" from config to test if the resulting openvpn config file will contain the default value taken from "cipher" flag
generalConfig.put("data-ciphers", null);
- vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3);
+ vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3, false);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
assertTrue(vpnProfiles.containsKey(OBFS4));
assertTrue(vpnProfiles.containsKey(OPENVPN));
@@ -1119,7 +1250,7 @@ public class VpnConfigGeneratorTest {
public void testGenerateVpnProfile_v4_ovpn_tcp_udp() throws Exception {
gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("v4/ptdemo_pt_tcp_udp.eip-service.json"))).getJSONArray("gateways").getJSONObject(0);
generalConfig = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("v4/ptdemo_pt_tcp_udp.eip-service.json"))).getJSONObject(OPENVPN_CONFIGURATION);
- vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 4);
+ vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 4, false);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
assertTrue(vpnProfiles.containsKey(OBFS4));
assertTrue(vpnProfiles.containsKey(OPENVPN));
@@ -1131,7 +1262,7 @@ public class VpnConfigGeneratorTest {
public void testGenerateVpnProfile_v4_ovpn_udp_tcp() throws Exception {
gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("v4/ptdemo_pt_udp_tcp.eip-service.json"))).getJSONArray("gateways").getJSONObject(0);
generalConfig = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("v4/ptdemo_pt_udp_tcp.eip-service.json"))).getJSONObject(OPENVPN_CONFIGURATION);
- vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 4);
+ vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 4, false);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
assertTrue(vpnProfiles.containsKey(OBFS4));
assertTrue(vpnProfiles.containsKey(OPENVPN));
@@ -1144,7 +1275,7 @@ public class VpnConfigGeneratorTest {
public void testGenerateVpnProfile_v3_ipv6only_allowOpenvpnIPv6Only() throws Exception {
gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_misconfigured_ipv6.json"))).getJSONArray("gateways").getJSONObject(0);
generalConfig = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_misconfigured_ipv6.json"))).getJSONObject(OPENVPN_CONFIGURATION);
- vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3);
+ vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3, false);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
assertTrue(vpnProfiles.containsKey(OPENVPN));
}
@@ -1153,16 +1284,19 @@ public class VpnConfigGeneratorTest {
public void testGenerateVpnProfile_v3_obfs4IPv6_skip() throws Exception {
gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_misconfigured_ipv6.json"))).getJSONArray("gateways").getJSONObject(0);
generalConfig = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_misconfigured_ipv6.json"))).getJSONObject(OPENVPN_CONFIGURATION);
- vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3);
+ vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3, false);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
assertFalse(vpnProfiles.containsKey(OBFS4));
}
+ /**
+ * obfs4 cannot be used with ipv6 addresses currently
+ */
@Test
public void testGenerateVpnProfile_v3_obfs4IPv4AndIPv6_skipIPv6() throws Exception {
gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_misconfigured_ipv4ipv6.json"))).getJSONArray("gateways").getJSONObject(0);
generalConfig = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_misconfigured_ipv4ipv6.json"))).getJSONObject(OPENVPN_CONFIGURATION);
- vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3);
+ vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3, false);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
assertTrue(vpnProfiles.containsKey(OBFS4));
assertTrue(vpnProfiles.containsKey(OPENVPN));
@@ -1170,11 +1304,14 @@ public class VpnConfigGeneratorTest {
assertEquals("37.218.247.60/32", vpnProfiles.get(OBFS4).mExcludedRoutes.trim());
}
+ /**
+ * obfs4 cannot be used with UDP
+ */
@Test
public void testGenerateVpnProfile_v3_obfs4udp_skip() throws Exception {
gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_misconfigured_udp.json"))).getJSONArray("gateways").getJSONObject(0);
generalConfig = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_misconfigured_udp.json"))).getJSONObject(OPENVPN_CONFIGURATION);
- vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3);
+ vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3, false);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
assertFalse(vpnProfiles.containsKey(OBFS4));
assertTrue(vpnProfiles.containsKey(OPENVPN));
@@ -1184,7 +1321,7 @@ public class VpnConfigGeneratorTest {
public void testGenerateVpnProfile_v3_obfs4UDPAndTCP_skipUDP() throws Exception {
gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_misconfigured_udptcp.json"))).getJSONArray("gateways").getJSONObject(0);
generalConfig = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_misconfigured_udptcp.json"))).getJSONObject(OPENVPN_CONFIGURATION);
- vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3);
+ vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3, false);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
assertTrue(vpnProfiles.containsKey(OBFS4));
assertTrue(vpnProfiles.containsKey(OPENVPN));
@@ -1192,4 +1329,17 @@ public class VpnConfigGeneratorTest {
assertFalse(vpnProfiles.get(OBFS4).mConnections[0].isUseUdp());
}
+ @Test
+ public void testGenerateVpnProfile_preferUDP_firstRemotesUDP() throws Exception {
+ gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("v4/multiport_tcpudp_eip-service.json"))).getJSONArray("gateways").getJSONObject(0);
+ generalConfig = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("v4/multiport_tcpudp_eip-service.json"))).getJSONObject(OPENVPN_CONFIGURATION);
+ vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3, true);
+ HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
+ assertTrue(vpnProfiles.containsKey(OBFS4));
+ assertTrue(vpnProfiles.containsKey(OPENVPN));
+ System.out.println(vpnProfiles.get(OPENVPN).getConfigFile(context, false));
+ System.out.println(expectedVPNConfig_v4_ovpn_multiport_tcpudp.trim());
+ assertTrue(vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim().equals(expectedVPNConfig_v4_ovpn_multiport_tcpudp.trim()));
+ }
+
} \ No newline at end of file
diff --git a/app/src/test/resources/v4/multiport_tcpudp_eip-service.json b/app/src/test/resources/v4/multiport_tcpudp_eip-service.json
new file mode 100644
index 00000000..c713e632
--- /dev/null
+++ b/app/src/test/resources/v4/multiport_tcpudp_eip-service.json
@@ -0,0 +1,67 @@
+{
+ "gateways":[
+ {
+ "capabilities":{
+ "adblock":false,
+ "filter_dns":false,
+ "limited":false,
+ "transport":[
+ {
+ "ports":[
+ "53",
+ "80",
+ "1194"
+ ],
+ "protocols":[
+ "tcp",
+ "udp"
+ ],
+ "type":"openvpn"
+ },
+ {
+ "options":{
+ "cert":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
+ "iatMode":"0"
+ },
+ "ports":[
+ "443"
+ ],
+ "protocols":[
+ "tcp"
+ ],
+ "type":"obfs4"
+ }
+ ]
+ },
+ "host":"pt.demo.bitmask.net",
+ "ip_address":"37.218.247.60",
+ "ip_address6":"2001:db8:123::1056",
+ "location":"Amsterdam"
+ }
+ ],
+ "locations":{
+ "Amsterdam":{
+ "country_code":"NL",
+ "hemisphere":"N",
+ "name":"Amsterdam",
+ "timezone":"-1"
+ }
+ },
+ "openvpn_configuration":{
+ "auth":"SHA1",
+ "cipher":"AES-256-CBC",
+ "keepalive":"10 30",
+ "tls-cipher":"DHE-RSA-AES128-SHA",
+ "tun-ipv6":true,
+ "dev" : "tun",
+ "sndbuf" : "0",
+ "rcvbuf" : "0",
+ "nobind" : true,
+ "persist-key" : true,
+ "comp-lzo" : true,
+ "key-direction" : "1",
+ "verb" : "3"
+ },
+ "serial":3,
+ "version":3
+} \ No newline at end of file