summaryrefslogtreecommitdiff
path: root/app/src/test/java
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2020-07-24 17:40:15 +0200
committercyBerta <cyberta@riseup.net>2020-07-24 17:40:15 +0200
commitd1ddaa7b10fde24b0b5f07369d1a22c221b81287 (patch)
tree2128ffb7fe977e56664623308bda358d100c87e1 /app/src/test/java
parente986a294ec3e328bd48bb4c423fe835d1aa2dc69 (diff)
fix bug in vpn profile based gateway order detection, write additional tests for it
Diffstat (limited to 'app/src/test/java')
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java36
1 files changed, 33 insertions, 3 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
index 5c5ebbfe..bfe96d2c 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
@@ -129,6 +129,36 @@ public class GatewaysManagerTest {
}
@Test
+ public void TestGetPosition_VpnProfileExistingObfs4FromPresortedList_returnsPositionOne() throws JSONException, ConfigParser.ConfigParseError, IOException {
+ Provider provider = getProvider(null, null, null, null, null, null, "ptdemo_three_mixed_gateways.json", "ptdemo_three_mixed_gateways.geoip.json");
+ JSONObject eipServiceJson = provider.getEipServiceJson();
+ JSONObject gateway1 = eipServiceJson.getJSONArray(GATEWAYS).getJSONObject(0);
+ MockHelper.mockProviderObserver(provider);
+ GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
+
+ VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, 3);
+ VpnProfile profile = configGenerator.createProfile(OBFS4);
+ profile.mGatewayIp = "37.218.247.60";
+
+ assertEquals(1, gatewaysManager.getPosition(profile));
+ }
+
+ @Test
+ public void TestGetPosition_VpnProfileExistingOpenvpnFromPresortedList_returnsPositionOne() throws JSONException, ConfigParser.ConfigParseError, IOException {
+ Provider provider = getProvider(null, null, null, null, null, null, "ptdemo_three_mixed_gateways.json", "ptdemo_three_mixed_gateways.geoip.json");
+ JSONObject eipServiceJson = provider.getEipServiceJson();
+ JSONObject gateway1 = eipServiceJson.getJSONArray(GATEWAYS).getJSONObject(0);
+ MockHelper.mockProviderObserver(provider);
+ GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
+
+ VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, 3);
+ VpnProfile profile = configGenerator.createProfile(OPENVPN);
+ profile.mGatewayIp = "37.218.247.60";
+
+ assertEquals(2, gatewaysManager.getPosition(profile));
+ }
+
+ @Test
public void TestGetPosition_VpnProfileDifferentIp_returnMinusOne() throws JSONException, ConfigParser.ConfigParseError, IOException {
Provider provider = getProvider(null, null, null, null, null, null, "ptdemo_three_mixed_gateways.json", null);
JSONObject eipServiceJson = provider.getEipServiceJson();
@@ -159,7 +189,7 @@ public class GatewaysManagerTest {
}
@Test
- public void TestSelectN_selectFirstObfs4Connection_returnThirdGateway() throws JSONException, ConfigParser.ConfigParseError, IOException {
+ public void TestSelectN_selectFirstObfs4Connection_returnThirdGateway() {
Provider provider = getProvider(null, null, null, null, null, null, "ptdemo_two_openvpn_one_pt_gateways.json", null);
MockHelper.mockProviderObserver(provider);
@@ -171,7 +201,7 @@ public class GatewaysManagerTest {
}
@Test
- public void testSelectN_selectFromPresortedGateways_returnsGatewaysInPresortedOrder() throws JSONException {
+ public void testSelectN_selectFromPresortedGateways_returnsGatewaysInPresortedOrder() {
Provider provider = getProvider(null, null, null, null, null, null, "ptdemo_three_mixed_gateways.json", "ptdemo_three_mixed_gateways.geoip.json");
MockHelper.mockProviderObserver(provider);
@@ -186,7 +216,7 @@ public class GatewaysManagerTest {
}
@Test
- public void testSelectN_selectObfs4FromPresortedGateways_returnsObfs4GatewaysInPresortedOrder() throws JSONException {
+ public void testSelectN_selectObfs4FromPresortedGateways_returnsObfs4GatewaysInPresortedOrder() {
Provider provider = getProvider(null, null, null, null, null, null, "ptdemo_three_mixed_gateways.json", "ptdemo_three_mixed_gateways.geoip.json");
MockHelper.mockProviderObserver(provider);