summaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java16
-rw-r--r--main/src/test/java/de/blinkt/openvpn/core/TestConfigParser.java38
2 files changed, 50 insertions, 4 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java b/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java
index f83a271e..883edf53 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java
@@ -5,8 +5,9 @@
package de.blinkt.openvpn.core;
-import android.text.TextUtils;
+import android.os.Build;
import android.support.v4.util.Pair;
+import android.text.TextUtils;
import java.io.BufferedReader;
import java.io.IOException;
@@ -29,7 +30,7 @@ public class ConfigParser {
public static final String CONVERTED_PROFILE = "converted Profile";
- private HashMap<String, Vector<Vector<String>>> options = new HashMap<String, Vector<Vector<String>>>();
+ private HashMap<String, Vector<Vector<String>>> options = new HashMap<>();
private HashMap<String, Vector<String>> meta = new HashMap<String, Vector<String>>();
private String auth_user_pass_file;
@@ -667,7 +668,7 @@ public class ConfigParser {
if (crlfile != null) {
// If the 'dir' parameter is present just add it as custom option ..
if (crlfile.size() == 3 && crlfile.get(2).equals("dir"))
- np.mCustomConfigOptions += TextUtils.join(" ", crlfile) + "\n";
+ np.mCustomConfigOptions += join(" ", crlfile) + "\n";
else
// Save the filename for the config converter to add later
np.mCrlFilename = crlfile.get(1);
@@ -733,6 +734,13 @@ public class ConfigParser {
return np;
}
+ private String join(String s, Vector<String> str) {
+ if (Build.VERSION.SDK_INT > 26)
+ return String.join(s, str);
+ else
+ return TextUtils.join(s, str);
+ }
+
private Pair<Connection, Connection[]> parseConnection(String connection, Connection defaultValues) throws IOException, ConfigParseError {
// Parse a connection Block as a new configuration file
@@ -816,7 +824,7 @@ public class ConfigParser {
conn.mCustomConfiguration += getOptionStrings(option);
}
- if (!TextUtils.isEmpty(conn.mCustomConfiguration))
+ if (!(conn.mCustomConfiguration == null || "".equals(conn.mCustomConfiguration.trim())))
conn.mUseCustomConfig = true;
}
// Make remotes empty to simplify code
diff --git a/main/src/test/java/de/blinkt/openvpn/core/TestConfigParser.java b/main/src/test/java/de/blinkt/openvpn/core/TestConfigParser.java
index 560d4fc8..5793676f 100644
--- a/main/src/test/java/de/blinkt/openvpn/core/TestConfigParser.java
+++ b/main/src/test/java/de/blinkt/openvpn/core/TestConfigParser.java
@@ -34,4 +34,42 @@ public class TestConfigParser {
Assert.assertTrue(p.mCustomConfigOptions.contains(httpproxypass));
}
+
+ @Test
+ public void testSockProxyImport() throws IOException, ConfigParser.ConfigParseError {
+ String proxy =
+ "<connection>\n" +
+ "socks-proxy 13.23.3.2\n" +
+ "remote foo.bar\n" +
+ "</connection>\n" +
+ "\n" +
+ "<connection>\n" +
+ "socks-proxy 1.2.3.4 1234\n" +
+ "remote foo.bar\n" +
+ "</connection>\n" +
+ "\n" +
+ "<connection>\n" +
+ "http-proxy 1.2.3.7 8080\n" +
+ "remote foo.bar\n" +
+ "</connection>";
+
+ ConfigParser cp = new ConfigParser();
+ cp.parseConfig(new StringReader(proxy));
+ VpnProfile vp = cp.convertProfile();
+ Assert.assertEquals(3, vp.mConnections.length);
+
+ Assert.assertEquals("13.23.3.2", vp.mConnections[0].mProxyName);
+ Assert.assertEquals("1080", vp.mConnections[0].mProxyPort);
+ Assert.assertEquals(Connection.ProxyType.SOCKS5, vp.mConnections[0].mProxyType);
+
+ Assert.assertEquals("1.2.3.4", vp.mConnections[1].mProxyName);
+ Assert.assertEquals("1234", vp.mConnections[1].mProxyPort);
+ Assert.assertEquals(Connection.ProxyType.SOCKS5, vp.mConnections[0].mProxyType);
+
+ Assert.assertEquals("1.2.3.7", vp.mConnections[2].mProxyName);
+ Assert.assertEquals("8080", vp.mConnections[2].mProxyPort);
+ Assert.assertEquals(Connection.ProxyType.HTTP, vp.mConnections[2].mProxyType);
+ }
+
+
}