aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanesh Dadachanji <[email protected]>2012-06-04 13:35:25 -0400
committerDanesh Dadachanji <[email protected]>2012-06-04 13:35:25 -0400
commitb6a2b55190c36fd9b42fdb3c61e8ff0e06776263 (patch)
tree194690c969f4375fa9e690ccb81446944e2fda3f
parent9a31bacf619e4f9ffa32fb6c1e348079db2d417c (diff)
Handle absolute paths passed into jnlp_href's value.
-rw-r--r--ChangeLog14
-rw-r--r--netx/net/sourceforge/jnlp/JNLPCreator.java35
-rw-r--r--netx/net/sourceforge/jnlp/PluginBridge.java22
-rw-r--r--tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java99
4 files changed, 165 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index aca6eea..111bbe6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2012-06-04 Danesh Dadachanji <[email protected]>
+
+ Fix to handle absolute paths passed into jnlp_href's value.
+ * netx/net/sourceforge/jnlp/PluginBridge.java
+ (PluginBridge): Uses context of codebase to evaluate jnlp_href's value.
+ Uses JNLPCreator's create method to make new JNLPFile variables.
+ New constructor that wraps around the original one, creating a new
+ JNLPCreator to use.
+ * netx/net/sourceforge/jnlp/JNLPCreator.java: New strategy pattern class
+ to be used to wrap around the creation of a JNLPFile. Replace this creator
+ when unit testing to skip running parsing code.
+ * tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java:
+ New class to unit test getEvaluatedJNLPHref.
+
2012-06-04 Adam Domurad <[email protected]>
Added self to AUTHORS.
diff --git a/netx/net/sourceforge/jnlp/JNLPCreator.java b/netx/net/sourceforge/jnlp/JNLPCreator.java
new file mode 100644
index 0000000..ca1b94b
--- /dev/null
+++ b/netx/net/sourceforge/jnlp/JNLPCreator.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2012 Red Hat, Inc.
+ * This file is part of IcedTea, http://icedtea.classpath.org
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package net.sourceforge.jnlp;
+
+import java.io.IOException;
+import java.net.URL;
+
+import net.sourceforge.jnlp.cache.UpdatePolicy;
+
+public class JNLPCreator {
+ public JNLPFile create(URL location, Version version, boolean strict,
+ UpdatePolicy policy, URL forceCodebase) throws IOException, ParseException {
+ return new JNLPFile(location, version, strict, policy, forceCodebase);
+ }
+}
diff --git a/netx/net/sourceforge/jnlp/PluginBridge.java b/netx/net/sourceforge/jnlp/PluginBridge.java
index 273b213..d241f7c 100644
--- a/netx/net/sourceforge/jnlp/PluginBridge.java
+++ b/netx/net/sourceforge/jnlp/PluginBridge.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2007 Red Hat, Inc.
+ * Copyright 2012 Red Hat, Inc.
* This file is part of IcedTea, http://icedtea.classpath.org
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -46,10 +46,20 @@ public class PluginBridge extends JNLPFile {
private boolean codeBaseLookup;
private boolean useJNLPHref;
+ /**
+ * Creates a new PluginBridge using a default JNLPCreator.
+ */
public PluginBridge(URL codebase, URL documentBase, String jar, String main,
int width, int height, Hashtable<String, String> atts,
String uKey)
throws Exception {
+ this(codebase, documentBase, jar, main, width, height, atts, uKey, new JNLPCreator());
+ }
+
+ public PluginBridge(URL codebase, URL documentBase, String jar, String main,
+ int width, int height, Hashtable<String, String> atts,
+ String uKey, JNLPCreator jnlpCreator)
+ throws Exception {
specVersion = new Version("1.0");
fileVersion = new Version("1.1");
this.codeBase = codebase;
@@ -59,8 +69,10 @@ public class PluginBridge extends JNLPFile {
if (atts.containsKey("jnlp_href")) {
useJNLPHref = true;
try {
- URL jnlp = new URL(codeBase.toExternalForm() + atts.get("jnlp_href"));
- JNLPFile jnlpFile = new JNLPFile(jnlp, null, false, JNLPRuntime.getDefaultUpdatePolicy(), this.codeBase);
+ // Use codeBase as the context for the URL. If jnlp_href's
+ // value is a complete URL, it will replace codeBase's context.
+ URL jnlp = new URL(codeBase, atts.get("jnlp_href"));
+ JNLPFile jnlpFile = jnlpCreator.create(jnlp, null, false, JNLPRuntime.getDefaultUpdatePolicy(), codeBase);
Map<String, String> jnlpParams = jnlpFile.getApplet().getParameters();
info = jnlpFile.info;
@@ -76,8 +88,8 @@ public class PluginBridge extends JNLPFile {
} catch (MalformedURLException e) {
// Don't fail because we cannot get the jnlp file. Parameters are optional not required.
// it is the site developer who should ensure that file exist.
- System.err.println("Unable to get JNLP file at: " + codeBase.toExternalForm()
- + atts.get("jnlp_href"));
+ System.err.println("Unable to get JNLP file at: " + atts.get("jnlp_href")
+ + " with context of URL as: " + codeBase.toExternalForm());
}
} else {
// Should we populate this list with applet attribute tags?
diff --git a/tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java b/tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java
new file mode 100644
index 0000000..c006fef
--- /dev/null
+++ b/tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2012 Red Hat, Inc.
+ * This file is part of IcedTea, http://icedtea.classpath.org
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package net.sourceforge.jnlp;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Hashtable;
+
+import net.sourceforge.jnlp.cache.UpdatePolicy;
+
+import org.junit.Test;
+
+public class PluginBridgeTest {
+ private class MockJNLPCreator extends JNLPCreator {
+
+ private URL JNLPHref;
+
+ public URL getJNLPHref() {
+ return JNLPHref;
+ }
+
+ public JNLPFile create(URL location, Version version, boolean strict,
+ UpdatePolicy policy, URL forceCodebase) throws IOException, ParseException {
+ JNLPHref = location;
+ return new MockJNLPFile();
+ }
+ }
+
+ private class MockJNLPFile extends JNLPFile {
+ public AppletDesc getApplet() {
+ return new AppletDesc(null, null, null, 0, 0, new HashMap<String, String>());
+ }
+
+ public ResourcesDesc getResources() {
+ return new ResourcesDesc(null, null, null, null);
+ }
+ }
+
+ @Test
+ public void testAbsoluteJNLPHref() throws MalformedURLException, Exception {
+ URL codeBase = new URL("http://undesired.absolute.codebase.com");
+ String absoluteLocation = "http://absolute.href.com/test.jnlp";
+ Hashtable<String, String> atts = new Hashtable<String, String>();
+ atts.put("jnlp_href", absoluteLocation);
+ MockJNLPCreator mockCreator = new MockJNLPCreator();
+ PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, atts, "", mockCreator);
+ assertEquals(absoluteLocation, mockCreator.getJNLPHref().toExternalForm());
+ }
+
+ @Test
+ public void testRelativeJNLPHref() throws MalformedURLException, Exception {
+ URL codeBase = new URL("http://desired.absolute.codebase.com/");
+ String relativeLocation = "sub/dir/test.jnlp";
+ Hashtable<String, String> atts = new Hashtable<String, String>();
+ atts.put("jnlp_href", relativeLocation);
+ MockJNLPCreator mockCreator = new MockJNLPCreator();
+ PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, atts, "", mockCreator);
+ assertEquals(codeBase.toExternalForm() + relativeLocation,
+ mockCreator.getJNLPHref().toExternalForm());
+ }
+
+ @Test
+ public void testNoSubDirInCodeBase() throws MalformedURLException, Exception {
+ String desiredDomain = "http://desired.absolute.codebase.com";
+ URL codeBase = new URL(desiredDomain + "/undesired/sub/dir");
+ String relativeLocation = "/app/test/test.jnlp";
+ Hashtable<String, String> atts = new Hashtable<String, String>();
+ atts.put("jnlp_href", relativeLocation);
+ MockJNLPCreator mockCreator = new MockJNLPCreator();
+ PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, atts, "", mockCreator);
+ assertEquals(desiredDomain + relativeLocation,
+ mockCreator.getJNLPHref().toExternalForm());
+ }
+
+} \ No newline at end of file