diff options
Diffstat (limited to 'tests/test-extensions-tests')
-rw-r--r-- | tests/test-extensions-tests/net/sourceforge/jnlp/ServerAccessTest.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test-extensions-tests/net/sourceforge/jnlp/ServerAccessTest.java b/tests/test-extensions-tests/net/sourceforge/jnlp/ServerAccessTest.java index 3ddd09e..1b93e3e 100644 --- a/tests/test-extensions-tests/net/sourceforge/jnlp/ServerAccessTest.java +++ b/tests/test-extensions-tests/net/sourceforge/jnlp/ServerAccessTest.java @@ -39,6 +39,8 @@ package net.sourceforge.jnlp; import java.io.File; import java.io.FileInputStream; import java.net.URL; +import java.net.URLDecoder; + import org.junit.Assert; import org.junit.Test; @@ -217,6 +219,42 @@ public class ServerAccessTest { Assert.assertArrayEquals(b2, bb[1]); Assert.assertArrayEquals(b3, bb[2]); } + + private static final String[] filePathTestUrls = { + "/foo.html", + "/foo/", + "/foo/bar.jar", + "/foo/bar.jar;path_param", + "/foo/bar.jar%3Bpath_param", + "/foo/bar?query=string&red=hat" + }; + + @Test + public void urlToFilePathTest() throws Exception { + for (String url : filePathTestUrls) { + String newUrl = TinyHttpdImpl.urlToFilePath(url); + + Assert.assertFalse("File path should not contain query string: " + newUrl, newUrl.contains("?")); + Assert.assertTrue("File path should be relative: " + newUrl, newUrl.startsWith("./")); + Assert.assertFalse("File path should not contain \"/XslowX\":" + newUrl, + newUrl.toLowerCase().contains("/XslowX".toLowerCase())); + + if (url.endsWith("/")) { + Assert.assertTrue(newUrl.endsWith("/index.html")); + } + } + } + + @Test + public void urlToFilePathUrlDecodeTest() throws Exception { + // This test may fail with strange original URLs, eg those containing the substring "%253B", + // which can be decoded into "%3B", then decoded again into ';'. + + for (String url : filePathTestUrls) { + String newUrl = TinyHttpdImpl.urlToFilePath(url); + Assert.assertEquals(newUrl, URLDecoder.decode(newUrl, "UTF-8")); + } + } @Test public void stripHttpPathParamTest() { |