summaryrefslogtreecommitdiff
path: root/app/src/androidTest/java/se
diff options
context:
space:
mode:
authorcyberta <cyberta@riseup.net>2017-10-13 11:08:54 +0000
committercyberta <cyberta@riseup.net>2017-10-13 11:08:54 +0000
commitef98b18734c25da77abe4f0067635cf795218c65 (patch)
treec0d4e87751f8720f27c2c1f0b5c5b97bd959c163 /app/src/androidTest/java/se
parentee442a9ee54face7a8f71fc0428ff6d1184e382f (diff)
parentde722d9c14a0ce4353d677081b077efe15eb9525 (diff)
Merge branch '8746_client_must_honor_specified_protocol' into 'master'
#8746 fixes client must honor the protocol default specified by the provider See merge request leap/bitmask_android!10
Diffstat (limited to 'app/src/androidTest/java/se')
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/TestGatewaysManager.java54
1 files changed, 47 insertions, 7 deletions
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestGatewaysManager.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestGatewaysManager.java
index 4817adbb..0a76638f 100644
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestGatewaysManager.java
+++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestGatewaysManager.java
@@ -19,10 +19,12 @@ package se.leap.bitmaskclient.test;
import android.app.*;
import android.content.*;
import android.test.*;
-import android.test.suitebuilder.annotation.*;
import org.json.*;
+import java.io.IOException;
+import java.util.Arrays;
+
import se.leap.bitmaskclient.*;
import se.leap.bitmaskclient.eip.*;
@@ -42,14 +44,13 @@ public class TestGatewaysManager extends InstrumentationTestCase {
@Override
protected void setUp() throws Exception {
+ super.setUp();
context = getInstrumentation().getContext();
assets = new FromAssets(context);
mockGatewaysManager();
mockRealGateway();
- super.setUp();
}
- @MediumTest
public void testFromEipServiceJson() {
gateways_manager.fromEipServiceJson(eip_definition);
assertEquals(2, gateways_manager.size());
@@ -57,13 +58,31 @@ public class TestGatewaysManager extends InstrumentationTestCase {
assertEquals(2, gateways_manager.size());
}
- @SmallTest
+ public void testOrderOfGateways_UDP_TCP() {
+ String[] protocolsInOrder = {"udp", "tcp"};
+ manipulateSupportedProtocols(protocolsInOrder);
+ gateways_manager.fromEipServiceJson(eip_definition);
+ gateways_manager.addFromString(gateway.toString());
+ assertTrue(gateways_manager.select().toString().contains("[\"udp\",\"tcp\"]"));
+ assertFalse(gateways_manager.select().toString().contains("[\"tcp\",\"udp\"]"));
+ }
+
+ public void testOrderOfGateways_TCP_UDP() {
+ String[] protocolsInOrder = {"tcp", "udp"};
+ manipulateSupportedProtocols(protocolsInOrder);
+ gateways_manager.fromEipServiceJson(eip_definition);
+ gateways_manager.addFromString(gateway.toString());
+ assertFalse(gateways_manager.select().toString().contains("[\"udp\",\"tcp\"]"));
+ assertTrue(gateways_manager.select().toString().contains("[\"tcp\",\"udp\"]"));
+ }
+
public void testAddFromString() {
gateways_manager.addFromString("");
+ assertEquals(0, gateways_manager.size());
gateways_manager.addFromString(gateway.toString());
+ assertEquals(1, gateways_manager.size());
}
- @MediumTest
public void testRemoveDuplicate() {
gateways_manager.addFromString(gateway.toString());
assertEquals(1, gateways_manager.size());
@@ -73,7 +92,6 @@ public class TestGatewaysManager extends InstrumentationTestCase {
assertEquals(1, gateways_manager.size());
}
- @MediumTest
public void testToString() {
assertEquals("[]", gateways_manager.toString());
@@ -81,7 +99,6 @@ public class TestGatewaysManager extends InstrumentationTestCase {
assertEquals("[" + gateway.toString() + "]", gateways_manager.toString());
}
- @SmallTest
public void testIsEmpty() {
assertTrue(gateways_manager.isEmpty());
gateways_manager.addFromString("");
@@ -107,6 +124,29 @@ public class TestGatewaysManager extends InstrumentationTestCase {
}
}
+ private void manipulateSupportedProtocols(String[] protocols) {
+ try {
+ eip_definition = new JSONObject(assets.toString(TestConstants.EIP_DEFINITION_FILE));
+ JSONObject secrets = new JSONObject(assets.toString(TestConstants.SECRETS_FILE));
+ JSONArray protocolJsonArray = new JSONArray(Arrays.asList(protocols));
+ JSONArray gateways = eip_definition.getJSONArray("gateways");
+ for (int i = 0; i < gateways.length(); i++) {
+ JSONObject gatewayJson = gateways.getJSONObject(i);
+ JSONObject capabilitiesJson = gatewayJson.getJSONObject("capabilities");
+ capabilitiesJson.put("protocols", protocolJsonArray);
+ gatewayJson.put("protocols", protocolJsonArray);
+ }
+ this.gateway = new Gateway(eip_definition, secrets, gateways.getJSONObject(0));
+ } catch (JSONException e) {
+ e.printStackTrace();
+ assertFalse(true);
+ } catch (IOException e) {
+ e.printStackTrace();
+ assertFalse(true);
+ }
+
+ }
+
private void mockArtificialGateway() {
try {
eip_definition = new JSONObject(assets.toString(TestConstants.EIP_DEFINITION_FILE));