Mercurial > hg > release > icedtea-web-1.4
changeset 659:3405d5fc4339
Move normalizeUrlAndStripParams to UrlUtils
author | Adam Domurad <adomurad@redhat.com> |
---|---|
date | Thu, 28 Mar 2013 14:40:11 -0400 |
parents | 866020eb16cf |
children | 126a7f9465ed |
files | ChangeLog netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmation.java netx/net/sourceforge/jnlp/util/UrlUtils.java tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmationTest.java tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java |
diffstat | 5 files changed, 66 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Mar 28 12:38:52 2013 -0400 +++ b/ChangeLog Thu Mar 28 14:40:11 2013 -0400 @@ -1,3 +1,16 @@ +2013-03-28 Adam Domurad <adomurad@redhat.com> + + * 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 <jvanek@redhat.com> Added code to parse properties and to find correct configuration files
--- a/netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmation.java Thu Mar 28 12:38:52 2013 -0400 +++ b/netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmation.java Thu Mar 28 14:40:11 2013 -0400 @@ -45,6 +45,8 @@ 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 @@ 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 @@ 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");
--- a/netx/net/sourceforge/jnlp/util/UrlUtils.java Thu Mar 28 12:38:52 2013 -0400 +++ b/netx/net/sourceforge/jnlp/util/UrlUtils.java Thu Mar 28 14:40:11 2013 -0400 @@ -37,10 +37,27 @@ 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") &&
--- a/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmationTest.java Thu Mar 28 12:38:52 2013 -0400 +++ b/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmationTest.java Thu Mar 28 14:40:11 2013 -0400 @@ -36,24 +36,4 @@ 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java Thu Mar 28 14:40:11 2013 -0400 @@ -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()); + } +}