From b65eb4154b50644c5858a2d55f3ce531bcfc171e Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 20 Oct 2018 10:14:30 +0200 Subject: remove ics-openvpn mock classes --- .../blinkt/openvpn/core/TestConfigGenerator.java | 69 ------ .../de/blinkt/openvpn/core/TestConfigParser.java | 256 --------------------- .../java/de/blinkt/openvpn/core/TestIpParser.java | 38 --- .../de/blinkt/openvpn/core/TestLogFileHandler.java | 124 ---------- 4 files changed, 487 deletions(-) delete mode 100644 app/src/test/java/de/blinkt/openvpn/core/TestConfigGenerator.java delete mode 100644 app/src/test/java/de/blinkt/openvpn/core/TestConfigParser.java delete mode 100644 app/src/test/java/de/blinkt/openvpn/core/TestIpParser.java delete mode 100644 app/src/test/java/de/blinkt/openvpn/core/TestLogFileHandler.java (limited to 'app/src/test/java/de') diff --git a/app/src/test/java/de/blinkt/openvpn/core/TestConfigGenerator.java b/app/src/test/java/de/blinkt/openvpn/core/TestConfigGenerator.java deleted file mode 100644 index 892a5807..00000000 --- a/app/src/test/java/de/blinkt/openvpn/core/TestConfigGenerator.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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.PackageManager; - -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 de.blinkt.openvpn.VpnProfile; - -import static de.blinkt.openvpn.VpnProfile.AUTH_RETRY_NOINTERACT; -import static de.blinkt.openvpn.VpnProfile.TYPE_USERPASS; - -/** - * 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")); - for (Connection connection: vp.mConnections) - Assert.assertTrue(connection.mProxyType == Connection.ProxyType.NONE); - - } - - -} diff --git a/app/src/test/java/de/blinkt/openvpn/core/TestConfigParser.java b/app/src/test/java/de/blinkt/openvpn/core/TestConfigParser.java deleted file mode 100644 index 41ee2981..00000000 --- a/app/src/test/java/de/blinkt/openvpn/core/TestConfigParser.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright (c) 2012-2016 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.app.Application; -import android.content.Context; -import se.leap.bitmaskclient.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 java.util.Arrays; - -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 { - - public static final String fakeCerts = "\n" + - "-----BEGIN CERTIFICATE-----\n" + - "\n" + - "-----END CERTIFICATE-----\n" + - "\n" + - "\n" + - "\n" + - "\n" + - "-----BEGIN CERTIFICATE-----\n" + - "\n" + - "-----END CERTIFICATE-----\n" + - "\n" + - "\n" + - "\n" + - "\n" + - "-----BEGIN PRIVATE KEY-----\n" + - "\n" + - "-----END PRIVATE KEY-----\n" + - "\n" + - ""; - private final String miniconfig = "client\nremote test.blinkt.de\n"; - - @Test - public void testHttpProxyPass() throws IOException, ConfigParser.ConfigParseError { - String httpproxypass = "\n" + - "foo\n" + - "bar\n" + - "\n"; - - ConfigParser cp = new ConfigParser(); - cp.parseConfig(new StringReader(miniconfig + httpproxypass)); - VpnProfile p = cp.convertProfile(); - Assert.assertFalse(p.mCustomConfigOptions.contains(httpproxypass)); - - - } - - @Test - public void cleanReImport() throws IOException, ConfigParser.ConfigParseError { - ConfigParser cp = new ConfigParser(); - cp.parseConfig(new StringReader(miniconfig + fakeCerts)); - VpnProfile vp = cp.convertProfile(); - - String outConfig = vp.getConfigFile(RuntimeEnvironment.application, false); - - cp = new ConfigParser(); - cp.parseConfig(new StringReader(outConfig)); - VpnProfile vp2 = cp.convertProfile(); - - String outConfig2 = vp2.getConfigFile(RuntimeEnvironment.application, false); - - Assert.assertEquals(outConfig, outConfig2); - Assert.assertFalse(vp.mUseCustomConfig); - Assert.assertFalse(vp2.mUseCustomConfig); - - } - - @Test - public void testCommonOptionsImport() throws IOException, ConfigParser.ConfigParseError - { - String config = "client\n" - + "tun-mtu 1234\n" + - "\n" + - "remote foo.bar\n" + - "tun-mtu 1222\n"+ - "\n"; - - ConfigParser cp = new ConfigParser(); - cp.parseConfig(new StringReader(config)); - VpnProfile vp = cp.convertProfile(); - - Assert.assertEquals(1234, vp.mTunMtu); - Assert.assertTrue(vp.mConnections[0].mCustomConfiguration.contains("tun-mtu 1222")); - Assert.assertTrue(vp.mConnections[0].mUseCustomConfig); - } - - @Test - public void testSockProxyImport() throws IOException, ConfigParser.ConfigParseError { - String proxy = - "ca baz\n" + - "key foo\n" + - "cert bar\n" + - "client\n" + - "\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); - - 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" + - "\n" + - "username12\n" + - "password34\n" + - "\n" + - "\n" + - "foo\n" + - "\n" + - "\n" + - "bar\n" + - "\n" + - "\n" + - "baz\n" + - "\n"; - ConfigParser cp = new ConfigParser(); - cp.parseConfig(new StringReader(proxy)); - VpnProfile vp = cp.convertProfile(); - String config = vp.getConfigFile(RuntimeEnvironment.application, true); - Assert.assertTrue(config.contains("username12")); - Assert.assertTrue(config.contains("http-proxy 1.2.3.4")); - - config = vp.getConfigFile(RuntimeEnvironment.application, false); - - Assert.assertFalse(config.contains("username12")); - Assert.assertFalse(config.contains("http-proxy 1.2.3.4")); - - Assert.assertTrue(vp.mConnections[0].mUseProxyAuth); - Assert.assertEquals(vp.mConnections[0].mProxyAuthUser, "username12"); - Assert.assertEquals(vp.mConnections[0].mProxyAuthPassword, "password34"); - } - - @Test - public void testConfigWithHttpProxyOptions() throws IOException, ConfigParser.ConfigParseError { - String proxyconf = "pull\n" + - "dev tun\n" + - "proto tcp-client\n" + - "cipher AES-128-CBC\n" + - "auth SHA1\n" + - "reneg-sec 0\n" + - "remote-cert-tls server\n" + - "tls-version-min 1.2 or-highest\n" + - "persist-tun\n" + - "nobind\n" + - "connect-retry 2 2\n" + - "dhcp-option DNS 1.1.1.1\n" + - "dhcp-option DNS 84.200.69.80\n" + - "auth-user-pass\n" + - "\n" + - "remote xx.xx.xx.xx 1194\n" + - "http-proxy 1.2.3.4 8080\n" + - "http-proxy-option VERSION 1.1\n" + - "http-proxy-option CUSTOM-HEADER \"Connection: Upgrade\"\n" + - "http-proxy-option CUSTOM-HEADER \"X-Forwarded-Proto: https\"\n" + - "http-proxy-option CUSTOM-HEADER \"Upgrade-Insecure-Requests: 1\"\n" + - "http-proxy-option CUSTOM-HEADER \"DNT: 1\"\n" + - "http-proxy-option CUSTOM-HEADER \"Tk: N\"\n" + - "\n" + - fakeCerts; - - ConfigParser cp = new ConfigParser(); - cp.parseConfig(new StringReader(proxyconf)); - VpnProfile vp = cp.convertProfile(); - String config = vp.getConfigFile(RuntimeEnvironment.application, true); - - - Assert.assertEquals(vp.checkProfile(RuntimeEnvironment.application, true), R.string.no_error_found); - Assert.assertEquals(vp.checkProfile(RuntimeEnvironment.application, false), R.string.no_error_found); - - config = vp.getConfigFile(RuntimeEnvironment.application, false); - - Assert.assertTrue(config.contains("http-proxy 1.2.3.4")); - Assert.assertFalse(config.contains("management-query-proxy")); - - - Assert.assertTrue(config.contains("http-proxy-option CUSTOM-HEADER")); - - vp.mConnections = Arrays.copyOf(vp.mConnections, vp.mConnections.length + 1); - vp.mConnections[vp.mConnections.length - 1] = new Connection(); - - vp.mConnections[vp.mConnections.length -1].mProxyType = Connection.ProxyType.ORBOT; - - Assert.assertEquals(vp.checkProfile(RuntimeEnvironment.application, false), R.string.error_orbot_and_proxy_options); - - } - -} diff --git a/app/src/test/java/de/blinkt/openvpn/core/TestIpParser.java b/app/src/test/java/de/blinkt/openvpn/core/TestIpParser.java deleted file mode 100644 index 6b330b63..00000000 --- a/app/src/test/java/de/blinkt/openvpn/core/TestIpParser.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2012-2016 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 junit.framework.Assert; - -import org.junit.Test; - -import java.net.Inet6Address; -import java.net.InetAddress; -import java.net.UnknownHostException; - -/** - * Created by arne on 23.07.16. - */ - -public class TestIpParser { - - @Test - public void parseIPv6Zeros() throws UnknownHostException { - - testAddress("2020:0:1234::", 45, "2020:0:1234::/45"); - testAddress("::", 0, "::/0"); - testAddress("2a02:2e0:3fe:1001:302::", 128, "2a02:2e0:3fe:1001:302::/128"); - testAddress("2a02:2e0:3fe:1001:302::70", 128, "2a02:2e0:3fe:1001:302:0:0:70/128"); - } - - void testAddress(String input, int mask, String output) throws UnknownHostException { - Inet6Address ip = (Inet6Address) InetAddress.getByName(input); - - NetworkSpace.IpAddress netIp = new NetworkSpace.IpAddress(ip, mask, true); - - Assert.assertEquals(output, netIp.toString()); - } -} diff --git a/app/src/test/java/de/blinkt/openvpn/core/TestLogFileHandler.java b/app/src/test/java/de/blinkt/openvpn/core/TestLogFileHandler.java deleted file mode 100644 index b32e5efa..00000000 --- a/app/src/test/java/de/blinkt/openvpn/core/TestLogFileHandler.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2012-2017 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.annotation.SuppressLint; - -import junit.framework.Assert; - -import org.junit.Before; -import org.junit.Test; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.util.Arrays; - -public class TestLogFileHandler { - - byte[] testUnescaped = new byte[]{0x00, 0x55, -27, 0x00, 0x56, 0x10, -128, 0x55, 0x54}; - byte[] expectedEscaped = new byte[]{0x55, 0x00, 0x00, 0x00, 0x09, 0x00, 0x56, 0x00, -27, 0x00, 0x56, 0x01, 0x10, -128, 0x56, 0x00, 0x54}; - private TestingLogFileHandler lfh; - - - @Before - public void setup() { - lfh = new TestingLogFileHandler(); - } - - @Test - public void testWriteByteArray() throws IOException { - - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - - lfh.setLogFile(byteArrayOutputStream); - - lfh.writeEscapedBytes(testUnescaped); - - byte[] result = byteArrayOutputStream.toByteArray(); - Assert.assertTrue(Arrays.equals(expectedEscaped, result)); - } - - @Test - public void readByteArray() throws IOException { - - ByteArrayInputStream in = new ByteArrayInputStream(expectedEscaped); - - lfh.readCacheContents(in); - - Assert.assertTrue(Arrays.equals(testUnescaped, lfh.mRestoredByteArray)); - - } - - @Test - public void testMarschal() throws UnsupportedEncodingException { - LogItem li = new LogItem(VpnStatus.LogLevel.DEBUG, 72, "foobar"); - LogItem li2 = marschalAndBack(li); - testEquals(li, li2); - Assert.assertEquals(li, li2); - } - - @Test - public void testMarschalArgs() throws UnsupportedEncodingException { - LogItem li = new LogItem(VpnStatus.LogLevel.DEBUG, 72, 772, "sinnloser Text", 7723, 723.2f, 7.2); - LogItem li2 = marschalAndBack(li); - testEquals(li, li2); - Assert.assertEquals(li, li2); - } - - @Test - public void testMarschalString() throws UnsupportedEncodingException { - LogItem li = new LogItem(VpnStatus.LogLevel.DEBUG, "Nutzlose Nachricht"); - LogItem li2 = marschalAndBack(li); - testEquals(li, li2); - Assert.assertEquals(li, li2); - } - - - private void testEquals(LogItem li, LogItem li2) { - Assert.assertEquals(li.getLogLevel(), li2.getLogLevel()); - Assert.assertEquals(li.getLogtime(), li2.getLogtime()); - Assert.assertEquals(li.getVerbosityLevel(), li2.getVerbosityLevel()); - Assert.assertEquals(li.toString(), li2.toString()); - - } - - private LogItem marschalAndBack(LogItem li) throws UnsupportedEncodingException { - byte[] bytes = li.getMarschaledBytes(); - - return new LogItem(bytes, bytes.length); - } - - - @SuppressLint("HandlerLeak") - static class TestingLogFileHandler extends LogFileHandler { - - public byte[] mRestoredByteArray; - - public TestingLogFileHandler() { - super(null); - } - - public void setLogFile(OutputStream out) { - mLogFile = out; - } - - @Override - public void readCacheContents(InputStream in) throws IOException { - super.readCacheContents(in); - } - - @Override - protected void restoreLogItem(byte[] buf, int len) { - mRestoredByteArray = Arrays.copyOf(buf, len); - } - } - - -} \ No newline at end of file -- cgit v1.2.3