diff options
author | Arne Schwabe <arne@rfc2549.org> | 2018-10-02 18:57:28 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2018-10-02 18:57:28 +0200 |
commit | de2173c73acd042d5364685ac36fa287161face2 (patch) | |
tree | b063bc598f3e2bfbcb0a27daf799a419d59bbbf7 /main/src/test/java/de/blinkt | |
parent | 84dd219b0e59d262bf74d6995ec5420d44a6c8ce (diff) |
Fix some VPN Config import problem (closes #935)
Diffstat (limited to 'main/src/test/java/de/blinkt')
-rw-r--r-- | main/src/test/java/de/blinkt/openvpn/core/TestConfigParser.java | 82 |
1 files changed, 61 insertions, 21 deletions
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 f0047ac7..248f6089 100644 --- a/main/src/test/java/de/blinkt/openvpn/core/TestConfigParser.java +++ b/main/src/test/java/de/blinkt/openvpn/core/TestConfigParser.java @@ -29,7 +29,27 @@ import org.robolectric.annotation.Config; @RunWith(RobolectricTestRunner.class) public class TestConfigParser { - String miniconfig = "client\nremote test.blinkt.de\n"; + public static final String fakeCerts = "<ca>\n" + + "-----BEGIN CERTIFICATE-----\n" + + "\n" + + "-----END CERTIFICATE-----\n" + + "\n" + + "</ca>\n" + + "\n" + + "<cert>\n" + + "-----BEGIN CERTIFICATE-----\n" + + "\n" + + "-----END CERTIFICATE-----\n" + + "\n" + + "</cert>\n" + + "\n" + + "<key>\n" + + "-----BEGIN PRIVATE KEY-----\n" + + "\n" + + "-----END PRIVATE KEY-----\n" + + "\n" + + "</key>"; + private final String miniconfig = "client\nremote test.blinkt.de\n"; @Test public void testHttpProxyPass() throws IOException, ConfigParser.ConfigParseError { @@ -47,6 +67,45 @@ public class TestConfigParser { } @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" + + "<connection>\n" + + "remote foo.bar\n" + + "tun-mtu 1222\n"+ + "</connection>\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" + @@ -166,26 +225,7 @@ public class TestConfigParser { "http-proxy-option CUSTOM-HEADER \"DNT: 1\"\n" + "http-proxy-option CUSTOM-HEADER \"Tk: N\"\n" + "\n" + - "<ca>\n" + - "-----BEGIN CERTIFICATE-----\n" + - "\n" + - "-----END CERTIFICATE-----\n" + - "\n" + - "</ca>\n" + - "\n" + - "<cert>\n" + - "-----BEGIN CERTIFICATE-----\n" + - "\n" + - "-----END CERTIFICATE-----\n" + - "\n" + - "</cert>\n" + - "\n" + - "<key>\n" + - "-----BEGIN PRIVATE KEY-----\n" + - "\n" + - "-----END PRIVATE KEY-----\n" + - "\n" + - "</key>"; + fakeCerts; ConfigParser cp = new ConfigParser(); cp.parseConfig(new StringReader(proxyconf)); |