diff options
Diffstat (limited to 'app/src/test/java')
3 files changed, 364 insertions, 174 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/GatewayTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/GatewayTest.java new file mode 100644 index 00000000..66c139b2 --- /dev/null +++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewayTest.java @@ -0,0 +1,154 @@ +package se.leap.bitmaskclient.eip; + +import static org.junit.Assert.*; + +import static se.leap.bitmaskclient.base.models.Constants.GATEWAYS; +import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_PRIVATE_KEY; +import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_VPN_CERTIFICATE; +import static se.leap.bitmaskclient.base.models.Provider.CA_CERT; +import static se.leap.bitmaskclient.testutils.TestSetupHelper.getProvider; + +import android.content.Context; +import android.content.SharedPreferences; + +import androidx.annotation.Nullable; + +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Answers; +import org.mockito.Mock; + +import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; + +import de.blinkt.openvpn.VpnProfile; +import de.blinkt.openvpn.core.ConfigParser; +import de.blinkt.openvpn.core.connection.Connection; +import de.blinkt.openvpn.core.connection.Obfs4Connection; +import se.leap.bitmaskclient.base.models.Provider; +import se.leap.bitmaskclient.base.models.ProviderObservable; +import se.leap.bitmaskclient.base.utils.PreferenceHelper; +import se.leap.bitmaskclient.base.utils.TimezoneHelper; +import se.leap.bitmaskclient.testutils.MockSharedPreferences; +import se.leap.bitmaskclient.testutils.TestSetupHelper; + +public class GatewayTest { + + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private Context mockContext; + + private SharedPreferences sharedPreferences; + + @Before + public void setUp() throws IOException, JSONException { + sharedPreferences = new MockSharedPreferences(); + + PreferenceHelper preferenceHelper = new PreferenceHelper(sharedPreferences); + } + + + private Gateway createGatewayFromProvider(int nClosest, @Nullable String eipServiceJsonPath) throws ConfigParser.ConfigParseError, JSONException, IOException { + Provider provider = getProvider(null, null, null, null, null, null, eipServiceJsonPath, null); + JSONObject eipServiceJson = provider.getEipServiceJson(); + + JSONObject gatewayJson = eipServiceJson.getJSONArray(GATEWAYS).getJSONObject(0); + JSONObject secrets = new JSONObject(); + try { + secrets.put(Provider.CA_CERT, provider.getCaCert()); + secrets.put(PROVIDER_VPN_CERTIFICATE, provider.getVpnCertificate()); + } catch (JSONException e) { + e.printStackTrace(); + } + + + return new Gateway(eipServiceJson, secrets, gatewayJson); + } + @Test + public void testGetProfile_OpenVPN_obfuscationProtocols_ignored_OpenVPNfound() throws ConfigParser.ConfigParseError, JSONException, IOException { + Gateway gateway = createGatewayFromProvider(0, "ptdemo_three_mixed_gateways.json"); + VpnProfile profile = gateway.getProfile(Connection.TransportType.OPENVPN, new HashSet<>(Arrays.asList("invalid"))); + assertNotNull(profile); + } + + @Test + public void testGetProfile_obfs4_obfuscationProtocolsTakenIntoAccount_Obfs4Notfound() throws ConfigParser.ConfigParseError, JSONException, IOException { + Gateway gateway = createGatewayFromProvider(0, "ptdemo_three_mixed_gateways.json"); + VpnProfile profile = gateway.getProfile(Connection.TransportType.OBFS4, new HashSet<>(Arrays.asList("invalid"))); + assertNull(profile); + } + + @Test + public void testGetProfile_obfs4_obfuscationProtocolsTakenIntoAccount_Obfs4found() throws ConfigParser.ConfigParseError, JSONException, IOException { + Gateway gateway = createGatewayFromProvider(0, "ptdemo_three_mixed_gateways.json"); + VpnProfile profile = gateway.getProfile(Connection.TransportType.OBFS4, new HashSet<>(Arrays.asList("tcp"))); + assertNotNull(profile); + } + + @Test + public void testGetProfile_obfs4_obfuscationProtocolsTakenIntoAccount_Obfs4KCPfound() throws ConfigParser.ConfigParseError, JSONException, IOException { + Gateway gateway = createGatewayFromProvider(0, "multiple_pts_per_host_eip-service.json"); + VpnProfile profile = gateway.getProfile(Connection.TransportType.OBFS4, new HashSet<>(Arrays.asList("kcp"))); + assertNotNull(profile); + } + + @Test + public void testGetProfile_obfs4_multipleProfiles_randomlySelected() throws ConfigParser.ConfigParseError, JSONException, IOException { + Gateway gateway = createGatewayFromProvider(0, "multiple_pts_per_host_eip-service.json"); + VpnProfile profile1 = gateway.getProfile(Connection.TransportType.OBFS4, new HashSet<>(Arrays.asList("kcp", "tcp"))); + assertNotNull(profile1); + assertEquals(1, profile1.mConnections.length); + assertTrue(profile1.mConnections[0] instanceof Obfs4Connection); + String[] transportLayerProtocols = ((Obfs4Connection)profile1.mConnections[0]).getObfs4Options().transport.getProtocols(); + + boolean profileWithDifferentTransportLayerProtosFound = false; + for (int i = 0; i < 1000; i++) { + VpnProfile otherProfile = gateway.getProfile(Connection.TransportType.OBFS4, new HashSet<>(Arrays.asList("kcp", "tcp"))); + String[] otherProtocols = ((Obfs4Connection)otherProfile.mConnections[0]).getObfs4Options().transport.getProtocols(); + if (!transportLayerProtocols[0].equals(otherProtocols[0])) { + profileWithDifferentTransportLayerProtosFound = true; + System.out.println(i + 1 + " attempts"); + break; + } + } + assertTrue(profileWithDifferentTransportLayerProtosFound); + } + + @Test + public void testSupportsTransport() throws ConfigParser.ConfigParseError, JSONException, IOException { + Gateway gateway = createGatewayFromProvider(0, "multiple_pts_per_host_eip-service.json"); + assertFalse(gateway.supportsTransport(Connection.TransportType.OBFS4_HOP, null)); + assertTrue(gateway.supportsTransport(Connection.TransportType.OBFS4, null)); + assertTrue(gateway.supportsTransport(Connection.TransportType.OBFS4, new HashSet<>(Arrays.asList("kcp")))); + assertTrue(gateway.supportsTransport(Connection.TransportType.OBFS4, new HashSet<>(Arrays.asList("tcp")))); + assertFalse(gateway.supportsTransport(Connection.TransportType.OBFS4, new HashSet<>(Arrays.asList("invalid")))); + } + + @Test + public void testGetSupportedTransports() throws ConfigParser.ConfigParseError, JSONException, IOException { + Gateway gateway = createGatewayFromProvider(0, "multiple_pts_per_host_eip-service.json"); + assertEquals(2, gateway.getSupportedTransports().size()); + assertTrue(gateway.getSupportedTransports().contains(Connection.TransportType.OBFS4)); + assertTrue(gateway.getSupportedTransports().contains(Connection.TransportType.OPENVPN)); + } + + @Test + public void testHasProfile() throws ConfigParser.ConfigParseError, JSONException, IOException { + Gateway gateway = createGatewayFromProvider(0, "multiple_pts_per_host_eip-service.json"); + VpnProfile profile = gateway.getProfiles().get(0); + String profileString = profile.toJson(); + VpnProfile newProfile = VpnProfile.fromJson(profileString); + assertTrue(gateway.hasProfile(newProfile)); + + newProfile.mGatewayIp = "XXXX"; + assertFalse(gateway.hasProfile(newProfile)); + + VpnProfile newProfile2 = VpnProfile.fromJson(profileString); + newProfile2.mConnections = new Connection[0]; + assertFalse(gateway.hasProfile(newProfile2)); + } + + +}
\ No newline at end of file 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 9286a787..b79c34ae 100644 --- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java @@ -3,6 +3,7 @@ package se.leap.bitmaskclient.eip; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNull; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static de.blinkt.openvpn.core.connection.Connection.TransportType.OBFS4; @@ -20,11 +21,12 @@ import static se.leap.bitmaskclient.testutils.TestSetupHelper.getProvider; import android.content.Context; import android.content.SharedPreferences; +import androidx.annotation.Nullable; + import org.json.JSONException; import org.json.JSONObject; import org.junit.Before; import org.junit.Test; -import org.junit.function.ThrowingRunnable; import org.mockito.Answers; import org.mockito.Mock; @@ -34,9 +36,11 @@ import java.util.List; import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.core.ConfigParser; +import de.blinkt.openvpn.core.connection.Connection; import se.leap.bitmaskclient.base.models.Location; import se.leap.bitmaskclient.base.models.Provider; import se.leap.bitmaskclient.base.models.ProviderObservable; +import se.leap.bitmaskclient.base.models.Transport; import se.leap.bitmaskclient.base.utils.PreferenceHelper; import se.leap.bitmaskclient.base.utils.TimezoneHelper; import se.leap.bitmaskclient.testutils.MockSharedPreferences; @@ -87,6 +91,18 @@ public class GatewaysManagerTest { assertEquals(3, gatewaysManager.size()); } + @Nullable + private static VpnProfile createProfile(VpnConfigGenerator configGenerator, Connection.TransportType transportType) throws IOException, ConfigParser.ConfigParseError, JSONException { + VpnProfile profile = null; + for (Transport transport : configGenerator.transports) { + if (transport.getTransportType() == transportType) { + profile = configGenerator.createProfile(transport); + break; + } + } + return profile; + } + @Test public void TestGetPosition_VpnProfileExtistingObfs4_returnPositionZero() throws JSONException, ConfigParser.ConfigParseError, IOException { Provider provider = getProvider(null, null, null, null, null, null, "ptdemo_three_mixed_gateways.json", null); @@ -99,9 +115,10 @@ public class GatewaysManagerTest { configuration.apiVersion = 3; configuration.remoteGatewayIP = "37.218.247.60"; VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, configuration); - VpnProfile profile = configGenerator.createProfile(OBFS4); - + VpnProfile profile = createProfile(configGenerator, OBFS4); + assertNotNull(profile); assertEquals(0, gatewaysManager.getPosition(profile)); + } @Test @@ -116,8 +133,8 @@ public class GatewaysManagerTest { configuration.apiVersion = 3; configuration.remoteGatewayIP = "37.218.247.60"; VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, configuration); - VpnProfile profile = configGenerator.createProfile(OPENVPN); - + VpnProfile profile = createProfile(configGenerator, OPENVPN); + assertNotNull(profile); assertEquals(0, gatewaysManager.getPosition(profile)); } @@ -133,7 +150,7 @@ public class GatewaysManagerTest { configuration.apiVersion = 3; configuration.remoteGatewayIP = "37.218.247.60"; VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, configuration); - assertThrows(ConfigParser.ConfigParseError.class, () -> configGenerator.createProfile(OBFS4)); + assertThrows(ConfigParser.ConfigParseError.class, () -> createProfile(configGenerator, OBFS4)); } @Test @@ -148,9 +165,9 @@ public class GatewaysManagerTest { configuration.apiVersion = 3; configuration.remoteGatewayIP = "37.218.247.60"; VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, configuration); - VpnProfile profile = configGenerator.createProfile(OBFS4); + VpnProfile profile = createProfile(configGenerator, OBFS4); - assertEquals(1, gatewaysManager.getPosition(profile)); + assertEquals(2, gatewaysManager.getPosition(profile)); } @Test @@ -165,7 +182,7 @@ public class GatewaysManagerTest { configuration.apiVersion = 3; configuration.remoteGatewayIP = "37.218.247.60"; VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, configuration); - VpnProfile profile = configGenerator.createProfile(OPENVPN); + VpnProfile profile = createProfile(configGenerator, OPENVPN); assertEquals(2, gatewaysManager.getPosition(profile)); } @@ -182,7 +199,7 @@ public class GatewaysManagerTest { configuration.apiVersion = 3; configuration.remoteGatewayIP = "37.218.247.61"; VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, configuration); - VpnProfile profile = configGenerator.createProfile(OBFS4); + VpnProfile profile = createProfile(configGenerator, OBFS4); assertEquals(-1, gatewaysManager.getPosition(profile)); } @@ -199,7 +216,7 @@ public class GatewaysManagerTest { configuration.apiVersion = 3; configuration.remoteGatewayIP = "3.21.247.89"; VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, configuration); - VpnProfile profile = configGenerator.createProfile(OBFS4); + VpnProfile profile = createProfile(configGenerator, OBFS4); assertEquals(1, gatewaysManager.getPosition(profile)); } @@ -212,7 +229,7 @@ public class GatewaysManagerTest { sharedPreferences.edit().putBoolean(USE_BRIDGES, true).commit(); GatewaysManager gatewaysManager = new GatewaysManager(mockContext); - assertEquals("37.12.247.10", gatewaysManager.select(0).gateway.getRemoteIP()); + assertEquals("37.12.247.10", gatewaysManager.selectVpnProfile(0).mGatewayIp); } @Test @@ -226,11 +243,11 @@ public class GatewaysManagerTest { commit(); GatewaysManager gatewaysManager = new GatewaysManager(mockContext); ArrayList<String> hosts = new ArrayList<>(); - hosts.add(gatewaysManager.select(0).gateway.getHost()); - hosts.add(gatewaysManager.select(1).gateway.getHost()); + hosts.add(gatewaysManager.selectVpnProfile(0).mGatewayIp); + hosts.add(gatewaysManager.selectVpnProfile(1).mGatewayIp); - assertTrue(hosts.contains("bridge-nyc1-02.bitmask-dev.leapvpn.net")); - assertTrue(hosts.contains("bridge-nyc1-01.bitmask-dev.leapvpn.net")); + assertTrue(hosts.contains("192.81.208.164")); + assertTrue(hosts.contains("104.248.232.240")); } @@ -246,10 +263,10 @@ public class GatewaysManagerTest { GatewaysManager gatewaysManager = new GatewaysManager(mockContext); ArrayList<String> hosts = new ArrayList<>(); - hosts.add(gatewaysManager.select(0).gateway.getHost()); - hosts.add(gatewaysManager.select(1).gateway.getHost()); - assertTrue(hosts.contains("bridge-nyc1-02.bitmask-dev.leapvpn.net")); - assertTrue(hosts.contains("bridge-nyc1-01.bitmask-dev.leapvpn.net")); + hosts.add(gatewaysManager.selectVpnProfile(0).mGatewayIp); + hosts.add(gatewaysManager.selectVpnProfile(1).mGatewayIp); + assertTrue(hosts.contains("192.81.208.164")); + assertTrue(hosts.contains("104.248.232.240")); } @Test @@ -264,7 +281,7 @@ public class GatewaysManagerTest { for (int i = 0; i < 1000; i++) { GatewaysManager gatewaysManager = new GatewaysManager(mockContext); - assertEquals("bridge-nyc1-01.bitmask-dev.leapvpn.net", gatewaysManager.select(0).gateway.getHost()); + assertEquals("104.248.232.240", gatewaysManager.selectVpnProfile(0).mGatewayIp); } } @@ -279,8 +296,8 @@ public class GatewaysManagerTest { commit(); GatewaysManager gatewaysManager = new GatewaysManager(mockContext); - assertEquals("bridge-nyc1-01.bitmask-dev.leapvpn.net", gatewaysManager.select(0).gateway.getHost()); - assertNull(gatewaysManager.select(1)); + assertEquals("104.248.232.240", gatewaysManager.selectVpnProfile(0).mGatewayIp); + assertNull(gatewaysManager.selectVpnProfile(1)); } @Test @@ -295,11 +312,11 @@ public class GatewaysManagerTest { GatewaysManager gatewaysManager = new GatewaysManager(mockContext); ArrayList<String> hosts = new ArrayList<>(); - hosts.add(gatewaysManager.select(0).gateway.getHost()); - hosts.add(gatewaysManager.select(1).gateway.getHost()); + hosts.add(gatewaysManager.selectVpnProfile(0).mGatewayIp); + hosts.add(gatewaysManager.selectVpnProfile(1).mGatewayIp); - assertTrue(hosts.contains("pt.demo.bitmask.net")); - assertTrue(hosts.contains("manila.bitmask.net")); + assertTrue(hosts.contains("37.218.247.60")); + assertTrue(hosts.contains("37.12.247.10")); } @Test @@ -309,9 +326,9 @@ public class GatewaysManagerTest { providerObservable.updateProvider(provider); GatewaysManager gatewaysManager = new GatewaysManager(mockContext); - 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()); + assertEquals("37.12.247.10", gatewaysManager.selectVpnProfile(0).mGatewayIp); + assertEquals("3.21.247.89", gatewaysManager.selectVpnProfile(1).mGatewayIp); + assertEquals("37.218.247.60", gatewaysManager.selectVpnProfile(2).mGatewayIp); } @Test @@ -325,9 +342,9 @@ public class GatewaysManagerTest { commit(); GatewaysManager gatewaysManager = new GatewaysManager(mockContext); - assertEquals("moscow.bitmask.net", gatewaysManager.select(0).gateway.getHost()); - assertEquals("pt.demo.bitmask.net", gatewaysManager.select(1).gateway.getHost()); - assertNull(gatewaysManager.select(2)); + assertEquals("3.21.247.89", gatewaysManager.selectVpnProfile(0).mGatewayIp); + assertEquals("37.218.247.60", gatewaysManager.selectVpnProfile(1).mGatewayIp); + assertNull(gatewaysManager.selectVpnProfile(2)); } @@ -342,9 +359,9 @@ public class GatewaysManagerTest { commit(); GatewaysManager gatewaysManager = new GatewaysManager(mockContext); - 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()); + assertEquals("163.172.126.44", gatewaysManager.selectVpnProfile(0).mGatewayIp); + assertEquals("212.83.143.67", gatewaysManager.selectVpnProfile(1).mGatewayIp); + assertEquals("212.129.62.247", gatewaysManager.selectVpnProfile(2).mGatewayIp); } @Test @@ -358,9 +375,9 @@ public class GatewaysManagerTest { commit(); GatewaysManager gatewaysManager = new GatewaysManager(mockContext); - 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()); + assertEquals("163.172.126.44", gatewaysManager.selectVpnProfile(0).mGatewayIp); + assertEquals("212.83.143.67", gatewaysManager.selectVpnProfile(1).mGatewayIp); + assertEquals("212.129.62.247", gatewaysManager.selectVpnProfile(2).mGatewayIp); } @Test @@ -375,10 +392,10 @@ public class GatewaysManagerTest { commit(); GatewaysManager gatewaysManager = new GatewaysManager(mockContext); - 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)); + assertEquals("Paris", gatewaysManager.selectVpnProfile(0).getName()); + assertEquals("Paris", gatewaysManager.selectVpnProfile(1).getName()); + assertEquals("Paris", gatewaysManager.selectVpnProfile(2).getName()); + assertEquals(null, gatewaysManager.selectVpnProfile(3)); } @Test @@ -388,9 +405,9 @@ public class GatewaysManagerTest { providerObservable.updateProvider(provider); GatewaysManager gatewaysManager = new GatewaysManager(mockContext); - 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()); + assertEquals("163.172.126.44", gatewaysManager.selectVpnProfile(0, "Paris").mGatewayIp); + assertEquals("212.83.143.67", gatewaysManager.selectVpnProfile(1, "Paris").mGatewayIp); + assertEquals("212.129.62.247", gatewaysManager.selectVpnProfile(2, "Paris").mGatewayIp); } @Test @@ -400,9 +417,9 @@ public class GatewaysManagerTest { providerObservable.updateProvider(provider); GatewaysManager gatewaysManager = new GatewaysManager(mockContext); - 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()); + assertEquals("163.172.126.44", gatewaysManager.selectVpnProfile(0, "Paris").mGatewayIp); + assertEquals("212.83.143.67", gatewaysManager.selectVpnProfile(1, "Paris").mGatewayIp); + assertEquals("212.129.62.247", gatewaysManager.selectVpnProfile(2, "Paris").mGatewayIp); } @Test @@ -413,10 +430,10 @@ public class GatewaysManagerTest { providerObservable.updateProvider(provider); GatewaysManager gatewaysManager = new GatewaysManager(mockContext); - 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")); + assertEquals("Paris", gatewaysManager.selectVpnProfile(0, "Paris").getName()); + assertEquals("Paris", gatewaysManager.selectVpnProfile(1, "Paris").getName()); + assertEquals("Paris", gatewaysManager.selectVpnProfile(2, "Paris").getName()); + assertEquals(null, gatewaysManager.selectVpnProfile(3, "Paris")); } @Test @@ -426,7 +443,7 @@ public class GatewaysManagerTest { provider.setGeoIpJson(new JSONObject()); providerObservable.updateProvider(provider); GatewaysManager gatewaysManager = new GatewaysManager(mockContext); - assertNull(gatewaysManager.select(0, "Stockholm")); + assertNull(gatewaysManager.selectVpnProfile(0, "Stockholm")); } @Test 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 547bb3df..5343c466 100644 --- a/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java @@ -19,6 +19,7 @@ import org.junit.Test; import java.io.File; import java.util.HashMap; +import java.util.Vector; import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.core.ConfigParser; @@ -1353,15 +1354,33 @@ public class VpnConfigGeneratorTest { when(context.getCacheDir()).thenReturn(new File("/data/data/se.leap.bitmask")); } + private static boolean containsKey(Vector<VpnProfile> profiles, Connection.TransportType transportType) { + for (VpnProfile profile : profiles) { + if (profile.getTransportType() == transportType) { + return true; + } + } + return false; + } + + private static VpnProfile getVpnProfile(Vector<VpnProfile> profiles, Connection.TransportType transportType) { + for (VpnProfile profile : profiles) { + if (profile.getTransportType() == transportType) { + return profile; + } + } + return null; + } + @Test public void testGenerateVpnProfile_v1_tcp_udp() throws Exception { gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("gateway_tcp_udp.json"))); VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 1; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertFalse(vpnProfiles.containsKey(OBFS4)); - assertEquals(expectedVPNConfig_v1_tcp_udp.trim(), vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim()); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertFalse(containsKey(vpnProfiles, OBFS4)); + assertEquals(expectedVPNConfig_v1_tcp_udp.trim(), getVpnProfile(vpnProfiles, OPENVPN).getConfigFile(context, false).trim()); } @Test @@ -1370,9 +1389,9 @@ public class VpnConfigGeneratorTest { VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 1; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertFalse(vpnProfiles.containsKey(OBFS4)); - assertEquals(expectedVPNConfig_v1_udp_tcp.trim(), vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim()); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertFalse(containsKey(vpnProfiles, OBFS4)); + assertEquals(expectedVPNConfig_v1_udp_tcp.trim(), getVpnProfile(vpnProfiles, OPENVPN).getConfigFile(context, false).trim()); } @Test @@ -1381,9 +1400,9 @@ public class VpnConfigGeneratorTest { VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 2; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertFalse(vpnProfiles.containsKey(OBFS4)); - assertEquals(expectedVPNConfig_v1_tcp_udp.trim(), vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim()); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertFalse(containsKey(vpnProfiles, OBFS4)); + assertEquals(expectedVPNConfig_v1_tcp_udp.trim(), getVpnProfile(vpnProfiles, OPENVPN).getConfigFile(context, false).trim()); } @Test @@ -1392,9 +1411,9 @@ public class VpnConfigGeneratorTest { VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 2; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertFalse(vpnProfiles.containsKey(OBFS4)); - assertEquals(expectedVPNConfig_v1_udp_tcp.trim(), vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim()); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertFalse(containsKey(vpnProfiles, OBFS4)); + assertEquals(expectedVPNConfig_v1_udp_tcp.trim(), getVpnProfile(vpnProfiles, OPENVPN).getConfigFile(context, false).trim()); } @@ -1405,11 +1424,11 @@ public class VpnConfigGeneratorTest { VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 3; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertTrue(vpnProfiles.containsKey(OBFS4)); - assertTrue(vpnProfiles.containsKey(OPENVPN)); - System.out.println(vpnProfiles.get(OBFS4).getConfigFile(context, false)); - assertEquals(expectedVPNConfig_v3_obfs4.trim(), vpnProfiles.get(OBFS4).getConfigFile(context, false).trim()); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertTrue(containsKey(vpnProfiles, OBFS4)); + assertTrue(containsKey(vpnProfiles, OPENVPN)); + System.out.println(getVpnProfile(vpnProfiles, OBFS4).getConfigFile(context, false)); + assertEquals(expectedVPNConfig_v3_obfs4.trim(), getVpnProfile(vpnProfiles, OBFS4).getConfigFile(context, false).trim()); } @Test @@ -1419,11 +1438,11 @@ public class VpnConfigGeneratorTest { VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 3; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertTrue(vpnProfiles.containsKey(OBFS4)); - assertTrue(vpnProfiles.containsKey(OPENVPN)); - System.out.println(vpnProfiles.get(OBFS4).getConfigFile(context, false)); - assertEquals(expectedVPNConfig_v3_obfsvpn_obfs4.trim(), vpnProfiles.get(OBFS4).getConfigFile(context, false).trim()); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertTrue(containsKey(vpnProfiles, OBFS4)); + assertTrue(containsKey(vpnProfiles, OPENVPN)); + System.out.println(getVpnProfile(vpnProfiles, OBFS4).getConfigFile(context, false)); + assertEquals(expectedVPNConfig_v3_obfsvpn_obfs4.trim(), getVpnProfile(vpnProfiles, OBFS4).getConfigFile(context, false).trim()); } @Test @@ -1432,11 +1451,11 @@ public class VpnConfigGeneratorTest { VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 3; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertTrue(vpnProfiles.containsKey(OBFS4)); - assertTrue(vpnProfiles.containsKey(OPENVPN)); - System.out.println(vpnProfiles.get(OPENVPN).getConfigFile(context, false)); - assertEquals(expectedVPNConfig_v3_ovpn_tcp_udp.trim(), vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim()); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertTrue(containsKey(vpnProfiles, OBFS4)); + assertTrue(containsKey(vpnProfiles, OPENVPN)); + System.out.println(getVpnProfile(vpnProfiles, OPENVPN).getConfigFile(context, false)); + assertEquals(expectedVPNConfig_v3_ovpn_tcp_udp.trim(), getVpnProfile(vpnProfiles, OPENVPN).getConfigFile(context, false).trim()); } @Test @@ -1445,11 +1464,11 @@ public class VpnConfigGeneratorTest { VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 3; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertTrue(vpnProfiles.containsKey(OBFS4)); - assertTrue(vpnProfiles.containsKey(OPENVPN)); - System.out.println(vpnProfiles.get(OPENVPN).getConfigFile(context, false)); - assertEquals(expectedVPNConfig_v3_ovpn_udp_tcp.trim(), vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim()); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertTrue(containsKey(vpnProfiles, OBFS4)); + assertTrue(containsKey(vpnProfiles, OPENVPN)); + System.out.println(getVpnProfile(vpnProfiles, OPENVPN).getConfigFile(context, false)); + assertEquals(expectedVPNConfig_v3_ovpn_udp_tcp.trim(), getVpnProfile(vpnProfiles, OPENVPN).getConfigFile(context, false).trim()); } @Test @@ -1460,11 +1479,11 @@ public class VpnConfigGeneratorTest { VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 3; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertTrue(vpnProfiles.containsKey(OBFS4)); - assertTrue(vpnProfiles.containsKey(OPENVPN)); - System.out.println(vpnProfiles.get(OPENVPN).getConfigFile(context, false)); - assertEquals(expectedVPNConfig_v3_ovpn_udp_tcp_defaultDataCiphers.trim(), vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim()); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertTrue(containsKey(vpnProfiles, OBFS4)); + assertTrue(containsKey(vpnProfiles, OPENVPN)); + System.out.println(getVpnProfile(vpnProfiles, OPENVPN).getConfigFile(context, false)); + assertEquals(expectedVPNConfig_v3_ovpn_udp_tcp_defaultDataCiphers.trim(), getVpnProfile(vpnProfiles, OPENVPN).getConfigFile(context, false).trim()); } @Test @@ -1474,11 +1493,11 @@ public class VpnConfigGeneratorTest { VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 4; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertTrue(vpnProfiles.containsKey(OBFS4)); - assertTrue(vpnProfiles.containsKey(OPENVPN)); - System.out.println(vpnProfiles.get(OPENVPN).getConfigFile(context, false)); - assertEquals(expectedVPNConfig_v4_ovpn_tcp_udp.trim(), vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim()); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertTrue(containsKey(vpnProfiles, OBFS4)); + assertTrue(containsKey(vpnProfiles, OPENVPN)); + System.out.println(getVpnProfile(vpnProfiles, OPENVPN).getConfigFile(context, false)); + assertEquals(expectedVPNConfig_v4_ovpn_tcp_udp.trim(), getVpnProfile(vpnProfiles, OPENVPN).getConfigFile(context, false).trim()); } @Test @@ -1488,11 +1507,11 @@ public class VpnConfigGeneratorTest { VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 4; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertTrue(vpnProfiles.containsKey(OBFS4)); - assertTrue(vpnProfiles.containsKey(OPENVPN)); - System.out.println(vpnProfiles.get(OPENVPN).getConfigFile(context, false)); - assertEquals(expectedVPNConfig_v4_ovpn_udp_tcp.trim(), vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim()); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertTrue(containsKey(vpnProfiles, OBFS4)); + assertTrue(containsKey(vpnProfiles, OPENVPN)); + System.out.println(getVpnProfile(vpnProfiles, OPENVPN).getConfigFile(context, false)); + assertEquals(expectedVPNConfig_v4_ovpn_udp_tcp.trim(), getVpnProfile(vpnProfiles, OPENVPN).getConfigFile(context, false).trim()); } @Test @@ -1502,8 +1521,8 @@ public class VpnConfigGeneratorTest { VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 3; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertTrue(vpnProfiles.containsKey(OPENVPN)); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertTrue(containsKey(vpnProfiles, OPENVPN)); } @Test @@ -1513,8 +1532,8 @@ public class VpnConfigGeneratorTest { VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 3; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertFalse(vpnProfiles.containsKey(OBFS4)); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertFalse(containsKey(vpnProfiles, OBFS4)); } /** @@ -1527,11 +1546,11 @@ public class VpnConfigGeneratorTest { VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 3; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertTrue(vpnProfiles.containsKey(OBFS4)); - assertTrue(vpnProfiles.containsKey(OPENVPN)); - assertEquals(1, vpnProfiles.get(OBFS4).mConnections.length); - assertEquals("37.218.247.60/32", vpnProfiles.get(OBFS4).mExcludedRoutes.trim()); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertTrue(containsKey(vpnProfiles, OBFS4)); + assertTrue(containsKey(vpnProfiles, OPENVPN)); + assertEquals(1, getVpnProfile(vpnProfiles, OBFS4).mConnections.length); + assertEquals("37.218.247.60/32", getVpnProfile(vpnProfiles, OBFS4).mExcludedRoutes.trim()); } /** @@ -1544,9 +1563,9 @@ public class VpnConfigGeneratorTest { VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 3; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertFalse(vpnProfiles.containsKey(OBFS4)); - assertTrue(vpnProfiles.containsKey(OPENVPN)); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertFalse(containsKey(vpnProfiles, OBFS4)); + assertTrue(containsKey(vpnProfiles, OPENVPN)); } /** @@ -1559,9 +1578,9 @@ public class VpnConfigGeneratorTest { VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 3; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertFalse(vpnProfiles.containsKey(OBFS4)); - assertTrue(vpnProfiles.containsKey(OPENVPN)); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertFalse(containsKey(vpnProfiles, OBFS4)); + assertTrue(containsKey(vpnProfiles, OPENVPN)); } @Test @@ -1571,10 +1590,10 @@ public class VpnConfigGeneratorTest { VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 3; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertTrue(vpnProfiles.containsKey(OBFS4)); - assertTrue(vpnProfiles.containsKey(OPENVPN)); - assertEquals(1, vpnProfiles.get(OBFS4).mConnections.length); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertTrue(containsKey(vpnProfiles, OBFS4)); + assertTrue(containsKey(vpnProfiles, OPENVPN)); + assertEquals(1, getVpnProfile(vpnProfiles, OBFS4).mConnections.length); } @Test @@ -1585,11 +1604,11 @@ public class VpnConfigGeneratorTest { configuration.apiVersion = 3; configuration.preferUDP = true; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertTrue(vpnProfiles.containsKey(OBFS4)); - assertTrue(vpnProfiles.containsKey(OPENVPN)); - System.out.println(vpnProfiles.get(OPENVPN).getConfigFile(context, false)); - assertEquals(expectedVPNConfig_v4_ovpn_multiport_tcpudp.trim(), vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim()); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertTrue(containsKey(vpnProfiles, OBFS4)); + assertTrue(containsKey(vpnProfiles, OPENVPN)); + System.out.println(getVpnProfile(vpnProfiles, OPENVPN).getConfigFile(context, false)); + assertEquals(expectedVPNConfig_v4_ovpn_multiport_tcpudp.trim(), getVpnProfile(vpnProfiles, OPENVPN).getConfigFile(context, false).trim()); } @Test @@ -1599,9 +1618,9 @@ public class VpnConfigGeneratorTest { VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 4; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - System.out.println(vpnProfiles.get(OPENVPN).getConfigFile(context, false)); - assertEquals(expectedVPNConfig_v4_ovpn_tcp_udp_new_ciphers.trim(), vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim()); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + System.out.println(getVpnProfile(vpnProfiles, OPENVPN).getConfigFile(context, false)); + assertEquals(expectedVPNConfig_v4_ovpn_tcp_udp_new_ciphers.trim(), getVpnProfile(vpnProfiles, OPENVPN).getConfigFile(context, false).trim()); } @Test @@ -1613,9 +1632,9 @@ public class VpnConfigGeneratorTest { configuration.experimentalTransports = true; configuration.preferUDP = true; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertTrue(vpnProfiles.containsKey(OBFS4) && ((Obfs4Connection)vpnProfiles.get(OBFS4).mConnections[0]).getObfs4Options().transport.getProtocols()[0].equals("kcp")); - assertTrue(vpnProfiles.containsKey(OPENVPN)); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertTrue(containsKey(vpnProfiles, OBFS4) && ((Obfs4Connection)getVpnProfile(vpnProfiles, OBFS4).mConnections[0]).getObfs4Options().transport.getProtocols()[0].equals("kcp")); + assertTrue(containsKey(vpnProfiles, OPENVPN)); } @Test @@ -1626,9 +1645,9 @@ public class VpnConfigGeneratorTest { configuration.apiVersion = 3; configuration.experimentalTransports = true; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertFalse(vpnProfiles.containsKey(OBFS4)); - assertTrue(vpnProfiles.containsKey(OPENVPN)); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertFalse(containsKey(vpnProfiles, OBFS4)); + assertTrue(containsKey(vpnProfiles, OPENVPN)); } @Test @@ -1644,10 +1663,10 @@ public class VpnConfigGeneratorTest { configuration.obfuscationProxyKCP = true; configuration.remoteGatewayIP = "1.2.3.4"; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertTrue("has openvpn profile", vpnProfiles.containsKey(OPENVPN)); - assertTrue("has obfs4 profile", vpnProfiles.containsKey(OBFS4)); - assertTrue("bridge is running KCP", vpnProfiles.get(OBFS4).mGatewayIp.equals("1.2.3.4")); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertTrue("has openvpn profile", containsKey(vpnProfiles, OPENVPN)); + assertTrue("has obfs4 profile", containsKey(vpnProfiles, OBFS4)); + assertTrue("bridge is running KCP", getVpnProfile(vpnProfiles, OBFS4).mGatewayIp.equals("1.2.3.4")); } @@ -1664,11 +1683,11 @@ public class VpnConfigGeneratorTest { configuration.obfuscationProxyCert = "asdfasdf"; configuration.remoteGatewayIP = "1.2.3.4"; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertFalse("has openvpn profile", vpnProfiles.containsKey(OPENVPN)); - 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 TCP", ((Obfs4Connection) vpnProfiles.get(OBFS4).mConnections[0]).getObfs4Options().transport.getProtocols()[0].equals("tcp")); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertFalse("has openvpn profile", containsKey(vpnProfiles, OPENVPN)); + assertTrue("has obfs4 profile", containsKey(vpnProfiles, OBFS4)); + assertTrue("bridge is pinned one", getVpnProfile(vpnProfiles, OBFS4).getTransportType() == OBFS4 && getVpnProfile(vpnProfiles, OBFS4).mConnections[0].isUseUdp()); + assertTrue("bridge is running TCP", ((Obfs4Connection) getVpnProfile(vpnProfiles, OBFS4).mConnections[0]).getObfs4Options().transport.getProtocols()[0].equals("tcp")); } @Test @@ -1685,11 +1704,11 @@ public class VpnConfigGeneratorTest { configuration.remoteGatewayIP = "1.2.3.4"; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertFalse("has openvpn profile", vpnProfiles.containsKey(OPENVPN)); - 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]).getObfs4Options().transport.getProtocols()[0].equals("kcp")); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertFalse("has openvpn profile", containsKey(vpnProfiles, OPENVPN)); + assertTrue("has no obfs4 profile", containsKey(vpnProfiles, OBFS4)); + assertTrue("bridge is pinned one", getVpnProfile(vpnProfiles, OBFS4).getTransportType() == OBFS4 && getVpnProfile(vpnProfiles, OBFS4).mGatewayIp.equals("1.2.3.4")); + assertTrue("bridge is running KCP", ((Obfs4Connection) getVpnProfile(vpnProfiles, OBFS4).mConnections[0]).getObfs4Options().transport.getProtocols()[0].equals("kcp")); } @Test public void testGenerateVpnProfile_obfs4hop_tcp () throws Exception { @@ -1699,9 +1718,9 @@ public class VpnConfigGeneratorTest { configuration.apiVersion = 3; configuration.experimentalTransports = true; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertTrue(vpnProfiles.containsKey(OBFS4_HOP) && ((Obfs4Connection)vpnProfiles.get(OBFS4_HOP).mConnections[0]).getObfs4Options().transport.getProtocols()[0].equals("tcp")); - assertTrue(vpnProfiles.containsKey(OPENVPN)); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertTrue(containsKey(vpnProfiles, OBFS4_HOP) && ((Obfs4Connection)getVpnProfile(vpnProfiles, OBFS4_HOP).mConnections[0]).getObfs4Options().transport.getProtocols()[0].equals("tcp")); + assertTrue(containsKey(vpnProfiles, OPENVPN)); } @Test @@ -1712,9 +1731,9 @@ public class VpnConfigGeneratorTest { configuration.apiVersion = 3; configuration.experimentalTransports = true; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertTrue(vpnProfiles.containsKey(OBFS4_HOP) && ((Obfs4Connection)vpnProfiles.get(OBFS4_HOP).mConnections[0]).getObfs4Options().transport.getProtocols()[0].equals("kcp")); - assertTrue(vpnProfiles.containsKey(OPENVPN)); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertTrue(containsKey(vpnProfiles, OBFS4_HOP) && ((Obfs4Connection)getVpnProfile(vpnProfiles, OBFS4_HOP).mConnections[0]).getObfs4Options().transport.getProtocols()[0].equals("kcp")); + assertTrue(containsKey(vpnProfiles, OPENVPN)); } @Test @@ -1726,9 +1745,9 @@ public class VpnConfigGeneratorTest { configuration.apiVersion = 3; configuration.experimentalTransports = true; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - System.out.println(vpnProfiles.get(OBFS4_HOP).getConfigFile(context, false)); - assertEquals(expectedVPNConfig_hopping_pt_portHopping.trim(), vpnProfiles.get(OBFS4_HOP).getConfigFile(context, false).trim()); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + System.out.println(getVpnProfile(vpnProfiles, OBFS4_HOP).getConfigFile(context, false)); + assertEquals(expectedVPNConfig_hopping_pt_portHopping.trim(), getVpnProfile(vpnProfiles, OBFS4_HOP).getConfigFile(context, false).trim()); } @Test @@ -1740,9 +1759,9 @@ public class VpnConfigGeneratorTest { configuration.apiVersion = 3; configuration.experimentalTransports = true; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - System.out.println(vpnProfiles.get(OBFS4_HOP).getConfigFile(context, false)); - assertEquals(expectedVPNConfig_hopping_pt_portHopping.trim(), vpnProfiles.get(OBFS4_HOP).getConfigFile(context, false).trim()); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + System.out.println(getVpnProfile(vpnProfiles, OBFS4_HOP).getConfigFile(context, false)); + assertEquals(expectedVPNConfig_hopping_pt_portHopping.trim(), getVpnProfile(vpnProfiles, OBFS4_HOP).getConfigFile(context, false).trim()); } @Test public void testGenerateVpnProfile_obfs4_decoupled() throws Exception { @@ -1753,10 +1772,10 @@ public class VpnConfigGeneratorTest { configuration.apiVersion = 3; configuration.experimentalTransports = true; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertTrue(vpnProfiles.containsKey(OBFS4)); - assertTrue(((Obfs4Connection)vpnProfiles.get(OBFS4).mConnections[0]).getObfs4Options().transport.getProtocols()[0].equals("tcp")); - assertFalse(vpnProfiles.containsKey(OPENVPN)); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertTrue(containsKey(vpnProfiles, OBFS4)); + assertTrue(((Obfs4Connection)getVpnProfile(vpnProfiles, OBFS4).mConnections[0]).getObfs4Options().transport.getProtocols()[0].equals("tcp")); + assertFalse(containsKey(vpnProfiles, OPENVPN)); } @Test @@ -1768,11 +1787,11 @@ public class VpnConfigGeneratorTest { configuration.apiVersion = 3; configuration.experimentalTransports = true; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertTrue(vpnProfiles.containsKey(OBFS4_HOP)); - assertTrue(((Obfs4Connection)vpnProfiles.get(OBFS4_HOP).mConnections[0]).getObfs4Options().transport.getProtocols()[0].equals("tcp")); - assertFalse(vpnProfiles.containsKey(OPENVPN)); - assertFalse(vpnProfiles.containsKey(OBFS4)); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertTrue(containsKey(vpnProfiles, OBFS4_HOP)); + assertTrue(((Obfs4Connection)getVpnProfile(vpnProfiles, OBFS4_HOP).mConnections[0]).getObfs4Options().transport.getProtocols()[0].equals("tcp")); + assertFalse(containsKey(vpnProfiles, OPENVPN)); + assertFalse(containsKey(vpnProfiles, OBFS4)); } @Test @@ -1802,10 +1821,10 @@ public class VpnConfigGeneratorTest { configuration.apiVersion = 3; configuration.experimentalTransports = true; vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, configuration); - HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); - assertTrue(vpnProfiles.containsKey(OBFS4_HOP)); - assertTrue(((Obfs4Connection)vpnProfiles.get(OBFS4_HOP).mConnections[0]).getObfs4Options().transport.getProtocols()[0].equals("tcp")); - assertFalse(vpnProfiles.containsKey(OPENVPN)); - assertFalse(vpnProfiles.containsKey(OBFS4)); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertTrue(containsKey(vpnProfiles, OBFS4_HOP)); + assertTrue(((Obfs4Connection)getVpnProfile(vpnProfiles, OBFS4_HOP).mConnections[0]).getObfs4Options().transport.getProtocols()[0].equals("tcp")); + assertFalse(containsKey(vpnProfiles, OPENVPN)); + assertFalse(containsKey(vpnProfiles, OBFS4)); } }
\ No newline at end of file |