diff options
author | Andrew Azores <[email protected]> | 2013-06-18 15:57:01 -0400 |
---|---|---|
committer | Andrew Azores <[email protected]> | 2013-06-18 15:57:01 -0400 |
commit | 222acc6f3e99b2c473036ebc76f6370acf487e6d (patch) | |
tree | 3d09892e0ae31d1c73a6826324b57b13f288710a /tests/test-extensions-tests | |
parent | faffea863331de3cb97e5654313922fafd61745c (diff) |
Extract URL to file logic in TinyHttpdImpl.java, with unit tests
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() { |