Commit c8343663 authored by cyberta's avatar cyberta
Browse files

fix existing tests and add one to test if a default data-ciphers parameter gets added correctly

parent cb7894ef
package se.leap.bitmaskclient.eip;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
......@@ -27,6 +31,7 @@ import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.when;
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.testutils.MockHelper.mockTextUtils;
import static se.leap.bitmaskclient.testutils.TestSetupHelper.getInputAsString;
/**
......@@ -34,7 +39,7 @@ import static se.leap.bitmaskclient.testutils.TestSetupHelper.getInputAsString;
*/
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(DataProviderRunner.class)
@PrepareForTest({ConfigHelper.class})
@PrepareForTest({ConfigHelper.class, TextUtils.class})
public class GatewaySelectorTest {
public static final String TAG = GatewaySelectorTest.class.getSimpleName();
......@@ -70,6 +75,7 @@ public class GatewaySelectorTest {
@Before
public void setup() throws IOException, JSONException, ConfigParser.ConfigParseError {
mockStatic(ConfigHelper.class);
mockTextUtils();
eipDefinition = new JSONObject(getInputAsString(getClass().getClassLoader().getResourceAsStream("eip-service-four-gateways.json")));
JSONArray gateways = eipDefinition.getJSONArray("gateways");
for (int i = 0; i < gateways.length(); i++) {
......
......@@ -2,6 +2,7 @@ package se.leap.bitmaskclient.eip;
import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import android.util.Log;
import org.json.JSONException;
......@@ -42,13 +43,14 @@ import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_EIP_DEFINITIO
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.MockHelper.mockTextUtils;
import static se.leap.bitmaskclient.testutils.TestSetupHelper.getProvider;
/**
* Created by cyberta on 09.10.17.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({ProviderObservable.class, Log.class, PreferenceHelper.class, ConfigHelper.class})
@PrepareForTest({ProviderObservable.class, Log.class, PreferenceHelper.class, ConfigHelper.class, TextUtils.class})
public class GatewaysManagerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
......@@ -62,6 +64,7 @@ public class GatewaysManagerTest {
public void setUp() throws IOException, JSONException {
mockStatic(Log.class);
mockStatic(ConfigHelper.class);
mockTextUtils();
when(ConfigHelper.getCurrentTimezone()).thenReturn(-1);
when(ConfigHelper.stringEqual(anyString(), anyString())).thenCallRealMethod();
secrets = new JSONObject(getJsonStringFor("secrets.json"));
......
......@@ -156,6 +156,7 @@ public class VpnConfigGeneratorTest {
"</cert>\n" +
"crl-verify file missing in config profile\n" +
"remote-cert-tls server\n" +
"data-ciphers AES-128-CBC\n" +
"cipher AES-128-CBC\n" +
"auth SHA1\n" +
"persist-tun\n" +
......@@ -274,6 +275,7 @@ public class VpnConfigGeneratorTest {
"</cert>\n" +
"crl-verify file missing in config profile\n" +
"remote-cert-tls server\n" +
"data-ciphers AES-128-CBC\n" +
"cipher AES-128-CBC\n" +
"auth SHA1\n" +
"persist-tun\n" +
......@@ -392,6 +394,7 @@ public class VpnConfigGeneratorTest {
"crl-verify file missing in config profile\n" +
"route 37.218.247.60 255.255.255.255 net_gateway\n"+
"remote-cert-tls server\n" +
"data-ciphers AES-128-CBC\n" +
"cipher AES-128-CBC\n" +
"auth SHA1\n" +
"persist-tun\n" +
......@@ -510,6 +513,7 @@ public class VpnConfigGeneratorTest {
"</cert>\n" +
"crl-verify file missing in config profile\n" +
"remote-cert-tls server\n" +
"data-ciphers AES-128-CBC\n" +
"cipher AES-128-CBC\n" +
"auth SHA1\n" +
"persist-tun\n" +
......@@ -628,6 +632,126 @@ public class VpnConfigGeneratorTest {
"</cert>\n" +
"crl-verify file missing in config profile\n" +
"remote-cert-tls server\n" +
"data-ciphers AES-128-CBC\n" +
"cipher AES-128-CBC\n" +
"auth SHA1\n" +
"persist-tun\n" +
"# persist-tun also enables pre resolving to avoid DNS resolve problem\n" +
"preresolve\n" +
"# Custom configuration options\n" +
"# You are on your on own here :)\n" +
"# These options found in the config file do not map to config settings:\n" +
"keepalive 10 30 \n" +
"tls-cipher DHE-RSA-AES128-SHA \n";
String expectedVPNConfig_v3_ovpn_udp_tcp_defaultDataCiphers = "# Config for OpenVPN 2.x\n" +
"# Enables connection to GUI\n" +
"management /data/data/se.leap.bitmask/mgmtsocket unix\n" +
"management-client\n" +
"management-query-passwords\n" +
"management-hold\n" +
"\n" +
"setenv IV_GUI_VER \"se.leap.bitmaskclient 0.9.10\" \n" +
"setenv IV_PLAT_VER \"0 null JUNIT null null null\"\n" +
"machine-readable-output\n" +
"allow-recursive-routing\n" +
"ifconfig-nowarn\n" +
"client\n" +
"verb 4\n" +
"connect-retry 2 300\n" +
"resolv-retry 60\n" +
"dev tun\n" +
"remote 37.218.247.60 1195 udp\n" +
"remote 37.218.247.60 1195 tcp-client\n" +
"<ca>\n" +
"-----BEGIN CERTIFICATE-----\n" +
"MIIFbzCCA1egAwIBAgIBATANBgkqhkiG9w0BAQ0FADBKMRgwFgYDVQQDDA9CaXRt\n" +
"YXNrIFJvb3QgQ0ExEDAOBgNVBAoMB0JpdG1hc2sxHDAaBgNVBAsME2h0dHBzOi8v\n" +
"Yml0bWFzay5uZXQwHhcNMTIxMTA2MDAwMDAwWhcNMjIxMTA2MDAwMDAwWjBKMRgw\n" +
"FgYDVQQDDA9CaXRtYXNrIFJvb3QgQ0ExEDAOBgNVBAoMB0JpdG1hc2sxHDAaBgNV\n" +
"BAsME2h0dHBzOi8vYml0bWFzay5uZXQwggI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n" +
"k/P5+ctHyOXx8IE79DBsZ6IL61UKIaKhqZBfLGYcWu17DVV6+LT+AKtHhOrv3TSj\n" +
"RnAcKnCbKqXLhUPXpK0eTjPYS2zQGQGIhIy9sQXVXJJJsGrPgMxna1Xw2JikBOCG\n" +
"htD/JKwt6xBmNwktH0GI/LVtVgSp82Clbn9C4eZN9E5YbVYjLkIEDhpByeC71QhX\n" +
"EIQ0ZR56bFuJA/CwValBqV/G9gscTPQqd+iETp8yrFpAVHOW+YzSFbxjTEkBte1J\n" +
"aF0vmbqdMAWLk+LEFPQRptZh0B88igtx6tV5oVd+p5IVRM49poLhuPNJGPvMj99l\n" +
"mlZ4+AeRUnbOOeAEuvpLJbel4rhwFzmUiGoeTVoPZyMevWcVFq6BMkS+jRR2w0jK\n" +
"G6b0v5XDHlcFYPOgUrtsOBFJVwbutLvxdk6q37kIFnWCd8L3kmES5q4wjyFK47Co\n" +
"Ja8zlx64jmMZPg/t3wWqkZgXZ14qnbyG5/lGsj5CwVtfDljrhN0oCWK1FZaUmW3d\n" +
"69db12/g4f6phldhxiWuGC/W6fCW5kre7nmhshcltqAJJuU47iX+DarBFiIj816e\n" +
"yV8e\n" +
"-----END CERTIFICATE-----\n" +
"\n" +
"</ca>\n" +
"<key>\n" +
"-----BEGIN RSA PRIVATE KEY-----\n" +
"MIIEwAIBADANBgkqhkiG9w0BAQEFAASCBKowggSmAgEAAoIBAQDUTYWeGgsHS+fjijmziniNqw6h\n" +
"MBpyK4S/cM6PxV28C33VuOWPTMcIYesctjZANWFCggfFTQSjV5Qaxq9UK4i27tayLbCdlVS6hpbl\n" +
"Vf4DuI3Gj1Pv1rtITBShtvCf3T7yBnjW4wVpOpsUAAOViKUSvUU3kPPMFWhiGQw8yHYr82ts6XMo\n" +
"jwMoonW5Ml4e7C7Cr22QesC63q7emNcpUd0pZGT9C33RgDAHZDMrlyjo4HEp1JbUfB0gbmXElJbE\n" +
"1TNdZ62HhgmMjzTUN1GGrQ1t91AEoEQwaK65o4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orrmjhhKP7IW/opdlnPk5ZrP3i0qI32/boRe0EWZGXJvr4P3K\n" +
"dJ30uCECAwEAAaNvMG0wHQYDVR0OBBYEFK8bMVAM4GBB5sHptoIOAaIvlYueMAsGA1UdDwQEAwIH\n" +
"gDATBgNVHSUEDDAKBggrBgEFBQcDAjAJBgNVHRMEAjAAMB8GA1UdIwQYMBaAFId+E7bsWFsUWah9\n" +
"vZuPvZ7O+aJsMA0GCSqGSIb3DQEBCwUAA4ICAQAQOX81csVhvP422NKkZH7+g3npBpl+sEHedaGR\n" +
"xYPOu4HrA4TVF9h44sljRoRJyenGNdBZCXcLKHg889eePTf8Z5K3lTojp6hvwyA6tgxOMHT1kESW\n" +
"PfqnRw8mHfHJuE3g+4YNUMwggzwc/VZATdV/7M33sarVN9AUOHou9n9BizgCC+UnYlS+F2POumE3\n" +
"FbOhKo5uubI02MwBYlN2JVO2TBt1Q20w8wc6cU07Xi5Epp+1mkgFiOShkNtPcJmEyBWJhxDtSDOW\n" +
"2doqWYNqH2kq7B5R/kyyfcpFJqAnBTV7xs+C5rTS1mW7LpxfdCUMbYuLCpyxpO3A/DhAm8n47tUH\n" +
"lBtmo8Avdb8VdFpYiGBpB0o9kTFcsWFb2GkWFBduGfSEB8jUI7QtqhgZqocAKK/cweSRV8FwyUcn\n" +
"R0prRm3QEi9fbXqEddzjSY9y/lqWYzT7u+IOAQpKroeZ4wzgYperDNOUFuYk1rP7yuvjP2pV5rcN\n" +
"yPoBP60TPVWMRM4WJm6nTogAz2qBrFsf/XwT/ajzbsjT6HNB7QbRE+wkFkqspoXG5Agp7KQ8lW3L\n" +
"SKCDGOQJz7VIE85pD0tg7QEXBEw8oaRZtMjQ0Gvs25mxXAKka4wGasaWfYH6d0E+iKYcWn86V1rH\n" +
"K2ZoknT+Nno5jgjFuUR3fZseNizEfx7BteooKQ==\n" +
"-----END CERTIFICATE-----\n" +
"</cert>\n" +
"crl-verify file missing in config profile\n" +
"remote-cert-tls server\n" +
"data-ciphers AES-256-GCM:AES-128-GCM:AES-128-CBC\n" +
"cipher AES-128-CBC\n" +
"auth SHA1\n" +
"persist-tun\n" +
......@@ -723,4 +847,17 @@ public class VpnConfigGeneratorTest {
System.out.println(vpnProfiles.get(OPENVPN).getConfigFile(context, false));
assertTrue(vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim().equals(expectedVPNConfig_v3_ovpn_udp_tcp.trim()));
}
@Test
public void testGenerateVpnProfile_v3_ovpn_addDataCiphersDefaults() throws Exception {
gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_pt_udp_tcp.eip-service.json"))).getJSONArray("gateways").getJSONObject(0);
//delete "data-ciphers" from config to test if the resulting openvpn config file will contain the default value taken from "cipher" flag
generalConfig.put("data-ciphers", null);
vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, gateway, 3);
HashMap<Connection.TransportType, VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles();
assertTrue(vpnProfiles.containsKey(OBFS4));
assertTrue(vpnProfiles.containsKey(OPENVPN));
System.out.println(vpnProfiles.get(OPENVPN).getConfigFile(context, false));
assertTrue(vpnProfiles.get(OPENVPN).getConfigFile(context, false).trim().equals(expectedVPNConfig_v3_ovpn_udp_tcp_defaultDataCiphers.trim()));
}
}
\ No newline at end of file
{"auth":"SHA1","cipher":"AES-128-CBC","keepalive":"10 30","tls-cipher":"DHE-RSA-AES128-SHA","tun-ipv6":true}
\ No newline at end of file
{"auth":"SHA1","cipher":"AES-128-CBC", "data-ciphers": "AES-128-CBC", "keepalive":"10 30","tls-cipher":"DHE-RSA-AES128-SHA","tun-ipv6":true}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment