[rfc][icedtea-web] Stripping semicolon tags from jar urls
Jiri Vanek
jvanek at redhat.com
Tue Jun 4 07:34:40 PDT 2013
General comment - please strip only parts of old coverstion which are already solved or become irrelevant thanx to new code (but strip!-)
On 06/04/2013 03:22 PM, Andrew Azores wrote:
> On 06/04/2013 04:50 AM, Jiri Vanek wrote:
>> On 06/03/2013 07:06 PM, Andrew Azores wrote:
>>> Changelog:
>>>
>>> * netx/net/sourceforge/jnlp/Parser.java: added call to UrlUtils.stripSemicolon()
>>> * netx/net/sourceforge/jnlp/util/UrlUtils.java: added method stripSemicolon()
>>>
>>> * tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java: added tests for Parser.getUrl()
>>> * tests/netx/unit/net/sourceforge/jnlp/basic.jnlp: added case for ParserBasic
>>> * tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java: added tests for UrlUtils.stripSemicolon()
>>>
>>> * tests/reproducers/simple/StripSemicolons/testcases/StripSemicolonsTest.java: added reproducer for UrlUtils.stripSemicolon()
>>> * tests/reproducers/simple/StripSemicolons/srcs/StripSemicolons.java: class used in reproducer above
>>> * tests/reproducers/simple/StripSemicolons/resources/stripsemicolons.jnlp: jnlp used to reference class above
>>>
>>>
>>> Created unit tests and reproducer for this change, which has also been moved out into UrlUtils.
>> Please split by logical units, not by files.
>> In this case three patches - fix, tests, reproducr(s) (with testcase)
>>
>>
>> J.
> Hopefully this is more manageable :)
>
> I definitely need some feedback on the reproducer, I'm not sure exactly what to be doing with it and at the moment it feels like it's just duplicating the unit tests.
Unit tests are testing the code, reproducers are integration tests - they test if the code is realy used when it should be used.
An I think you ahve messed it a bit togehter :) But nvm. You have done a little bit redundant work, and individual parts are strangly merged, but the testd do not need to be thrown away.
Tahnxz for splitting it, loosk much better!
>
> Andrew A
>
>
> fix.patch
>
>
> diff --git a/netx/net/sourceforge/jnlp/Parser.java b/netx/net/sourceforge/jnlp/Parser.java
> --- a/netx/net/sourceforge/jnlp/Parser.java
> +++ b/netx/net/sourceforge/jnlp/Parser.java
> @@ -29,6 +29,7 @@ import java.util.*;
> import net.sourceforge.jnlp.UpdateDesc.Check;
> import net.sourceforge.jnlp.UpdateDesc.Policy;
> import net.sourceforge.jnlp.runtime.JNLPRuntime;
> +import net.sourceforge.jnlp.util.UrlUtils;
> import net.sourceforge.nanoxml.*;
>
> /**
> @@ -1063,9 +1064,12 @@ class Parser {
> * @throws ParseException if the JNLP file is invalid
> */
> public URL getURL(Node node, String name, URL base) throws ParseException {
> - String href = getAttribute(node, name, null);
> - if (href == null)
> + String href = UrlUtils.stripSemicolon(getAttribute(node, name, null));
> + // Remove appended semicolon "tags" (https://bugzilla.redhat.com/show_bug.cgi?id=905074)
> +
> + if (href == null) {
> return null; // so that code can throw an exception if attribute was required
> + }
eeee? ahve null chel *after* your new code some purpose? Also why the remove initialisation? I would expect :
String href = getAttribute(node, name, null);
if (href == null) {
return null; // so that code can throw an exception if attribute was required
}
// Remove appended semicolon "tags" (https://bugzilla.redhat.com/show_bug.cgi?id=905074)
String href = UrlUtils.stripSemicolon(href);
>
> try {
> if (base == null)
> diff --git a/netx/net/sourceforge/jnlp/util/UrlUtils.java b/netx/net/sourceforge/jnlp/util/UrlUtils.java
> --- a/netx/net/sourceforge/jnlp/util/UrlUtils.java
> +++ b/netx/net/sourceforge/jnlp/util/UrlUtils.java
> @@ -139,4 +139,25 @@ public class UrlUtils {
> public static File decodeUrlAsFile(URL url) {
> return new File(decodeUrlQuietly(url).getFile());
> }
> +
> + /* Strip any characters after the file extension iff there is a semicolon after the extension. */
> + public static String stripSemicolon(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;
> + }
> +
> + public static URL stripSemicolon(URL url) throws MalformedURLException {
> + return new URL(stripSemicolon(url.toString()));
> + }
> }
Those two methods above looks already ok :)
>
>
As yu have messed unittest and reproducer together, I willt try to mark hat should be what.
> reproducer.patch
>
>
> diff --git a/tests/reproducers/simple/StripSemicolons/resources/stripsemicolons.jnlp b/tests/reproducers/simple/StripSemicolons/resources/stripsemicolons.jnlp
> new file mode 100644
hmm.. this jnlp should simulate the "corrupted" run, so shouldn't there be semicolon somewhere?
> --- /dev/null
> +++ b/tests/reproducers/simple/StripSemicolons/resources/stripsemicolons.jnlp
> @@ -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="stripsemicolons.jnlp" codebase=".">
> +<information>
> +<title>stripsemicolons</title>
> +<vendor>IcedTea</vendor>
> +<homepage href="http://icedtea.classpath.org/wiki/IcedTea-Web#Testing_IcedTea-Web"/>
> +<description>stripsemicolons</description>
> +<offline/>
> +</information>
> +<resources>
> +<j2se version="1.4+"/>
Maybe here ˇ?
> +<jar href="StripSemicolons.jar"/>
> +</resources>
> +<application-desc main-class="StripSemicolons">
> +</application-desc>
> +</jnlp>
> diff --git a/tests/reproducers/simple/StripSemicolons/srcs/StripSemicolons.java b/tests/reproducers/simple/StripSemicolons/srcs/StripSemicolons.java
> new file mode 100644
> --- /dev/null
> +++ b/tests/reproducers/simple/StripSemicolons/srcs/StripSemicolons.java
> @@ -0,0 +1,45 @@
> +import net.sourceforge.jnlp.util.UrlUtils;
> +
> +/* SimpleTest2.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.
> + */
> +
> +public class StripSemicolons {
> + public static void main(String[] args) {
> + System.out.println("running");
> + for (String arg: args) System.out.println(UrlUtils.stripSemicolon(arg));
> + }
> +}
You mentioned that the ; can be used also in extensions definitions - if sou, then this jnlp is msisng, and if sou, then the code in main should check if extension was downlaoded
Also appelts are affected by this issue or not? Please provide and execute also html simulating this issue.
> + for (String arg: args) System.out.println(UrlUtils.stripSemicolon(arg));
^ this is terrible misunderstending of issue. THe reproducer must BE THE ISSUE, not execute the method which was written to help him to run. I will sent Adam to your help otherwise wi weill end up in nevereding emailing deadlock;)
> diff --git a/tests/reproducers/simple/StripSemicolons/testcases/StripSemicolonsTest.java b/tests/reproducers/simple/StripSemicolons/testcases/StripSemicolonsTest.java
> new file mode 100644
> --- /dev/null
> +++ b/tests/reproducers/simple/StripSemicolons/testcases/StripSemicolonsTest.java
> @@ -0,0 +1,83 @@
> +/* SimpleTest2Test.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.util.ArrayList;
> +import net.sourceforge.jnlp.ServerAccess;
> +import net.sourceforge.jnlp.util.UrlUtils;
> +import net.sourceforge.jnlp.annotations.KnownToFail;
> +import org.junit.Assert;
> +
> +import org.junit.Test;
> +
> +public class StripSemicolonsTest {
> +
Yaaah THIS ˇˇˇˇ
> + private static ServerAccess server = new ServerAccess();
> +
> + private static String[] testCases = {
> + "http://localhost/jar.jar;tag",
> + "http://localhost/jar;tag.jar",
> + "http://local;host/jar;tag.jar;tag1;tag2",
> + "http://zhbapssp-spsv01.bwns.ch:8080/spectrum/lib/jsafeJCEFIPS.jar;no_javaws_cheat"
> + };
> + private static String[] expectedResults = {
> + "http://localhost/jar.jar",
> + "http://localhost/jar;tag.jar",
> + "http://local;host/jar;tag.jar",
> + "http://zhbapssp-spsv01.bwns.ch:8080/spectrum/lib/jsafeJCEFIPS.jar"
> + };
^^^^^^^^^ is unittest - just one method to iterate those two arrays, against your new method.
> +
> + @Test
> + public void testStripSemicolonsLaunch() throws Exception {
> + ServerAccess.ProcessResult pr = server.executeJavawsHeadless(null, "/stripsemicolons.jnlp");
> + Assert.assertTrue("stdout should contain " + "running" + " but did not", pr.stdout.contains("running"));
Pelase use ContainsRule for this. It is not necessary here, but is good habbit in reproducers.
> + }
> +
> + @Test
> + public void testStripSemicolonsTests() throws Exception {
> + ArrayList<String> args = new ArrayList<String>();
> + args.add("-nosecurity");
> + for (String test : testCases) {
> + args.add("-arg");
> + args.add(test);
> + }
> + ServerAccess.ProcessResult pr = server.executeJavawsHeadless(args, "/stripsemicolons.jnlp");
> + for (String result : expectedResults) {
> + Assert.assertTrue("stdout should contain " + result + " but did not.", pr.stdout.contains(result));
> + }
eehhhh.. what is this??? When you mett adam in officxe, ask him :)
> + }
> +
> +}
>
>
> unit_tests.patch
>
>
> diff --git a/tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java b/tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java
> --- a/tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java
> +++ b/tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java
> @@ -37,15 +37,14 @@ exception statement from your version.
>
> package net.sourceforge.jnlp;
>
> -import java.io.ByteArrayInputStream;
> import java.io.InputStream;
> +import java.net.MalformedURLException;
> +import java.net.URL;
> import java.util.List;
> -import net.sourceforge.jnlp.runtime.CodeBaseClassLoaderTest;
> +
> import net.sourceforge.jnlp.mock.DummyJNLPFile;
>
> -import org.junit.After;
> import org.junit.Assert;
> -import org.junit.Before;
> import org.junit.BeforeClass;
> import org.junit.Test;
>
> @@ -54,6 +53,7 @@ public class ParserBasic {
>
> private static Node root;
> private static Parser parser;
> + private static int numResourceJars = 4;
>
> @BeforeClass
> public static void setUp() throws ParseException {
> @@ -222,13 +222,17 @@ public class ParserBasic {
> boolean foundNative = false;
> boolean foundEager = false;
> boolean foundLazy = false;
> + boolean foundBadlyNamed = false;
>
> JARDesc[] jars = resources.getJARs();
> - Assert.assertEquals(3, jars.length);
> + Assert.assertEquals(numResourceJars, jars.length);
> for (int i = 0; i< jars.length; i++) {
> if (jars[i].isNative()) {
> foundNative = true;
> Assert.assertEquals("http://localhost/native.jar", jars[i].getLocation().toString());
> + } else if (jars[i].isMain()) {
> + foundBadlyNamed = true;
> + Assert.assertEquals("http://localhost/semicolon.jar", jars[i].getLocation().toString());
I'm not sure if I understand pupose of this hunk
> } else if (jars[i].isEager()) {
> foundEager = true;
> Assert.assertEquals("http://localhost/eager.jar", jars[i].getLocation().toString());
> @@ -243,6 +247,7 @@ public class ParserBasic {
> Assert.assertTrue(foundNative);
> Assert.assertTrue(foundLazy);
> Assert.assertTrue(foundEager);
> + Assert.assertTrue(foundBadlyNamed);
> }
>
> @Test
> @@ -281,4 +286,48 @@ public class ParserBasic {
> Assert.assertArrayEquals(new String[] { "arg1", "arg2" }, app.getArguments());
> }
>
> + @Test
> + public void testGetUrl() throws ParseException {
> + Node resources = null;
> + for (Node child : root.getChildNodes()) {
> + if (child.getNodeName().equals("resources")) {
> + resources = child;
> + break;
> + }
> + }
> +
> + Assert.assertNotNull(resources);
> +
> + Node[] jars = new Node[numResourceJars - 1];
> + int index = 0;
> + for (Node child: resources.getChildNodes()) {
> + if (child.getNodeName().equals("jar")) {
> + jars[index] = child;
> + index++;
> + }
> + }
> +
> + for (Node jar : jars) {
> + try {
> + String url = parser.getURL(jar, "href", new URL("http://localhost")).toString();
> + String href = jar.getAttribute("href");
> + Assert.assertFalse(url.equals(""));
> + Assert.assertFalse(href.equals(""));
> +
> + int fileExtension = href.toUpperCase().lastIndexOf(".JAR");
> + if (fileExtension != -1) {
> + int semiColon = href.indexOf(';', fileExtension);
> + if (semiColon != -1) {
> + href = href.substring(0, semiColon);
> + }
> + }
> +
> + Assert.assertEquals(url,"http://localhost/" + href);
> +
> + if (url.lastIndexOf(';') != -1) Assert.assertTrue(url.lastIndexOf(';')< url.indexOf('.'));
> + } catch (MalformedURLException e) {
> + Assert.assertTrue(false);
> + }
actually even this is misty for me in context od unittests
> + }
> + }
> }
> diff --git a/tests/netx/unit/net/sourceforge/jnlp/basic.jnlp b/tests/netx/unit/net/sourceforge/jnlp/basic.jnlp
> --- a/tests/netx/unit/net/sourceforge/jnlp/basic.jnlp
> +++ b/tests/netx/unit/net/sourceforge/jnlp/basic.jnlp
> @@ -35,6 +35,7 @@
> max-heap-size='128m' />
> <jar href='eager.jar' download='eager'/>
> <jar href='lazy.jar' download='lazy'/>
> +<jar href='semicolon.jar;bad_name' main='true'/>
> <nativelib href='native.jar'/>
> <extension name='extension' version='0.1.1' href='http://extension/'/>
> <property name='key' value='value'/>
Its probably good idea to test also parser on this issue.
> diff --git a/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java b/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java
> --- a/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java
> +++ b/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java
> @@ -43,6 +43,7 @@ import static org.junit.Assert.assertFal
> import java.io.File;
> import java.net.URL;
>
> +import org.junit.Assert;
> import org.junit.Test;
>
> public class UrlUtilsTest {
> @@ -116,4 +117,26 @@ public class UrlUtilsTest {
> assertEquals(testFile, UrlUtils.decodeUrlAsFile(encodedUrl));
> }
> }
> +
> + @Test
> + public void testStripSemicolon() {
> + String simpleCodebase ="http://localhost/",
> + complexCodebase ="http://localhost/i=123?q=456¶m=test;semicolon/",
> + simpleJarName = "file.jar",
> + complexJarName = "file2.jar.pack.gz;no_javaws_cheat",
> + multiTaggedJarName = "file.jar;ignored;ignored;ignored",
> + bareJarName = "jar",
> + taggedBareJarName = "jar;ignored";
> +
> + Assert.assertEquals(simpleCodebase + simpleJarName, UrlUtils.stripSemicolon(simpleCodebase + simpleJarName));
> + Assert.assertEquals(simpleCodebase + bareJarName, UrlUtils.stripSemicolon(simpleCodebase + bareJarName));
> + Assert.assertEquals(simpleCodebase + "file2.jar.pack.gz", UrlUtils.stripSemicolon(simpleCodebase + complexJarName));
> + Assert.assertEquals(simpleCodebase + "file.jar", UrlUtils.stripSemicolon(simpleCodebase + multiTaggedJarName));
> + Assert.assertEquals(simpleCodebase + taggedBareJarName, UrlUtils.stripSemicolon(simpleCodebase + taggedBareJarName));
> + Assert.assertEquals(complexCodebase + simpleJarName, UrlUtils.stripSemicolon(complexCodebase + simpleJarName));
> + Assert.assertEquals(complexCodebase + bareJarName, UrlUtils.stripSemicolon(complexCodebase + bareJarName));
> + Assert.assertEquals(complexCodebase + "file2.jar.pack.gz", UrlUtils.stripSemicolon(complexCodebase + complexJarName));
> + Assert.assertEquals(complexCodebase + "file.jar", UrlUtils.stripSemicolon(complexCodebase + multiTaggedJarName));
> + Assert.assertEquals(complexCodebase + taggedBareJarName, UrlUtils.stripSemicolon(complexCodebase + taggedBareJarName));
This is strange. Sorry
> + }
> }
> \ No newline at end of file
> diff --git a/tests/reproducers/simple/StripSemicolons/resources/stripsemicolons.jnlp b/tests/reproducers/simple/StripSemicolons/resources/stripsemicolons.jnlp
> new file mode 100644
> --- /dev/null
> +++ b/tests/reproducers/simple/StripSemicolons/resources/stripsemicolons.jnlp
> @@ -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="stripsemicolons.jnlp" codebase=".">
> +<information>
> +<title>stripsemicolons</title>
> +<vendor>IcedTea</vendor>
> +<homepage href="http://icedtea.classpath.org/wiki/IcedTea-Web#Testing_IcedTea-Web"/>
> +<description>stripsemicolons</description>
> +<offline/>
> +</information>
> +<resources>
> +<j2se version="1.4+"/>
> +<jar href="StripSemicolons.jar"/>
> +</resources>
> +<application-desc main-class="StripSemicolons">
> +</application-desc>
> +</jnlp>
> diff --git a/tests/reproducers/simple/StripSemicolons/srcs/StripSemicolons.java b/tests/reproducers/simple/StripSemicolons/srcs/StripSemicolons.java
> new file mode 100644
> --- /dev/null
> +++ b/tests/reproducers/simple/StripSemicolons/srcs/StripSemicolons.java
> @@ -0,0 +1,45 @@
> +import net.sourceforge.jnlp.util.UrlUtils;
> +
> +/* SimpleTest2.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.
> + */
> +
> +public class StripSemicolons {
> + public static void main(String[] args) {
> + System.out.println("running");
> + for (String arg: args) System.out.println(UrlUtils.stripSemicolon(arg));
> + }
> +}
> diff --git a/tests/reproducers/simple/StripSemicolons/testcases/StripSemicolonsTest.java b/tests/reproducers/simple/StripSemicolons/testcases/StripSemicolonsTest.java
> new file mode 100644
> --- /dev/null
> +++ b/tests/reproducers/simple/StripSemicolons/testcases/StripSemicolonsTest.java
> @@ -0,0 +1,83 @@
> +/* SimpleTest2Test.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.util.ArrayList;
> +import net.sourceforge.jnlp.ServerAccess;
> +import net.sourceforge.jnlp.util.UrlUtils;
> +import net.sourceforge.jnlp.annotations.KnownToFail;
> +import org.junit.Assert;
> +
> +import org.junit.Test;
> +
> +public class StripSemicolonsTest {
> +
> + private static ServerAccess server = new ServerAccess();
> +
> + private static String[] testCases = {
> + "http://localhost/jar.jar;tag",
> + "http://localhost/jar;tag.jar",
> + "http://local;host/jar;tag.jar;tag1;tag2",
> + "http://zhbapssp-spsv01.bwns.ch:8080/spectrum/lib/jsafeJCEFIPS.jar;no_javaws_cheat"
> + };
> + private static String[] expectedResults = {
> + "http://localhost/jar.jar",
> + "http://localhost/jar;tag.jar",
> + "http://local;host/jar;tag.jar",
> + "http://zhbapssp-spsv01.bwns.ch:8080/spectrum/lib/jsafeJCEFIPS.jar"
> + };
> +
> + @Test
> + public void testStripSemicolonsLaunch() throws Exception {
> + ServerAccess.ProcessResult pr = server.executeJavawsHeadless(null, "/stripsemicolons.jnlp");
> + Assert.assertTrue("stdout should contain " + "running" + " but did not", pr.stdout.contains("running"));
> + }
> +
> + @Test
> + public void testStripSemicolonsTests() throws Exception {
> + ArrayList<String> args = new ArrayList<String>();
> + args.add("-nosecurity");
> + for (String test : testCases) {
> + args.add("-arg");
> + args.add(test);
> + }
> + ServerAccess.ProcessResult pr = server.executeJavawsHeadless(args, "/stripsemicolons.jnlp");
> + for (String result : expectedResults) {
> + Assert.assertTrue("stdout should contain " + result + " but did not.", pr.stdout.contains(result));
> + }
> + }
> +
This was already here, wasn'nt it?
> +}
Genral comments to test:
In your case you will add two or three testmethods to unittest files:
- tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java:
added tests for Parser.getUrl() - correct, this will iterate through your testCase and comapre with expectedessults in assserEwuals. Nice test
- tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java:
This is bonus test, and should be muchhless complicated then you started it - You wil prvide jnlp file (like * tests/netx/unit/net/sourceforge/jnlp/basic.jnlp: added case for ParserBasic) s separate file or or as string (and s inputstream) for parser. No localhosts here!
Then yo will tests if parser returns correct urls.
Reproducer:
You must prepare one or two "semicolon corrupted" html and one or two "semicolon corrupted" jnlp file.
If you will try to test also extension with semicolon, you shoud tests taht extension was loaded in your (in src) main class. Otehrwise some "app finished" stdout is enough
you shoud use closing listener for applets
your testcase is then executing the html and jnlp files, and is checking the output. By this way you will find that your fix is really workling.
I'm sending adam to look over your shoulder:)
Good luck!
J
More information about the distro-pkg-dev
mailing list