diff options
author | Arne Schwabe <arne@rfc2549.org> | 2018-04-04 14:32:18 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2018-04-04 16:05:40 +0200 |
commit | af2709bcf95654b944cac2f94975a10f8037a53f (patch) | |
tree | dc53d9615dc5daca4dcba583ab0bf11bb1a906a7 /main/src/test/java/de | |
parent | 0db69bbeed93c59e6643d2f392721050a3c30064 (diff) |
Improve unit tests, fix orbot warning (closes #860)
Diffstat (limited to 'main/src/test/java/de')
-rw-r--r-- | main/src/test/java/de/blinkt/openvpn/core/TestConfigGenerator.java | 3 | ||||
-rw-r--r-- | main/src/test/java/de/blinkt/openvpn/core/TestConfigParser.java | 59 |
2 files changed, 61 insertions, 1 deletions
diff --git a/main/src/test/java/de/blinkt/openvpn/core/TestConfigGenerator.java b/main/src/test/java/de/blinkt/openvpn/core/TestConfigGenerator.java index 66e69ca5..4fb14d2c 100644 --- a/main/src/test/java/de/blinkt/openvpn/core/TestConfigGenerator.java +++ b/main/src/test/java/de/blinkt/openvpn/core/TestConfigGenerator.java @@ -60,6 +60,9 @@ public class TestConfigGenerator { vp.mAuthRetry = AUTH_RETRY_NOINTERACT; String config = vp.getConfigFile(RuntimeEnvironment.application, false); Assert.assertTrue(config.contains("\nauth-retry nointeract\n")); + for (Connection connection: vp.mConnections) + Assert.assertTrue(connection.mProxyType == Connection.ProxyType.NONE); } + } 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 5793676f..6615a8f0 100644 --- a/main/src/test/java/de/blinkt/openvpn/core/TestConfigParser.java +++ b/main/src/test/java/de/blinkt/openvpn/core/TestConfigParser.java @@ -5,18 +5,27 @@ package de.blinkt.openvpn.core; +import android.app.Application; +import android.content.Context; +import de.blinkt.openvpn.R; import org.junit.Assert; import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; import java.io.IOException; import java.io.StringReader; import de.blinkt.openvpn.VpnProfile; +import org.robolectric.annotation.Config; /** * Created by arne on 03.10.16. */ +@Config(manifest= "src/main/AndroidManifest.xml") +@RunWith(RobolectricTestRunner.class) public class TestConfigParser { String miniconfig = "client\nremote test.blinkt.de\n"; @@ -38,7 +47,11 @@ public class TestConfigParser { @Test public void testSockProxyImport() throws IOException, ConfigParser.ConfigParseError { String proxy = - "<connection>\n" + + "ca baz\n" + + "key foo\n" + + "cert bar\n" + + "client\n" + + "<connection>\n" + "socks-proxy 13.23.3.2\n" + "remote foo.bar\n" + "</connection>\n" + @@ -69,7 +82,51 @@ public class TestConfigParser { 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); + + Context c = RuntimeEnvironment.application; + int err = vp.checkProfile(c, false); + Assert.assertTrue("Failed with " + c.getString(err), err == R.string.no_error_found); } + @Test + public void testHttpUserPassAuth() throws IOException, ConfigParser.ConfigParseError { + String proxy ="client\n" + + "dev tun\n" + + "proto tcp\n" + + "remote 1.2.3.4 443\n" + + "resolv-retry infinite\n" + + "nobind\n" + + "persist-key\n" + + "persist-tun\n" + + "auth-user-pass\n" + + "verb 3\n" + + "cipher AES-128-CBC\n" + + "pull\n" + + "route-delay 2\n" + + "redirect-gateway\n" + + "remote-cert-tls server\n" + + "ns-cert-type server\n" + + "comp-lzo no\n" + + "http-proxy 1.2.3.4 1234\n" + + "<http-proxy-user-pass>\n" + + "username12\n" + + "password34\n" + + "</http-proxy-user-pass>\n" + + "<ca>\n" + + "foo\n" + + "</ca>\n" + + "<cert>\n" + + "bar\n" + + "</cert>\n" + + "<key>\n" + + "baz\n" + + "</key>\n"; + ConfigParser cp = new ConfigParser(); + cp.parseConfig(new StringReader(proxy)); + VpnProfile vp = cp.convertProfile(); + String config = vp.getConfigFile(RuntimeEnvironment.application, false); + Assert.assertTrue(config.contains("username12")); + Assert.assertTrue(config.contains("http-proxy 1.2.3.4")); + } } |