summaryrefslogtreecommitdiff
path: root/app/src/test/java/se/leap/bitmaskclient/eip
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/test/java/se/leap/bitmaskclient/eip')
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/GatewayTest.java154
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java125
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java953
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java263
4 files changed, 366 insertions, 1129 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/ProviderApiManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java
deleted file mode 100644
index b8c6d0c9..00000000
--- a/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java
+++ /dev/null
@@ -1,953 +0,0 @@
-/**
- * Copyright (c) 2018 LEAP Encryption Access Project and contributers
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package se.leap.bitmaskclient.eip;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static se.leap.bitmaskclient.base.models.Constants.BROADCAST_RESULT_KEY;
-import static se.leap.bitmaskclient.base.models.Constants.EIP_ACTION_START;
-import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_KEY;
-import static se.leap.bitmaskclient.base.models.Constants.USE_BRIDGES;
-import static se.leap.bitmaskclient.base.models.Constants.USE_SNOWFLAKE;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.CORRECTLY_DOWNLOADED_GEOIP_JSON;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.CORRECTLY_UPDATED_INVALID_VPN_CERTIFICATE;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.ERRORS;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.INCORRECTLY_DOWNLOADED_GEOIP_JSON;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.INCORRECTLY_UPDATED_INVALID_VPN_CERTIFICATE;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.MISSING_NETWORK_CONNECTION;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.PARAMETERS;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.PROVIDER_NOK;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.PROVIDER_OK;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.TOR_EXCEPTION;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.TOR_TIMEOUT;
-import static se.leap.bitmaskclient.testutils.BackendMockResponses.BackendMockProvider.TestBackendErrorCase.ERROR_CASE_FETCH_EIP_SERVICE_CERTIFICATE_INVALID;
-import static se.leap.bitmaskclient.testutils.BackendMockResponses.BackendMockProvider.TestBackendErrorCase.ERROR_CASE_MICONFIGURED_PROVIDER;
-import static se.leap.bitmaskclient.testutils.BackendMockResponses.BackendMockProvider.TestBackendErrorCase.ERROR_CASE_UPDATED_CERTIFICATE;
-import static se.leap.bitmaskclient.testutils.BackendMockResponses.BackendMockProvider.TestBackendErrorCase.ERROR_DNS_RESUOLUTION_TOR_FALLBACK;
-import static se.leap.bitmaskclient.testutils.BackendMockResponses.BackendMockProvider.TestBackendErrorCase.ERROR_GEOIP_SERVICE_IS_DOWN;
-import static se.leap.bitmaskclient.testutils.BackendMockResponses.BackendMockProvider.TestBackendErrorCase.ERROR_GEOIP_SERVICE_IS_DOWN_TOR_FALLBACK;
-import static se.leap.bitmaskclient.testutils.BackendMockResponses.BackendMockProvider.TestBackendErrorCase.NO_ERROR;
-import static se.leap.bitmaskclient.testutils.BackendMockResponses.BackendMockProvider.TestBackendErrorCase.NO_ERROR_API_V4;
-import static se.leap.bitmaskclient.testutils.MockHelper.mockBuildConfigHelper;
-import static se.leap.bitmaskclient.testutils.MockHelper.mockCertificateHelper;
-import static se.leap.bitmaskclient.testutils.MockHelper.mockClientGenerator;
-import static se.leap.bitmaskclient.testutils.MockHelper.mockContext;
-import static se.leap.bitmaskclient.testutils.MockHelper.mockPreferenceHelper;
-import static se.leap.bitmaskclient.testutils.MockHelper.mockProviderApiConnector;
-import static se.leap.bitmaskclient.testutils.MockHelper.mockRSAHelper;
-import static se.leap.bitmaskclient.testutils.MockHelper.mockResources;
-import static se.leap.bitmaskclient.testutils.MockHelper.mockResultReceiver;
-import static se.leap.bitmaskclient.testutils.TestSetupHelper.getConfiguredProvider;
-import static se.leap.bitmaskclient.testutils.TestSetupHelper.getConfiguredProviderAPIv4;
-import static se.leap.bitmaskclient.testutils.TestSetupHelper.getProvider;
-
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.pm.PackageManager;
-import android.content.res.Resources;
-import android.os.Bundle;
-
-import androidx.annotation.Nullable;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.security.NoSuchAlgorithmException;
-import java.security.cert.CertificateEncodingException;
-import java.util.concurrent.TimeoutException;
-
-import se.leap.bitmaskclient.BuildConfig;
-import se.leap.bitmaskclient.base.models.Provider;
-import se.leap.bitmaskclient.base.utils.BuildConfigHelper;
-import se.leap.bitmaskclient.base.utils.CertificateHelper;
-import se.leap.bitmaskclient.base.utils.HandlerProvider;
-import se.leap.bitmaskclient.base.utils.PreferenceHelper;
-import se.leap.bitmaskclient.base.utils.RSAHelper;
-import se.leap.bitmaskclient.providersetup.ProviderAPI;
-import se.leap.bitmaskclient.providersetup.ProviderApiConnector;
-import se.leap.bitmaskclient.providersetup.ProviderApiManager;
-import se.leap.bitmaskclient.providersetup.ProviderApiManagerBase;
-import se.leap.bitmaskclient.testutils.MockSharedPreferences;
-import se.leap.bitmaskclient.tor.TorStatusObservable;
-
-
-/**
- * Created by cyberta on 04.01.18.
- */
-
-public class ProviderApiManagerTest {
-
- private Resources mockResources;
- private Context mockContext;
-
- private ProviderApiManager providerApiManager;
-
- static class TestProviderApiServiceCallback implements ProviderApiManagerBase.ProviderApiServiceCallback {
- Throwable startTorServiceException;
- boolean hasNetworkConnection;
- boolean torTimeout;
- TorStatusObservable torStatusObservable;
-
- TestProviderApiServiceCallback() {
- this(null, true);
- }
- TestProviderApiServiceCallback(@Nullable Throwable startTorServiceException, boolean hasNetworkConnection) {
- this.startTorServiceException = startTorServiceException;
- this.hasNetworkConnection = hasNetworkConnection;
- this.torStatusObservable = TorStatusObservable.getInstance();
- }
-
- TestProviderApiServiceCallback(boolean torTimeout, boolean hasNetworkConnection) {
- this.hasNetworkConnection = hasNetworkConnection;
- this.torStatusObservable = TorStatusObservable.getInstance();
- this.torTimeout = torTimeout;
- }
-
- @Override
- public void broadcastEvent(Intent intent) {
- }
-
- @Override
- public boolean startTorService() throws InterruptedException, IllegalStateException {
- if (startTorServiceException != null) {
- if (startTorServiceException instanceof InterruptedException) {
- throw (InterruptedException) startTorServiceException;
- }
- if (startTorServiceException instanceof IllegalStateException) {
- throw (IllegalStateException) startTorServiceException;
- }
- }
- if (!torTimeout) {
- try {
- TorStatusObservable.updateState(mockContext(), TorStatusObservable.TorStatus.ON.toString());
- } catch (PackageManager.NameNotFoundException e) {
- throw new RuntimeException(e);
- }
- }
- return true;
- }
-
- @Override
- public void stopTorService() {
- }
-
- @Override
- public int getTorHttpTunnelPort() {
- return 8118;
- }
-
- @Override
- public boolean hasNetworkConnection() {
- return hasNetworkConnection;
- }
-
- @Override
- public void saveProvider(Provider p) {
-
- }
-
- }
-
- @Before
- public void setUp() throws Exception {
- mockContext = mockContext();
- mockResources = mockResources(getClass().getClassLoader().getResourceAsStream("error_messages.json"));
- HandlerProvider handlerProvider = new HandlerProvider((r, delay) -> new Thread(r).start());
- BuildConfigHelper buildConfigHelper = mockBuildConfigHelper(true);
- TorStatusObservable torStatusObservable = TorStatusObservable.getInstance();
- TorStatusObservable.setProxyPort(-1);
- TorStatusObservable.setLastError(null);
- TorStatusObservable.updateState(mockContext, TorStatusObservable.TorStatus.OFF.toString());
- }
-
- @Test
- public void test_handleIntentSetupProvider_noProviderMainURL() throws IOException, JSONException {
- Provider provider = new Provider("");
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
- Bundle expectedResult = new Bundle();
-
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);
- expectedResult.putString(ERRORS, "{\"errors\":\"It doesn't seem to be a Bitmask provider.\"}");
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
-
- providerApiManager.handleIntent(providerApiCommand);
- }
-
- @Test
- public void test_handleIntentSetupProvider_happyPath_preseededProviderAndCA() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, JSONException {
- Provider provider = getConfiguredProvider();
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
- CertificateHelper certHelper = mockCertificateHelper(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector providerApiConnector = mockProviderApiConnector(NO_ERROR);
-
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, true);
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_OK, expectedResult));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
- providerApiManager.handleIntent(providerApiCommand);
- }
-
- @Test
- public void test_handleIntentSetupProvider_happyPath_no_preseededProviderAndCA() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, JSONException {
- Provider provider = getConfiguredProvider();
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
- CertificateHelper certHelper = mockCertificateHelper("a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(NO_ERROR);
-
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
- Bundle expectedResult = new Bundle();
-
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, true);
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
-
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_OK, expectedResult));
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
-
- providerApiManager.handleIntent(providerApiCommand);
- }
-
- @Test
- public void test_handleIntentSetupProvider_happyPath_storedProviderAndCAFromPreviousSetup() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, JSONException {
- Provider provider = new Provider("https://riseup.net");
- PreferenceHelper preferenceHelper = mockPreferenceHelper(getConfiguredProvider());
- CertificateHelper certHelper = mockCertificateHelper("a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(NO_ERROR);
-
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, true);
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_OK, expectedResult));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
-
- providerApiManager.handleIntent(providerApiCommand);
- }
-
- @Test
- public void test_handleIntentSetupProvider_preseededProviderAndCA_failedCAPinning() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, JSONException {
- Provider provider = getConfiguredProvider();
-
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
- CertificateHelper certHelper = mockCertificateHelper(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29495");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(NO_ERROR);
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);
- expectedResult.putString(ERRORS, "{\"errorId\":\"ERROR_CERTIFICATE_PINNING\",\"errors\":\"Stored provider certificate is invalid. You can either update Bitmask (recommended) or update the provider certificate using a commercial CA certificate.\"}");
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
-
- providerApiManager.handleIntent(providerApiCommand);
- }
-
- @Test
- public void test_handleIntentSetupProvider_no_preseededProviderAndCA_failedPinning() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, JSONException {
- Provider provider = new Provider("https://riseup.net");
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
- CertificateHelper certHelper = mockCertificateHelper("a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29495");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(NO_ERROR);
-
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);
- expectedResult.putString(ERRORS, "{\"errorId\":\"ERROR_CERTIFICATE_PINNING\",\"errors\":\"Stored provider certificate is invalid. You can either update Bitmask (recommended) or update the provider certificate using a commercial CA certificate.\"}");
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
-
- providerApiManager.handleIntent(providerApiCommand);
- }
-
- @Test
- public void test_handleIntentSetupProvider_storedProviderAndCAFromPreviousSetup_failedPinning() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, JSONException {
- Provider provider = new Provider("https://riseup.net");
- mockPreferenceHelper(getConfiguredProvider());
- CertificateHelper certHelper = mockCertificateHelper("a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29495");
-
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(NO_ERROR);
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);
- expectedResult.putString(ERRORS, "{\"errorId\":\"ERROR_CERTIFICATE_PINNING\",\"errors\":\"Stored provider certificate is invalid. You can either update Bitmask (recommended) or update the provider certificate using a commercial CA certificate.\"}");
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
-
- providerApiManager.handleIntent(providerApiCommand);
- }
-
-
- @Test
- public void test_handleIntentSetupProvider_preseededProviderAndCA_outdatedCertificate() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, JSONException {
- Provider provider = getProvider(null ,null, null, null, "outdated_cert.pem", null, null, null);
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(NO_ERROR);
- CertificateHelper certHelper = mockCertificateHelper("a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);
- expectedResult.putString(ERRORS, "{\"errorId\":\"ERROR_INVALID_CERTIFICATE\",\"errors\":\"Stored provider certificate is expired. You can either update Bitmask (recommended) or update the provider certificate using a commercial CA certificate.\"}");
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
-
- providerApiManager.handleIntent(providerApiCommand);
- }
-
- @Test
- public void test_handleIntentSetupProvider_storedProviderAndCAFromPreviousSetup_outdatedCertificate() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, JSONException {
- Provider provider = getProvider(null, null, null, null, "outdated_cert.pem", "riseup.net.json", null, null);
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
- PreferenceHelper.getEipDefinitionFromPreferences();
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(NO_ERROR);
- CertificateHelper certHelper = mockCertificateHelper("a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);
- expectedResult.putString(ERRORS, "{\"errorId\":\"ERROR_INVALID_CERTIFICATE\",\"errors\":\"Stored provider certificate is expired. You can either update Bitmask (recommended) or update the provider certificate using a commercial CA certificate.\"}");
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
-
- providerApiManager.handleIntent(providerApiCommand);
- }
-
- @Test
- public void test_handleIntentSetupProvider_preseededProviderAndCA_ValidCertificateButUpdatedCertificateOnServerSide() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, JSONException {
- Provider provider = getConfiguredProvider();
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
- CertificateHelper certHelper = mockCertificateHelper("a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(ERROR_CASE_UPDATED_CERTIFICATE);
-
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);
- expectedResult.putString(ERRORS, "{\"errorId\":\"ERROR_INVALID_CERTIFICATE\",\"errors\":\"Stored provider certificate is invalid. You can either update Bitmask (recommended) or update the provider certificate using a commercial CA certificate.\"}");
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
-
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
-
- providerApiManager.handleIntent(providerApiCommand);
- }
-
- @Test
- public void test_handleIntentSetupProvider_storedProviderAndCAFromPreviousSetup_ValidCertificateButUpdatedCertificateOnServerSide() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, JSONException {
- Provider provider = new Provider("https://riseup.net");
- PreferenceHelper preferenceHelper = mockPreferenceHelper(getConfiguredProvider());
- CertificateHelper certHelper = mockCertificateHelper("a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(ERROR_CASE_UPDATED_CERTIFICATE);
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);
- expectedResult.putString(ERRORS, "{\"errorId\":\"ERROR_INVALID_CERTIFICATE\",\"errors\":\"Stored provider certificate is invalid. You can either update Bitmask (recommended) or update the provider certificate using a commercial CA certificate.\"}");
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
-
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
-
- providerApiManager.handleIntent(providerApiCommand);
- }
-
- @Test
- public void test_handleIntentSetupProvider_preseededProviderAndCA_failedConfiguration() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, JSONException {
-
- Provider provider = getConfiguredProvider();
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
-
- CertificateHelper certHelper = mockCertificateHelper("a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(ERROR_CASE_MICONFIGURED_PROVIDER);
-
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);
- expectedResult.putString(ERRORS, "{\"errors\":\"There was an error configuring Bitmask with your chosen provider.\"}");
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
-
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
-
- providerApiManager.handleIntent(providerApiCommand);
- }
-
-
- @Test
- public void test_handleIntentSetupProvider_preseededCustomProviderAndCA_failedConfiguration() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, JSONException {
- if ("insecure".equals(BuildConfig.FLAVOR_implementation )) {
- return;
- }
- Provider provider = getConfiguredProvider();
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
-
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(ERROR_CASE_MICONFIGURED_PROVIDER);
- CertificateHelper certHelper = mockCertificateHelper("a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- BuildConfigHelper buildConfigHelper = mockBuildConfigHelper(false);
-
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);
- expectedResult.putString(ERRORS, "{\"errors\":\"There was an error configuring RiseupVPN.\"}");
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
-
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
-
- providerApiManager.handleIntent(providerApiCommand);
- }
-
- @Test
- public void test_handleIntentSetupProvider_outdatedPreseededProviderAndCA_successfulConfiguration() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, JSONException {
-
- Provider provider = getProvider(null, null, null, null, null, "riseup_net_outdated_config.json", null, null);
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
- CertificateHelper certHelper = mockCertificateHelper(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(NO_ERROR);
-
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, true);
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
-
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_OK, expectedResult));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
-
- providerApiManager.handleIntent(providerApiCommand);
- }
-
- @Test
- public void test_handleIntentSetupProvider_failingEipServiceFetch_failedConfiguration() throws IOException, NoSuchAlgorithmException, CertificateEncodingException {
- if ("insecure".equals(BuildConfig.FLAVOR_implementation )) {
- return;
- }
-
- Provider provider = new Provider("https://riseup.net");
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
- CertificateHelper certHelper = mockCertificateHelper("a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(ERROR_CASE_FETCH_EIP_SERVICE_CERTIFICATE_INVALID);
-
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);
- expectedResult.putParcelable(PROVIDER_KEY, provider);
- expectedResult.putString(ERRORS, "This is not a trusted Bitmask provider.");
- Intent providerApiCommand = new Intent();
-
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
-
- providerApiManager.handleIntent(providerApiCommand);
- }
-
- @Test
- public void test_handleIntentGetGeoip_happyPath() throws IOException, NoSuchAlgorithmException, CertificateEncodingException, JSONException {
- if ("insecure".equals(BuildConfig.FLAVOR_implementation )) {
- return;
- }
-
- Provider inputProvider = getConfiguredProvider();
- inputProvider.setGeoIpJson(new JSONObject());
- PreferenceHelper preferenceHelper = mockPreferenceHelper(inputProvider);
- Provider expectedProvider = getConfiguredProvider();
- CertificateHelper certHelper = mockCertificateHelper("a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(NO_ERROR);
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(EIP_ACTION_START, true);
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, true);
- expectedResult.putParcelable(PROVIDER_KEY, expectedProvider);
-
- Intent providerApiCommand = new Intent();
-
- providerApiCommand.setAction(ProviderAPI.DOWNLOAD_GEOIP_JSON);
- Bundle extrasBundle = new Bundle();
- extrasBundle.putBoolean(EIP_ACTION_START, true);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(CORRECTLY_DOWNLOADED_GEOIP_JSON, expectedResult));
- providerApiCommand.putExtra(PROVIDER_KEY, inputProvider);
- providerApiCommand.putExtra(PARAMETERS, extrasBundle);
-
- providerApiManager.handleIntent(providerApiCommand);
-
- }
-
-
- @Test
- public void test_handleIntentGetGeoip_serviceDown_failToDownload() throws IOException, NoSuchAlgorithmException, CertificateEncodingException, JSONException {
- if ("insecure".equals(BuildConfig.FLAVOR_implementation)) {
- return;
- }
-
- Provider provider = getConfiguredProvider();
- SharedPreferences mockSharedPref = new MockSharedPreferences();
- mockSharedPref.edit().
- putBoolean(USE_BRIDGES, false).
- putBoolean(USE_SNOWFLAKE, false).commit();
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider, mockSharedPref);
- CertificateHelper certHelper = mockCertificateHelper("a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(ERROR_GEOIP_SERVICE_IS_DOWN);
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(EIP_ACTION_START, true);
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
-
- providerApiCommand.setAction(ProviderAPI.DOWNLOAD_GEOIP_JSON);
- Bundle extrasBundle = new Bundle();
- extrasBundle.putBoolean(EIP_ACTION_START, true);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(INCORRECTLY_DOWNLOADED_GEOIP_JSON, expectedResult));
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.putExtra(PARAMETERS, extrasBundle);
-
- providerApiManager.handleIntent(providerApiCommand);
-
- }
-
- @Test
- public void test_handleIntentGetGeoip_serviceDown_torNotStarted() throws IOException, NoSuchAlgorithmException, CertificateEncodingException, JSONException, TimeoutException, InterruptedException {
- if ("insecure".equals(BuildConfig.FLAVOR_implementation)) {
- return;
- }
-
- Provider provider = getConfiguredProvider();
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
- CertificateHelper certHelper = mockCertificateHelper("a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(ERROR_GEOIP_SERVICE_IS_DOWN_TOR_FALLBACK);
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(EIP_ACTION_START, true);
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
-
- providerApiCommand.setAction(ProviderAPI.DOWNLOAD_GEOIP_JSON);
- Bundle extrasBundle = new Bundle();
- extrasBundle.putBoolean(EIP_ACTION_START, true);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(INCORRECTLY_DOWNLOADED_GEOIP_JSON, expectedResult));
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.putExtra(PARAMETERS, extrasBundle);
-
- providerApiManager.handleIntent(providerApiCommand);
- // also assert that Tor was not allowed to start
- assertEquals(-1, TorStatusObservable.getProxyPort());
-
- }
-
- @Test
- public void test_handleIntentGetGeoip_didNotReachTimeoutToFetchNew_returnsFailure() throws IOException, NoSuchAlgorithmException, CertificateEncodingException, JSONException {
- if ("insecure".equals(BuildConfig.FLAVOR_implementation)) {
- return;
- }
-
- Provider provider = getConfiguredProvider();
- provider.setLastGeoIpUpdate(System.currentTimeMillis());
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
- CertificateHelper certHelper = mockCertificateHelper("a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(NO_ERROR);
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(EIP_ACTION_START, true);
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
-
- providerApiCommand.setAction(ProviderAPI.DOWNLOAD_GEOIP_JSON);
- Bundle extrasBundle = new Bundle();
- extrasBundle.putBoolean(EIP_ACTION_START, true);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(INCORRECTLY_DOWNLOADED_GEOIP_JSON, expectedResult));
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.putExtra(PARAMETERS, extrasBundle);
-
- providerApiManager.handleIntent(providerApiCommand);
- }
-
- @Test
- public void test_handleIntentGetGeoip_noGeoipServiceURLDefined_returnsFailure() throws IOException, NoSuchAlgorithmException, CertificateEncodingException, JSONException {
- if ("insecure".equals(BuildConfig.FLAVOR_implementation)) {
- return;
- }
-
- Provider provider = getConfiguredProvider();
- provider.setGeoipUrl(null);
- provider.setGeoIpJson(new JSONObject());
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
- CertificateHelper certHelper = mockCertificateHelper("a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(NO_ERROR);
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(EIP_ACTION_START, true);
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
-
- providerApiCommand.setAction(ProviderAPI.DOWNLOAD_GEOIP_JSON);
- Bundle extrasBundle = new Bundle();
- extrasBundle.putBoolean(EIP_ACTION_START, true);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(INCORRECTLY_DOWNLOADED_GEOIP_JSON, expectedResult));
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.putExtra(PARAMETERS, extrasBundle);
-
- providerApiManager.handleIntent(providerApiCommand);
- }
-
- @Test
- public void test_handleIntentSetupProvider_APIv4_happyPath() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, JSONException {
- Provider provider = getConfiguredProviderAPIv4();
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
- CertificateHelper certHelper = mockCertificateHelper(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(NO_ERROR_API_V4);
-
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, true);
- expectedResult.putParcelable(PROVIDER_KEY, provider);
- Intent providerApiCommand = new Intent();
-
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_OK, expectedResult));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
-
- providerApiManager.handleIntent(providerApiCommand);
- }
-
- @Test
- public void test_handleIntentSetupProvider_TorFallback_SecondTryHappyPath() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, TimeoutException, InterruptedException {
-
- Provider provider = getConfiguredProviderAPIv4();
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
- CertificateHelper certHelper = mockCertificateHelper(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(ERROR_DNS_RESUOLUTION_TOR_FALLBACK);
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Intent providerApiCommand = new Intent();
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_OK));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
-
- providerApiManager.handleIntent(providerApiCommand);
- assertNotEquals(-1, TorStatusObservable.getProxyPort());
- }
-
-
- @Test
- public void test_handleIntentSetupProvider_TorFallbackStartServiceException_SecondTryFailed() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, TimeoutException, InterruptedException {
- Provider provider = getConfiguredProviderAPIv4();
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
- CertificateHelper certHelper = mockCertificateHelper(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(ERROR_DNS_RESUOLUTION_TOR_FALLBACK);
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(new IllegalStateException("Tor service start not failed."), true));
-
- Intent providerApiCommand = new Intent();
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
-
- providerApiManager.handleIntent(providerApiCommand);
- assertEquals(-1, TorStatusObservable.getProxyPort());
- }
-
- @Test
- public void test_handleIntentSetupProvider_TorFallbackTimeoutException_SecondTryFailed() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, TimeoutException, InterruptedException {
- Provider provider = getConfiguredProviderAPIv4();
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
- CertificateHelper certHelper = mockCertificateHelper(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(ERROR_DNS_RESUOLUTION_TOR_FALLBACK);
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(true, true));
-
- Intent providerApiCommand = new Intent();
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
-
- providerApiManager.handleIntent(providerApiCommand);
- assertEquals(-1, TorStatusObservable.getProxyPort());
- }
-
- @Test
- public void test_handleIntentSetupProvider_TorBridgesPreferenceEnabled_Success() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, TimeoutException, InterruptedException {
- Provider provider = getConfiguredProviderAPIv4();
-
- SharedPreferences sharedPreferences = new MockSharedPreferences();
- sharedPreferences.edit().putBoolean(USE_BRIDGES, true).putBoolean(USE_SNOWFLAKE, true).commit();
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider, sharedPreferences);
- CertificateHelper certHelper = mockCertificateHelper(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(NO_ERROR_API_V4);
-
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Intent providerApiCommand = new Intent();
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_OK));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
-
- providerApiManager.handleIntent(providerApiCommand);
- assertEquals(8118, TorStatusObservable.getProxyPort());
- }
-
- @Test
- public void test_handleIntentSetupProvider_TorBridgesDisabled_TorNotStarted() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, TimeoutException, InterruptedException {
- Provider provider = getConfiguredProviderAPIv4();
-
- SharedPreferences sharedPreferences = new MockSharedPreferences();
- sharedPreferences.edit().putBoolean(USE_BRIDGES, false).putBoolean(USE_SNOWFLAKE, false).commit();
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider, sharedPreferences);
- CertificateHelper certHelper = mockCertificateHelper(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(NO_ERROR_API_V4);
-
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Intent providerApiCommand = new Intent();
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_OK));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
-
- providerApiManager.handleIntent(providerApiCommand);
- assertEquals(-1, TorStatusObservable.getProxyPort());
- }
-
- @Test
- public void test_handleIntentUpdateVPNCertificate_TorBridgesPreferencesNotConfigured_TorStartedAndSuccess() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, TimeoutException, InterruptedException {
- Provider provider = getConfiguredProviderAPIv4();
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider);
- CertificateHelper certHelper = mockCertificateHelper(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- RSAHelper rsaHelper = mockRSAHelper();
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(ERROR_DNS_RESUOLUTION_TOR_FALLBACK);
-
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Intent providerApiCommand = new Intent();
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.setAction(ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(CORRECTLY_UPDATED_INVALID_VPN_CERTIFICATE));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
-
- providerApiManager.handleIntent(providerApiCommand);
- assertEquals(8118, TorStatusObservable.getProxyPort());
- }
-
- @Test
- public void test_handleIntentUpdateVPNCertificate_TorBridgesPreferencesFalse_TorNotStartedAndFailure() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, TimeoutException, InterruptedException {
- Provider provider = getConfiguredProviderAPIv4();
-
- SharedPreferences sharedPreferences = new MockSharedPreferences();
- sharedPreferences.edit().putBoolean(USE_BRIDGES, false).putBoolean(USE_SNOWFLAKE, false).commit();
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider, sharedPreferences);
- CertificateHelper certHelper = mockCertificateHelper(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(ERROR_DNS_RESUOLUTION_TOR_FALLBACK);
-
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Intent providerApiCommand = new Intent();
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.setAction(ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(INCORRECTLY_UPDATED_INVALID_VPN_CERTIFICATE));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
-
- providerApiManager.handleIntent(providerApiCommand);
- assertEquals(-1, TorStatusObservable.getProxyPort());
- }
-
- @Test
- public void test_handleIntentUpdateVPNCertificate_TorBridgesPreferencesTrue_TorStartedAndSuccess() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, TimeoutException, InterruptedException {
- Provider provider = getConfiguredProviderAPIv4();
-
- SharedPreferences sharedPreferences = new MockSharedPreferences();
- sharedPreferences.edit().putBoolean(USE_BRIDGES, true).putBoolean(USE_SNOWFLAKE, true).commit();
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider, sharedPreferences);
- CertificateHelper certHelper = mockCertificateHelper(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- RSAHelper rsaHelper = mockRSAHelper();
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(NO_ERROR_API_V4);
-
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback());
-
- Intent providerApiCommand = new Intent();
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.setAction(ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(CORRECTLY_UPDATED_INVALID_VPN_CERTIFICATE));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
-
- providerApiManager.handleIntent(providerApiCommand);
- assertNotEquals(-1, TorStatusObservable.getProxyPort());
- }
-
- @Test
- public void test_handleIntentUpdateVPNCertificate_TorBridgesPreferencesTrue_TorException_Failure() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, TimeoutException, InterruptedException {
- Provider provider = getConfiguredProviderAPIv4();
-
- SharedPreferences sharedPreferences = new MockSharedPreferences();
- sharedPreferences.edit().putBoolean(USE_BRIDGES, true).putBoolean(USE_SNOWFLAKE, true).commit();
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider, sharedPreferences);
- CertificateHelper certHelper = mockCertificateHelper(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(NO_ERROR_API_V4);
-
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(new IllegalStateException("Nothing works always."), true));
-
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);
- expectedResult.putString(ERRORS, "{\"initalAction\":\"ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE\"}");
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.setAction(ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(TOR_EXCEPTION, expectedResult));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
-
- providerApiManager.handleIntent(providerApiCommand);
- assertEquals(-1, TorStatusObservable.getProxyPort());
- }
-
- @Test
- public void test_handleIntentSetupProvider_TorBridgesPreferencesEnabledTimeout_TimeoutError() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, TimeoutException, InterruptedException {
- Provider provider = getConfiguredProviderAPIv4();
- SharedPreferences sharedPreferences = new MockSharedPreferences();
- sharedPreferences.edit().putBoolean(USE_BRIDGES, true).putBoolean(USE_SNOWFLAKE, true).commit();
- PreferenceHelper preferenceHelper = mockPreferenceHelper(provider, sharedPreferences);
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(NO_ERROR_API_V4);
-
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(true, true));
-
- Bundle expectedResult = new Bundle();
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);
- expectedResult.putString(ERRORS, "{\"errorId\":\"ERROR_TOR_TIMEOUT\",\"initalAction\":\"setUpProvider\",\"errors\":\"Starting bridges failed. Do you want to retry or continue with an unobfuscated secure connection to configure Bitmask?\"}");
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(TOR_TIMEOUT, expectedResult));
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
-
- providerApiManager.handleIntent(providerApiCommand);
- assertEquals(-1, TorStatusObservable.getProxyPort());
- }
-
- @Test
- public void test_handleIntentSetupProvider_noNetwork_NetworkError() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, JSONException {
- Provider provider = getConfiguredProvider();
-
- CertificateHelper certHelper = mockCertificateHelper("a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- ProviderApiConnector mockedApiConnector = mockProviderApiConnector(NO_ERROR);
- providerApiManager = new ProviderApiManager(mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(null, false));
- Bundle expectedResult = new Bundle();
-
- expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);
- expectedResult.putString(ERRORS, "{\"errors\":\"Bitmask has no internet connection. Please check your WiFi and cellular data settings.\"}");
- expectedResult.putParcelable(PROVIDER_KEY, provider);
-
- Intent providerApiCommand = new Intent();
-
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(MISSING_NETWORK_CONNECTION, expectedResult));
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.putExtra(PARAMETERS, new Bundle());
- providerApiManager.handleIntent(providerApiCommand);
- }
-}
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 7581a395..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;
@@ -27,7 +28,7 @@ import de.blinkt.openvpn.core.connection.Obfs4Connection;
import se.leap.bitmaskclient.base.models.ProviderObservable;
import se.leap.bitmaskclient.base.utils.BuildConfigHelper;
import se.leap.bitmaskclient.base.utils.PreferenceHelper;
-import se.leap.bitmaskclient.base.utils.RSAHelper;
+import se.leap.bitmaskclient.base.utils.PrivateKeyHelper;
import se.leap.bitmaskclient.testutils.MockHelper;
import se.leap.bitmaskclient.testutils.MockSharedPreferences;
import se.leap.bitmaskclient.testutils.TestSetupHelper;
@@ -1347,21 +1348,39 @@ public class VpnConfigGeneratorTest {
context = MockHelper.mockContext();
ProviderObservable providerObservable = MockHelper.mockProviderObservable(TestSetupHelper.getConfiguredProvider());
- RSAHelper rsaHelper = MockHelper.mockRSAHelper();
+ PrivateKeyHelper privateKeyHelper = MockHelper.mockPrivateKeyHelper();
sharedPreferences = new MockSharedPreferences();
preferenceHelper = new PreferenceHelper(new MockSharedPreferences());
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