summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main/build.gradle7
-rw-r--r--main/src/main/java/de/blinkt/openvpn/VpnProfile.java6
-rw-r--r--main/src/test/java/de/blinkt/openvpn/core/TestConfigGenerator.java74
3 files changed, 83 insertions, 4 deletions
diff --git a/main/build.gradle b/main/build.gradle
index 8a7318b2..b421e864 100644
--- a/main/build.gradle
+++ b/main/build.gradle
@@ -27,6 +27,10 @@ dependencies {
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.2'
testImplementation 'junit:junit:4.12'
+ testImplementation 'org.mockito:mockito-core:2.16.0'
+ testImplementation "org.robolectric:robolectric:3.7.1"
+
+
}
@@ -37,10 +41,11 @@ task ("generateOpenVPN3Swig" ,type:Exec) {
doFirst {
mkdir openvpn3SwigFiles
}
- commandLine "swig", "-outdir", openvpn3SwigFiles, "-outcurrentdir", "-c++", "-java", "-package", "net.openvpn.ovpn3",
+ commandLine "/usr/local/bin/swig", "-outdir", openvpn3SwigFiles, "-outcurrentdir", "-c++", "-java", "-package", "net.openvpn.ovpn3",
"-Isrc/main/cpp/openvpn3/client", "-Isrc/main/cpp/openvpn3/",
"-o", "${openvpn3SwigFiles}/ovpncli_wrap.cxx", "-oh", "${openvpn3SwigFiles}/ovpncli_wrap.h",
"src/main/cpp/openvpn3/javacli/ovpncli.i"
+ environment 'PATH', "${environment.PATH}:/usr/local/bin/"
}
diff --git a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
index 8cce8597..5056a111 100644
--- a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
+++ b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
@@ -307,7 +307,7 @@ public class VpnProfile implements Serializable, Cloneable {
String versionString = getPlatformVersionEnvString();
cfg += String.format("setenv IV_PLAT_VER %s\n", openVpnEscape(versionString));
} else {
- cfg += "# Config for OpeNVPN 3 C++\n";
+ cfg += "# Config for OpenVPN 3 C++\n";
}
@@ -429,8 +429,8 @@ public class VpnProfile implements Serializable, Cloneable {
}
if (isUserPWAuth()) {
- if (mAuthenticationType == AUTH_RETRY_NOINTERACT)
- cfg += "auth-retry nointeract";
+ if (mAuthRetry == AUTH_RETRY_NOINTERACT)
+ cfg += "auth-retry nointeract\n";
}
if (!TextUtils.isEmpty(mCrlFilename))
diff --git a/main/src/test/java/de/blinkt/openvpn/core/TestConfigGenerator.java b/main/src/test/java/de/blinkt/openvpn/core/TestConfigGenerator.java
new file mode 100644
index 00000000..58e5c268
--- /dev/null
+++ b/main/src/test/java/de/blinkt/openvpn/core/TestConfigGenerator.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2012-2018 Arne Schwabe
+ * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
+ */
+
+package de.blinkt.openvpn.core;
+
+import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.test.mock.MockContext;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.io.File;
+
+import static de.blinkt.openvpn.VpnProfile.TYPE_USERPASS;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import de.blinkt.openvpn.VpnProfile;
+
+import static de.blinkt.openvpn.VpnProfile.AUTH_RETRY_NOINTERACT;
+
+/**
+ * Created by arne on 14.03.18.
+ */
+
+@Config(manifest= Config.NONE)
+@RunWith(RobolectricTestRunner.class)
+public class TestConfigGenerator {
+ @Test
+ public void testAuthRetryGen() throws PackageManager.NameNotFoundException {
+ /*Context mc = mock(Context.class);
+ PackageManager mpm = mock(PackageManager.class);
+
+ PackageInfo mpi = new PackageInfo();
+ mpi.versionCode = 177;
+ mpi.versionName = "foo";
+
+ when(mc.getCacheDir()).thenReturn(new File("/j/unit/test/"));
+ when(mc.getPackageName()).thenReturn("de.blinkt.openvpn");
+ when(mc.getPackageManager()).thenReturn(mpm);
+ when(mpm.getPackageInfo(eq("de.blinkt.openvpn"),eq(0))).thenReturn(mpi);*/
+
+
+
+ VpnProfile vp = new VpnProfile ("test") {
+ @Override
+ public String getVersionEnvString(Context c) {
+ return "no ver";
+ }
+
+ @Override
+ public String getPlatformVersionEnvString() {
+ return "test";
+ }
+ };
+
+ vp.mAuthenticationType = TYPE_USERPASS;
+ vp.mAuthRetry = AUTH_RETRY_NOINTERACT;
+ String config = vp.getConfigFile(RuntimeEnvironment.application, false);
+ Assert.assertTrue(config.contains("\nauth-retry nointeract\n"));
+
+ }
+}