summaryrefslogtreecommitdiff
path: root/app/src/test/java/de/blinkt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/test/java/de/blinkt')
-rw-r--r--app/src/test/java/de/blinkt/openvpn/VpnProfileTest.java39
1 files changed, 18 insertions, 21 deletions
diff --git a/app/src/test/java/de/blinkt/openvpn/VpnProfileTest.java b/app/src/test/java/de/blinkt/openvpn/VpnProfileTest.java
index a3ac3f92..ad42ffde 100644
--- a/app/src/test/java/de/blinkt/openvpn/VpnProfileTest.java
+++ b/app/src/test/java/de/blinkt/openvpn/VpnProfileTest.java
@@ -2,6 +2,7 @@ package de.blinkt.openvpn;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.when;
@@ -18,17 +19,16 @@ import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import java.util.Arrays;
import java.util.UUID;
import de.blinkt.openvpn.core.connection.Obfs4Connection;
import de.blinkt.openvpn.core.connection.OpenvpnConnection;
import se.leap.bitmaskclient.base.models.Transport;
-import se.leap.bitmaskclient.base.utils.ConfigHelper;
+import se.leap.bitmaskclient.base.utils.BuildConfigHelper;
import se.leap.bitmaskclient.pluggableTransports.Obfs4Options;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({UUID.class, ConfigHelper.ObfsVpnHelper.class})
+@PrepareForTest({UUID.class, BuildConfigHelper.class})
public class VpnProfileTest {
private static final String OPENVPNCONNECTION_PROFILE = "{\"mCipher\":\"\",\"mProfileVersion\":7,\"mLastUsed\":0,\"mCheckRemoteCN\":true,\"mVerb\":\"1\",\"mRemoteRandom\":false,\"mRoutenopull\":false,\"mConnectRetry\":\"2\",\"mAllowedAppsVpn\":[],\"mUserEditable\":true,\"mUseUdp\":true,\"mAllowedAppsVpnAreDisallowed\":true,\"mDNS1\":\"8.8.8.8\",\"mDNS2\":\"8.8.4.4\",\"mUseCustomConfig\":false,\"mUseFloat\":false,\"mUseDefaultRoute\":true,\"mConnectRetryMaxTime\":\"300\",\"mNobind\":true,\"mVersion\":0,\"mConnectRetryMax\":\"-1\",\"mOverrideDNS\":false,\"mAuth\":\"\",\"mTunMtu\":0,\"mPassword\":\"\",\"mTLSAuthDirection\":\"\",\"mKeyPassword\":\"\",\"mCustomConfigOptions\":\"\",\"mName\":\"mockProfile\",\"mExpectTLSCert\":false,\"mUsername\":\"\",\"mAllowLocalLAN\":false,\"mDataCiphers\":\"\",\"mSearchDomain\":\"blinkt.de\",\"mTemporaryProfile\":false,\"mUseTLSAuth\":false,\"mRemoteCN\":\"\",\"mCustomRoutesv6\":\"\",\"mPersistTun\":false,\"mX509AuthType\":3,\"mUuid\":\"9d295ca2-3789-48dd-996e-f731dbf50fdc\",\"mServerName\":\"openvpn.example.com\",\"mMssFix\":0,\"mPushPeerInfo\":false,\"mAuthenticationType\":2,\"mBlockUnusedAddressFamilies\":true,\"mServerPort\":\"1194\",\"mUseDefaultRoutev6\":true,\"mConnections\":[{\"mCustomConfiguration\":\"\",\"mUseUdp\":false,\"mServerName\":\"openvpn.example.com\",\"mProxyType\":\"NONE\",\"mProxyPort\":\"8080\",\"mUseCustomConfig\":false,\"mConnectTimeout\":0,\"mProxyName\":\"proxy.example.com\",\"mUseProxyAuth\":false,\"ConnectionAdapter.META_TYPE\":\"de.blinkt.openvpn.core.connection.OpenvpnConnection\",\"mServerPort\":\"1194\",\"mEnabled\":true}],\"mUseLzo\":false,\"mTransportType\":1,\"mAllowAppVpnBypass\":false,\"mUsePull\":true,\"mUseRandomHostname\":false,\"mAuthRetry\":0}";
@@ -45,7 +45,7 @@ public class VpnProfileTest {
@Before
public void setup() {
mockStatic(UUID.class);
- mockStatic(ConfigHelper.ObfsVpnHelper.class);
+ mockStatic(BuildConfigHelper.class);
}
@Test
@@ -77,7 +77,7 @@ public class VpnProfileTest {
@Test
public void toJson_obfs4() throws JSONException {
- when(ConfigHelper.ObfsVpnHelper.useObfsVpn()).thenReturn(false);
+ when(BuildConfigHelper.useObfsVpn()).thenReturn(false);
VpnProfile mockVpnProfile = new VpnProfile("mockProfile", OBFS4);
@@ -85,7 +85,6 @@ public class VpnProfileTest {
mockVpnProfile.mConnections[0] = new Obfs4Connection(new Obfs4Options("192.168.0.1", transport));
mockVpnProfile.mLastUsed = 0;
String s = mockVpnProfile.toJson();
- System.out.println(s);
//ignore UUID in comparison -> set it to fixed value
JSONObject actual = new JSONObject(s);
@@ -97,14 +96,13 @@ public class VpnProfileTest {
@Test
public void toJson_obfs4_obfsvpn() throws JSONException {
- when(ConfigHelper.ObfsVpnHelper.useObfsVpn()).thenReturn(true);
+ when(BuildConfigHelper.useObfsVpn()).thenReturn(true);
VpnProfile mockVpnProfile = new VpnProfile("mockProfile", OBFS4);
Transport.Options options = new Transport.Options("CERT", "1");
Transport transport = new Transport(OBFS4.toString(), new String[]{"tcp"}, new String[]{"1234"}, options);
mockVpnProfile.mConnections[0] = new Obfs4Connection(new Obfs4Options("192.168.0.1", transport));
mockVpnProfile.mLastUsed = 0;
String s = mockVpnProfile.toJson();
- System.out.println(s);
//ignore UUID in comparison -> set it to fixed value
JSONObject actual = new JSONObject(s);
@@ -116,7 +114,7 @@ public class VpnProfileTest {
@Test
public void toJson_obfs4_obfsvpn_kcp() throws JSONException {
- when(ConfigHelper.ObfsVpnHelper.useObfsVpn()).thenReturn(true);
+ when(BuildConfigHelper.useObfsVpn()).thenReturn(true);
VpnProfile mockVpnProfile = new VpnProfile("mockProfile", OBFS4);
Transport.Options options = new Transport.Options("CERT", "1");
@@ -124,7 +122,6 @@ public class VpnProfileTest {
mockVpnProfile.mConnections[0] = new Obfs4Connection(new Obfs4Options("192.168.0.1", transport));
mockVpnProfile.mLastUsed = 0;
String s = mockVpnProfile.toJson();
- System.out.println(s);
//ignore UUID in comparison -> set it to fixed value
JSONObject actual = new JSONObject(s);
@@ -136,7 +133,7 @@ public class VpnProfileTest {
@Test
public void toJson_obfs4hop_kcp() throws JSONException {
- when(ConfigHelper.ObfsVpnHelper.useObfsVpn()).thenReturn(true);
+ when(BuildConfigHelper.useObfsVpn()).thenReturn(true);
VpnProfile mockVpnProfile = new VpnProfile("mockProfile", OBFS4_HOP);
@@ -146,7 +143,6 @@ public class VpnProfileTest {
mockVpnProfile.mLastUsed = 0;
String s = mockVpnProfile.toJson();
- System.out.println(s);
//ignore UUID in comparison -> set it to fixed value
JSONObject actual = new JSONObject(s);
@@ -158,7 +154,7 @@ public class VpnProfileTest {
@Test
public void toJson_obfs4hop_portHopping() throws JSONException {
- when(ConfigHelper.ObfsVpnHelper.useObfsVpn()).thenReturn(true);
+ when(BuildConfigHelper.useObfsVpn()).thenReturn(true);
VpnProfile mockVpnProfile = new VpnProfile("mockProfile", OBFS4_HOP);
@@ -168,7 +164,6 @@ public class VpnProfileTest {
mockVpnProfile.mLastUsed = 0;
String s = mockVpnProfile.toJson();
- System.out.println(s);
//ignore UUID in comparison -> set it to fixed value
JSONObject actual = new JSONObject(s);
@@ -180,7 +175,7 @@ public class VpnProfileTest {
@Test
public void toJson_obfs4hop() throws JSONException {
- when(ConfigHelper.ObfsVpnHelper.useObfsVpn()).thenReturn(true);
+ when(BuildConfigHelper.useObfsVpn()).thenReturn(true);
VpnProfile mockVpnProfile = new VpnProfile("mockProfile", OBFS4_HOP);
Transport.Options options = new Transport.Options("1", new Transport.Endpoint[]{new Transport.Endpoint("1.1.1.1", "CERT1"), new Transport.Endpoint("2.2.2.2", "CERT2")}, 200, 100, true);
@@ -189,7 +184,6 @@ public class VpnProfileTest {
mockVpnProfile.mLastUsed = 0;
String s = mockVpnProfile.toJson();
- System.out.println(s);
//ignore UUID in comparison -> set it to fixed value
JSONObject actual = new JSONObject(s);
@@ -201,7 +195,7 @@ public class VpnProfileTest {
@Test
public void fromJson_obfs4() {
- when(ConfigHelper.ObfsVpnHelper.useObfsVpn()).thenReturn(false);
+ when(BuildConfigHelper.useObfsVpn()).thenReturn(false);
VpnProfile mockVpnProfile = VpnProfile.fromJson(OBFS4CONNECTION_PROFILE);
assertNotNull(mockVpnProfile);
@@ -210,7 +204,10 @@ public class VpnProfileTest {
assertFalse(mockVpnProfile.mConnections[0].isUseUdp());
Obfs4Connection obfs4Connection = (Obfs4Connection) mockVpnProfile.mConnections[0];
assertEquals(OBFS4, obfs4Connection.getTransportType());
- assertFalse(Arrays.asList(obfs4Connection.getObfs4Options().transport.getProtocols()).contains(UDP));
+ String[] protocols = obfs4Connection.getObfs4Options().transport.getProtocols();
+ for (String protocol : protocols) {
+ assertNotEquals(UDP, protocol);
+ }
assertEquals("CERT", obfs4Connection.getObfs4Options().transport.getOptions().getCert());
assertEquals("0", obfs4Connection.getObfs4Options().transport.getOptions().getIatMode());
assertEquals("192.168.0.1", obfs4Connection.getObfs4Options().gatewayIP);
@@ -220,11 +217,11 @@ public class VpnProfileTest {
@Test
public void fromJson_obfs4_obfsvpn() {
- when(ConfigHelper.ObfsVpnHelper.useObfsVpn()).thenReturn(true);
+ when(BuildConfigHelper.useObfsVpn()).thenReturn(true);
VpnProfile mockVpnProfile = VpnProfile.fromJson(OBFS4CONNECTION_PROFILE_OBFSVPN);
assertNotNull(mockVpnProfile);
- assertNotNull(mockVpnProfile.mConnections);
+ assertNotEquals(null, mockVpnProfile.mConnections);
assertNotNull(mockVpnProfile.mConnections[0]);
assertFalse(mockVpnProfile.mConnections[0].isUseUdp());
Obfs4Connection obfs4Connection = (Obfs4Connection) mockVpnProfile.mConnections[0];
@@ -239,7 +236,7 @@ public class VpnProfileTest {
@Test
public void fromJson_obfs4_obfsvpn_kcp() {
- when(ConfigHelper.ObfsVpnHelper.useObfsVpn()).thenReturn(true);
+ when(BuildConfigHelper.useObfsVpn()).thenReturn(true);
VpnProfile mockVpnProfile = VpnProfile.fromJson(OBFS4CONNECTION_PROFILE_OBFSVPN_KCP);
assertNotNull(mockVpnProfile);