diff options
author | Adam Domurad <[email protected]> | 2013-03-28 14:40:11 -0400 |
---|---|---|
committer | Adam Domurad <[email protected]> | 2013-03-28 14:40:11 -0400 |
commit | 30cfedc8f9d0fcaa0378005c9a0ca38930bf946b (patch) | |
tree | 374f8075602a274bab0c4deba711f9a67e277e94 | |
parent | 6bc87a67d88072fa2d701cf4e6a700893ee81e00 (diff) |
Move normalizeUrlAndStripParams to UrlUtils
5 files changed, 66 insertions, 37 deletions
@@ -1,3 +1,16 @@ +2013-03-28 Adam Domurad <[email protected]> + + * netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmation.java + (normalizeUrlAndStripParams): Moved. + * netx/net/sourceforge/jnlp/util/UrlUtils.java + (normalizeUrlAndStripParams): New, moved from + UnsignedAppletTrustConfirmation. + * tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmationTest.java + (testNormalizeUrlAndStripParams): Moved. + * tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java: + New, has (testNormalizeUrlAndStripParams) from + UnsignedAppletTrustConfirmationTest. + 2013-03-22 Jiri Vanek <[email protected]> Added code to parse properties and to find correct configuration files diff --git a/netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmation.java b/netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmation.java index 26bc1d4..6139321 100644 --- a/netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmation.java +++ b/netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmation.java @@ -45,6 +45,8 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; + +import net.sourceforge.jnlp.util.UrlUtils; import net.sourceforge.jnlp.LaunchException; import net.sourceforge.jnlp.PluginBridge; import net.sourceforge.jnlp.cache.ResourceTracker; @@ -96,24 +98,11 @@ public class UnsignedAppletTrustConfirmation { private static UnsignedAppletActionEntry getMatchingItem(UnsignedAppletActionStorage actionStorage, PluginBridge file) { return actionStorage.getMatchingItem( - normalizeUrlAndStripParams(file.getSourceLocation()).toString(), - normalizeUrlAndStripParams(file.getCodeBase()).toString(), + UrlUtils.normalizeUrlAndStripParams(file.getSourceLocation()).toString(), + UrlUtils.normalizeUrlAndStripParams(file.getCodeBase()).toString(), toRelativePaths(file.getArchiveJars(), file.getCodeBase().toString())); } - static URL normalizeUrlAndStripParams(URL url) { - try { - String[] urlParts = url.toString().split("\\?"); - URL strippedUrl = new URL(urlParts[0]); - return ResourceTracker.normalizeUrl(strippedUrl, false); - } catch (IOException e) { - e.printStackTrace(); - } catch (URISyntaxException e) { - e.printStackTrace(); - } - return url; - } - /* Extract the archives as relative paths */ static List<String> toRelativePaths(List<String> paths, String rootPath) { List<String> fileNames = new ArrayList<String>(); @@ -142,8 +131,8 @@ public class UnsignedAppletTrustConfirmation { return; } - URL codebase = normalizeUrlAndStripParams(file.getCodeBase()); - URL documentbase = normalizeUrlAndStripParams(file.getSourceLocation()); + URL codebase = UrlUtils.normalizeUrlAndStripParams(file.getCodeBase()); + URL documentbase = UrlUtils.normalizeUrlAndStripParams(file.getSourceLocation()); /* Else, create a new entry */ UrlRegEx codebaseRegex = new UrlRegEx("\\Q" + codebase + "\\E"); diff --git a/netx/net/sourceforge/jnlp/util/UrlUtils.java b/netx/net/sourceforge/jnlp/util/UrlUtils.java index 403b977..a043bb0 100644 --- a/netx/net/sourceforge/jnlp/util/UrlUtils.java +++ b/netx/net/sourceforge/jnlp/util/UrlUtils.java @@ -37,10 +37,27 @@ exception statement from your version. package net.sourceforge.jnlp.util; +import java.io.IOException; +import java.net.URISyntaxException; import java.net.URL; +import net.sourceforge.jnlp.cache.ResourceTracker; + public class UrlUtils { + public static URL normalizeUrlAndStripParams(URL url) { + try { + String[] urlParts = url.toString().split("\\?"); + URL strippedUrl = new URL(urlParts[0]); + return ResourceTracker.normalizeUrl(strippedUrl, false); + } catch (IOException e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + return url; + } + public static boolean isLocalFile(URL url) { if (url.getProtocol().equals("file") && diff --git a/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmationTest.java b/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmationTest.java index be33f20..31da5d3 100644 --- a/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmationTest.java +++ b/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmationTest.java @@ -36,24 +36,4 @@ public class UnsignedAppletTrustConfirmationTest { assertEquals(toList("test .jar"), UnsignedAppletTrustConfirmation.toRelativePaths(toList("http://example.com/test .jar"), "http://example.com/")); } - - @Test - public void testNormalizeUrlAndStripParams() throws Exception { - /* Test that URL is normalized (encoded if not already encoded, leading whitespace trimmed, etc) */ - assertEquals("http://example.com/%20test%20test", - UnsignedAppletTrustConfirmation.normalizeUrlAndStripParams(new URL("http://example.com/ test%20test ")).toString()); - /* Test that a URL without '?' is left unchanged */ - assertEquals("http://example.com/test", - UnsignedAppletTrustConfirmation.normalizeUrlAndStripParams(new URL("http://example.com/test")).toString()); - /* Test that parts of a URL that come after '?' are stripped */ - assertEquals("http://example.com/test", - UnsignedAppletTrustConfirmation.normalizeUrlAndStripParams(new URL("http://example.com/test?test=test")).toString()); - /* Test that everything after the first '?' is stripped */ - assertEquals("http://example.com/test", - UnsignedAppletTrustConfirmation.normalizeUrlAndStripParams(new URL("http://example.com/test?http://example.com/?test")).toString()); - - /* Test normalization + stripping */ - assertEquals("http://example.com/%20test%20test", - UnsignedAppletTrustConfirmation.normalizeUrlAndStripParams(new URL("http://www.example.com/ test%20test ?test=test")).toString()); - } }
\ No newline at end of file diff --git a/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java b/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java new file mode 100644 index 0000000..bd0ef17 --- /dev/null +++ b/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java @@ -0,0 +1,30 @@ +package net.sourceforge.jnlp.util; + +import static org.junit.Assert.*; + +import java.net.URL; + +import org.junit.Test; + +public class UrlUtilsTest { + + @Test + public void testNormalizeUrlAndStripParams() throws Exception { + /* Test that URL is normalized (encoded if not already encoded, leading whitespace trimmed, etc) */ + assertEquals("http://example.com/%20test%20test", + UrlUtils.normalizeUrlAndStripParams(new URL("http://example.com/ test%20test ")).toString()); + /* Test that a URL without '?' is left unchanged */ + assertEquals("http://example.com/test", + UrlUtils.normalizeUrlAndStripParams(new URL("http://example.com/test")).toString()); + /* Test that parts of a URL that come after '?' are stripped */ + assertEquals("http://example.com/test", + UrlUtils.normalizeUrlAndStripParams(new URL("http://example.com/test?test=test")).toString()); + /* Test that everything after the first '?' is stripped */ + assertEquals("http://example.com/test", + UrlUtils.normalizeUrlAndStripParams(new URL("http://example.com/test?http://example.com/?test")).toString()); + + /* Test normalization + stripping */ + assertEquals("http://example.com/%20test%20test", + UrlUtils.normalizeUrlAndStripParams(new URL("http://example.com/ test%20test ?test=test")).toString()); + } +} |