diff options
8 files changed, 307 insertions, 0 deletions
@@ -1,3 +1,20 @@ +2012-03-16 Danesh Dadachanji <[email protected]> + + Applications using JNLP files without a title or vendor section + still run, despite them being required elements. + * netx/net/sourceforge/jnlp/Parser.java: + (getInformationDesc): If title or vendor are not found in info, + a new ParseException is thrown. + * netx/net/sourceforge/jnlp/resources/Messages.properties: + Added PNoTitleElement and PNoVendorElement + * tests/jnlp_tests/simple/InformationTitleVendorParser/resources/InformationParser.jnlp, + * tests/jnlp_tests/simple/InformationTitleVendorParser/resources/TitleParser.jnlp, + * tests/jnlp_tests/simple/InformationTitleVendorParser/resources/TitleVendorParser.jnlp, + * tests/jnlp_tests/simple/InformationTitleVendorParser/resources/VendorParser.jnlp, + * tests/jnlp_tests/simple/InformationTitleVendorParser/testcases/TitleVendorParserTest.java: + New test that runs JNLPs in a combination of missing information, title + and vendor tags, checking for the appropriate exceptions. + 2012-03-14 Deepak Bhole <[email protected]> Omair Majid <[email protected]> diff --git a/netx/net/sourceforge/jnlp/Parser.java b/netx/net/sourceforge/jnlp/Parser.java index 917cad2..a823562 100644 --- a/netx/net/sourceforge/jnlp/Parser.java +++ b/netx/net/sourceforge/jnlp/Parser.java @@ -504,6 +504,11 @@ class Parser { child = child.getNextSibling(); } + if (info.getTitle() == null || info.getTitle().trim().isEmpty()) + throw new ParseException(R("PNoTitleElement")); + if (info.getVendor() == null || info.getVendor().trim().isEmpty()) + throw new ParseException(R("PNoVendorElement")); + return info; } diff --git a/netx/net/sourceforge/jnlp/resources/Messages.properties b/netx/net/sourceforge/jnlp/resources/Messages.properties index f1187e5..a0801b6 100644 --- a/netx/net/sourceforge/jnlp/resources/Messages.properties +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties @@ -105,6 +105,8 @@ PInnerJ2SE=j2se element cannot be specified within a j2se element. PTwoMains=Duplicate main JAR defined in a resources element (there can be only one)
PNativeHasMain=Cannot specify main attribute on native JARs.
PNoInfoElement=No information section defined
+PNoTitleElement=The title section has not been defined in the JNLP file.
+PNoVendorElement=The vendor section has not been defined in the JNLP file.
PTwoDescriptions=Duplicate description of kind {0}
PSharing=Element "sharing-allowed" is illegal in a standard JNLP file
PTwoSecurity=Only one security element allowed per JNLPFile.
diff --git a/tests/jnlp_tests/simple/InformationTitleVendorParser/resources/InformationParser.jnlp b/tests/jnlp_tests/simple/InformationTitleVendorParser/resources/InformationParser.jnlp new file mode 100644 index 0000000..aabd685 --- /dev/null +++ b/tests/jnlp_tests/simple/InformationTitleVendorParser/resources/InformationParser.jnlp @@ -0,0 +1,47 @@ +<!-- + +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="InformationParser.jnlp" codebase="."> + <!-- information tag missing --> + <resources> + <j2se version="1.4+"/> + <jar href="simpletest1.jar"/> + </resources> + <application-desc main-class="TitleVendorParser"> + </application-desc> +</jnlp> diff --git a/tests/jnlp_tests/simple/InformationTitleVendorParser/resources/TitleParser.jnlp b/tests/jnlp_tests/simple/InformationTitleVendorParser/resources/TitleParser.jnlp new file mode 100644 index 0000000..64a7e28 --- /dev/null +++ b/tests/jnlp_tests/simple/InformationTitleVendorParser/resources/TitleParser.jnlp @@ -0,0 +1,52 @@ +<!-- + +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="TitleParser.jnlp" codebase="."> + <information> + <vendor>IcedTea</vendor> + <homepage href="http://jnlp.sourceforge.net/netx/"/> + <description>Title tag missing</description> + <offline/> + </information> + <resources> + <j2se version="1.4+"/> + <jar href="simpletest1.jar"/> + </resources> + <application-desc main-class="TitleVendorParser"> + </application-desc> +</jnlp> diff --git a/tests/jnlp_tests/simple/InformationTitleVendorParser/resources/TitleVendorParser.jnlp b/tests/jnlp_tests/simple/InformationTitleVendorParser/resources/TitleVendorParser.jnlp new file mode 100644 index 0000000..faf52cb --- /dev/null +++ b/tests/jnlp_tests/simple/InformationTitleVendorParser/resources/TitleVendorParser.jnlp @@ -0,0 +1,51 @@ +<!-- + +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="TitleVendorParser.jnlp" codebase="."> + <information> + <homepage href="http://jnlp.sourceforge.net/netx/"/> + <description>Title/Vendor tags missing</description> + <offline/> + </information> + <resources> + <j2se version="1.4+"/> + <jar href="simpletest1.jar"/> + </resources> + <application-desc main-class="TitleVendorParser"> + </application-desc> +</jnlp> diff --git a/tests/jnlp_tests/simple/InformationTitleVendorParser/resources/VendorParser.jnlp b/tests/jnlp_tests/simple/InformationTitleVendorParser/resources/VendorParser.jnlp new file mode 100644 index 0000000..e201bf0 --- /dev/null +++ b/tests/jnlp_tests/simple/InformationTitleVendorParser/resources/VendorParser.jnlp @@ -0,0 +1,52 @@ +<!-- + +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="VendorParser.jnlp" codebase="."> + <information> + <title>VendorParser</title> + <homepage href="http://jnlp.sourceforge.net/netx/"/> + <description>Vendor tag missing</description> + <offline/> + </information> + <resources> + <j2se version="1.4+"/> + <jar href="simpletest1.jar"/> + </resources> + <application-desc main-class="TitleVendorParser"> + </application-desc> +</jnlp> diff --git a/tests/jnlp_tests/simple/InformationTitleVendorParser/testcases/InformationTitleVendorParserTest.java b/tests/jnlp_tests/simple/InformationTitleVendorParser/testcases/InformationTitleVendorParserTest.java new file mode 100644 index 0000000..c34bdd3 --- /dev/null +++ b/tests/jnlp_tests/simple/InformationTitleVendorParser/testcases/InformationTitleVendorParserTest.java @@ -0,0 +1,81 @@ +/* InformationTitleVendorParserTest.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.ServerAccess; +import org.junit.Assert; +import org.junit.Test; + +public class InformationTitleVendorParserTest { + + private static ServerAccess server = new ServerAccess(); + + public void runTest(String jnlpName, String exceptionMessage) throws Exception { + System.out.println("connecting InformationTitleVendorParser request, testing " + jnlpName); + System.err.println("connecting InformationTitleVendorParser request, testing " + jnlpName); + ServerAccess.ProcessResult pr=server.executeJavawsHeadless(null,"/" + jnlpName + ".jnlp"); + System.out.println(pr.stdout); + System.err.println(pr.stderr); + String s1 = "Good simple javaws exapmle"; + Assert.assertFalse("test" + jnlpName + " stdout should not contain " + s1 + " but did.", pr.stdout.contains(s1)); + // Looking for "Could not read or parse the JNLP file. (${DESCRIPTION})" + String s2 = "(?s).*Could not read or parse the JNLP file.{0,5}" + exceptionMessage + "(?s).*"; + Assert.assertTrue("testForTitle stderr should match " + s2 + " but did not.", pr.stderr.matches(s2)); + Assert.assertFalse(pr.wasTerminated); + Assert.assertEquals((Integer)0, pr.returnValue); + } + + @Test + public void testInformationeParser() throws Exception { + runTest("InformationParser", "No information section defined"); + } + + @Test + public void testTitleParser() throws Exception { + runTest("TitleParser", "The title section has not been defined in the JNLP file."); + } + @Test + public void testVendorParser() throws Exception { + runTest("VendorParser", "The vendor section has not been defined in the JNLP file."); + } + + @Test + public void testTitleVendorParser() throws Exception { + // Note that the title message missing causes an immediate exception, regardless of Vendor. + runTest("TitleVendorParser", "The title section has not been defined in the JNLP file."); + } +} |