changeset 749:1a327a09262e

Handled semicolon in internal server (with reproducers)
author Jiri Vanek <jvanek@redhat.com>
date Mon, 10 Jun 2013 13:22:53 +0200
parents e8341834febd
children fa6a80c73e0d
files ChangeLog tests/reproducers/simple/StripHttpPathParams/resources/StripHttpPathParams.html tests/reproducers/simple/StripHttpPathParams/resources/StripHttpPathParams.jnlp tests/reproducers/simple/StripHttpPathParams/srcs/StripHttpPathParams.java tests/reproducers/simple/StripHttpPathParams/testcases/StripHttpPathParamsTest.java tests/test-extensions-tests/net/sourceforge/jnlp/ServerAccessTest.java tests/test-extensions/net/sourceforge/jnlp/TinyHttpdImpl.java
diffstat 7 files changed, 290 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Jun 06 17:07:28 2013 +0200
+++ b/ChangeLog	Mon Jun 10 13:22:53 2013 +0200
@@ -1,3 +1,21 @@
+2013-06-06  Jiri Vanek  <jvanek@redhat.com>
+        Andrew Azores  <aazores@redhat.com>
+
+	Handled semicolon in internal server
+	* tests/test-extensions/net/sourceforge/jnlp/TinyHttpdImpl.java:
+	added stripHttpPathParams method to remove semicolon-delimited "tags"
+	from end of JAR URLs
+	* tests/test-extensions-tests/net/sourceforge/jnlp/ServerAccessTest.java:
+	added test case for new method in TinyHttpdImpl
+	* tests/reproducers/simple/StripHttpPathParams/resources/StripHttpPathParams.html:
+	browser-launched applet test case for reproducer
+	* tests/reproducers/simple/StripHttpPathParams/resources/StripHttpPathParams.jnlp:
+	JNLP test case for reproducer
+	* tests/reproducers/simple/StripHttpPathParams/srcs/StripHttpPathParams.java:
+	reproducer
+	* tests/reproducers/simple/StripHttpPathParams/testcases/StripHttpPathParamsTest.java: 
+	Testcase to above reproducer
+
 2013-06-06  Jiri Vanek  <jvanek@redhat.com>
 
 	Made all tests running wit junit4.10 and higher
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/simple/StripHttpPathParams/resources/StripHttpPathParams.html	Mon Jun 10 13:22:53 2013 +0200
@@ -0,0 +1,48 @@
+<!--
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+IcedTea 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 for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+
+ -->
+<html>
+  <head></head>
+  <body>
+    <applet code="StripHttpPathParams.class"
+            archive="StripHttpPathParams.jar;foo_bar"
+            codebase="."
+            width="800"
+            height="600">
+    </applet>
+  </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/simple/StripHttpPathParams/resources/StripHttpPathParams.jnlp	Mon Jun 10 13:22:53 2013 +0200
@@ -0,0 +1,53 @@
+<!--
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+IcedTea 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 for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+
+ -->
+<?xml version="1.0" encoding="utf-8"?>
+<jnlp spec="1.0" href="StripHttpPathParams.jnlp" codebase=".">
+  <information>
+    <title>StripHttpPathParams</title>
+    <vendor>IcedTea</vendor>
+    <homepage href="http://icedtea.classpath.org/wiki/IcedTea-Web#Testing_IcedTea-Web"/>
+    <description>Remove HTTP Path Parameters from JAR URLs</description>
+    <offline/>
+  </information>
+  <resources>
+    <j2se version="1.4+"/>
+    <jar href="StripHttpPathParams.jar;foo_bar"/>
+  </resources>
+  <application-desc main-class="StripHttpPathParams">
+  </application-desc>
+</jnlp>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/simple/StripHttpPathParams/srcs/StripHttpPathParams.java	Mon Jun 10 13:22:53 2013 +0200
@@ -0,0 +1,51 @@
+/* StripHttpPathParams.java
+Copyright (C) 2011 Red Hat, Inc.
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 2.
+
+IcedTea 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 for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+ */
+
+import java.applet.Applet;
+
+public class StripHttpPathParams extends Applet {
+	private static final String appletCloseString = "*** APPLET FINISHED ***";
+	
+	public static void main(String[] args)  {
+		System.out.println("running");
+	}
+
+	@Override
+	public void init() {
+		System.out.println(appletCloseString);
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/simple/StripHttpPathParams/testcases/StripHttpPathParamsTest.java	Mon Jun 10 13:22:53 2013 +0200
@@ -0,0 +1,68 @@
+/* StripHttpPathParamsTest.java
+Copyright (C) 2011 Red Hat, Inc.
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 2.
+
+IcedTea 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 for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+ */
+
+import net.sourceforge.jnlp.ProcessResult;
+import net.sourceforge.jnlp.ServerAccess.AutoClose;
+import net.sourceforge.jnlp.annotations.KnownToFail;
+import net.sourceforge.jnlp.annotations.NeedsDisplay;
+import net.sourceforge.jnlp.annotations.TestInBrowsers;
+import net.sourceforge.jnlp.browsertesting.BrowserTest;
+import net.sourceforge.jnlp.browsertesting.Browsers;
+import net.sourceforge.jnlp.closinglisteners.AutoOkClosingListener;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class StripHttpPathParamsTest extends BrowserTest {
+
+	private static final String appletCloseString = AutoOkClosingListener.MAGICAL_OK_CLOSING_STRING; 
+	
+	@Test
+	public void testStripHttpPathParamsLaunch() throws Exception {
+		ProcessResult pr = server.executeJavawsHeadless("/StripHttpPathParams.jnlp");
+		Assert.assertTrue("stdout should contain \"running\" but did not", pr.stdout.contains("running"));	
+	}
+
+	@NeedsDisplay
+	@Test
+	@TestInBrowsers(testIn={Browsers.one})
+	public void testStripHttpPathParamsApplet() throws Exception {
+		ProcessResult pr = server.executeBrowser("/StripHttpPathParams.html", AutoClose.CLOSE_ON_BOTH);
+		Assert.assertTrue("stdout should contain " + appletCloseString + " but did not", pr.stdout.contains(appletCloseString));
+	}
+
+}
--- a/tests/test-extensions-tests/net/sourceforge/jnlp/ServerAccessTest.java	Thu Jun 06 17:07:28 2013 +0200
+++ b/tests/test-extensions-tests/net/sourceforge/jnlp/ServerAccessTest.java	Mon Jun 10 13:22:53 2013 +0200
@@ -217,6 +217,34 @@
         Assert.assertArrayEquals(b2, bb[1]);
         Assert.assertArrayEquals(b3, bb[2]);
     }
+    
+    @Test
+    public void stripHttpPathParamTest() {
+    	String[] testBaseUrls = {
+    			"http://foo.com/bar",
+    			"localhost:8080",
+    			"https://bar.co.uk/site;para/baz?u=param1&v=param2"
+    	};
+
+    	String[] testJarNames = {
+    			"jar",
+    			"foo.jar",
+    			"bar;baz.jar",
+    			"nom.jar;",
+    			"rhat.jar.pack.gz;tag"
+    	};
+
+    	for (String url : testBaseUrls) {
+    		for (String jar : testJarNames) {
+    			String newUrl = TinyHttpdImpl.stripHttpPathParams(url),
+    					newJar = TinyHttpdImpl.stripHttpPathParams(jar),
+    					path = newUrl + "/" + newJar;
+    			Assert.assertTrue("Base URL should not have been modified: " + url + " => " + newUrl, newUrl.equals(url));
+    			Assert.assertTrue("JAR name should not be altered other than removing path param: " + jar + " => " + newJar, jar.startsWith(newJar));
+    			Assert.assertTrue("New path should be a substring of old path: " + path + " => " + url + "/" + jar, (url + "/" + jar).startsWith(path));
+    		}
+    	}
+    }
 
     private void printArrays(byte[][] bb) {
         System.out.println("[][] l=" + bb.length);
--- a/tests/test-extensions/net/sourceforge/jnlp/TinyHttpdImpl.java	Thu Jun 06 17:07:28 2013 +0200
+++ b/tests/test-extensions/net/sourceforge/jnlp/TinyHttpdImpl.java	Mon Jun 10 13:22:53 2013 +0200
@@ -127,6 +127,7 @@
                         p = URLDecoder.decode(p, "UTF-8");
                         p = p.replaceAll("\\?.*", "");
                         p = (".".concat((p.endsWith("/")) ? p.concat("index.html") : p)).replace('/', File.separatorChar);
+                        p = stripHttpPathParams(p);
                         ServerAccess.logNoReprint("Serving: " + p);
                         File pp = new File(dir, p);
                         int l = (int) pp.length();
@@ -203,4 +204,27 @@
         }
         return array;
     }
+    
+    /**
+     * This function removes the HTTP Path Parameter from a given JAR URL, assuming that the
+     * path param delimiter is a semicolon
+     * @param url - the URL from which to remove the path parameter
+     * @return the URL with the path parameter removed
+     */
+    public static String stripHttpPathParams(String url) {
+    	if (url == null) {
+    		return null;
+    	}
+    	
+    	// If JNLP specifies JAR URL with .JAR extension (as it should), then look for any semicolons
+    	// after this position. If one is found, remove it and any following characters.
+    	int fileExtension = url.toUpperCase().lastIndexOf(".JAR");
+    	if (fileExtension != -1) {
+    		int firstSemiColon = url.indexOf(';', fileExtension);
+    		if (firstSemiColon != -1) {    			
+    			url = url.substring(0, firstSemiColon);
+    		}
+    	}
+    	return url;
+    }
 }