From 111c3cf994f6788aa6251f3f8a1992765ba967d1 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Wed, 14 Mar 2018 23:03:34 +0100 Subject: Tests for sock proxy support --- main/build.gradle | 7 ++-- .../java/de/blinkt/openvpn/core/ConfigParser.java | 16 ++++++--- .../de/blinkt/openvpn/core/TestConfigParser.java | 38 ++++++++++++++++++++++ 3 files changed, 53 insertions(+), 8 deletions(-) (limited to 'main') diff --git a/main/build.gradle b/main/build.gradle index 680bba69..8a7318b2 100644 --- a/main/build.gradle +++ b/main/build.gradle @@ -20,9 +20,9 @@ repositories { dependencies { implementation 'com.android.support.constraint:constraint-layout:1.0.2' - implementation 'com.android.support:support-annotations:27.0.2' - implementation 'com.android.support:cardview-v7:27.0.2' - implementation 'com.android.support:recyclerview-v7:27.0.2' + implementation 'com.android.support:support-annotations:27.1.0' + implementation 'com.android.support:cardview-v7:27.1.0' + implementation 'com.android.support:recyclerview-v7:27.1.0' // compile 'ch.acra:acra:4.5.0' implementation 'com.github.PhilJay:MPAndroidChart:v3.0.2' @@ -113,7 +113,6 @@ android { dimension "implementation" buildConfigField 'boolean', 'openvpn3', 'false' } - normal { dimension "implementation" buildConfigField 'boolean', 'openvpn3', 'true' 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>> options = new HashMap>>(); + private HashMap>> options = new HashMap<>(); private HashMap> meta = new HashMap>(); 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 str) { + if (Build.VERSION.SDK_INT > 26) + return String.join(s, str); + else + return TextUtils.join(s, str); + } + private Pair 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 = + "\n" + + "socks-proxy 13.23.3.2\n" + + "remote foo.bar\n" + + "\n" + + "\n" + + "\n" + + "socks-proxy 1.2.3.4 1234\n" + + "remote foo.bar\n" + + "\n" + + "\n" + + "\n" + + "http-proxy 1.2.3.7 8080\n" + + "remote foo.bar\n" + + ""; + + 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); + } + + } -- cgit v1.2.3