diff options
11 files changed, 290 insertions, 143 deletions
@@ -1,3 +1,35 @@ +2013-04-26 Jiri Vanek <[email protected]> + + Silenced unittests + * tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageImplTest.java: and + * tests/netx/unit/sun/applet/PluginAppletViewerTest.java: + System.out.println replaced by ServerAccess.logOutputReprint + +2013-04-26 Jiri Vanek <[email protected]> + + Fixed compilation under jdk6 + * netx/net/sourceforge/jnlp/util/JarFile.java: + is now implementing Closeable + +2013-04-26 Jiri Vanek <[email protected]> + + Fixed regressed unittest and "cause" + * /netx/net/sourceforge/jnlp/NullJnlpFileException.java: + fixed header + * netx/net/sourceforge/jnlp/SecurityDesc.java: (SecurityDesc) is now + throwing NullJnlpFileException in case of null jnlp file. + * tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java: is now using + correct DummyJnlpFile + * tests/netx/unit/net/sourceforge/jnlp/SecurityDescTest.java: new testfile. + (testNotNullJnlpFile) (testNullJnlpFile) testing the behavior for null + jnlp file and for existing jnlpfile. + * tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java: + (DummyJnlpFile) extracted to test-extensions and have removed incorrect have security + (testNullFileSecurityDescApplet) and (testNullFileSecurityDesc) is now expecting + NullJnlpFileException instead of results + * tests/test-extensions/net/sourceforge/jnlp/mock/DummyJNLPFile.java: new + reusable dummy jnlp file + 2013-04-25 Adam Domurad <[email protected]> Add accidentally not included files from "Tests & test extensions for diff --git a/netx/net/sourceforge/jnlp/NullJnlpFileException.java b/netx/net/sourceforge/jnlp/NullJnlpFileException.java index 9c67f61..58c4d87 100644 --- a/netx/net/sourceforge/jnlp/NullJnlpFileException.java +++ b/netx/net/sourceforge/jnlp/NullJnlpFileException.java @@ -1,14 +1,42 @@ package net.sourceforge.jnlp; -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ +/* +Copyright (C) 2012 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. -/** - * - * @author jvanek +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 NullJnlpFileException extends NullPointerException { public NullJnlpFileException() { diff --git a/netx/net/sourceforge/jnlp/SecurityDesc.java b/netx/net/sourceforge/jnlp/SecurityDesc.java index 927917a..51b58bb 100644 --- a/netx/net/sourceforge/jnlp/SecurityDesc.java +++ b/netx/net/sourceforge/jnlp/SecurityDesc.java @@ -149,6 +149,9 @@ public class SecurityDesc { * @param downloadHost the download host (can always connect to) */ public SecurityDesc(JNLPFile file, Object type, String downloadHost) { + if (file == null) { + throw new NullJnlpFileException(); + } this.file = file; this.type = type; this.downloadHost = downloadHost; diff --git a/netx/net/sourceforge/jnlp/util/JarFile.java b/netx/net/sourceforge/jnlp/util/JarFile.java index 8eee518..f90cba3 100644 --- a/netx/net/sourceforge/jnlp/util/JarFile.java +++ b/netx/net/sourceforge/jnlp/util/JarFile.java @@ -36,14 +36,16 @@ exception statement from your version. */ package net.sourceforge.jnlp.util; +import java.io.Closeable; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.util.zip.ZipFile; import net.sourceforge.jnlp.runtime.JNLPRuntime; -public class JarFile extends java.util.jar.JarFile { +//in jdk6 java.util.jar.JarFile is not Closeable - fixing +//overwritening class can add duplicate occurence of interface so this should be perfectly safe +public class JarFile extends java.util.jar.JarFile implements Closeable{ public JarFile(String name) throws IOException { super(name); diff --git a/netx/net/sourceforge/jnlp/util/StreamUtils.java b/netx/net/sourceforge/jnlp/util/StreamUtils.java index 7dd7a92..6692d1c 100644 --- a/netx/net/sourceforge/jnlp/util/StreamUtils.java +++ b/netx/net/sourceforge/jnlp/util/StreamUtils.java @@ -73,8 +73,8 @@ public class StreamUtils { } } } - - + + public static String readStreamAsString(InputStream stream) throws IOException { InputStreamReader is = new InputStreamReader(stream); StringBuilder sb = new StringBuilder(); diff --git a/tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java b/tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java index 5fe6764..e1d009d 100644 --- a/tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java +++ b/tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java @@ -40,6 +40,8 @@ package net.sourceforge.jnlp; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.List; +import net.sourceforge.jnlp.runtime.CodeBaseClassLoaderTest; +import net.sourceforge.jnlp.mock.DummyJNLPFile; import org.junit.After; import org.junit.Assert; @@ -61,7 +63,7 @@ public class ParserBasic { } InputStream jnlpStream = cl.getResourceAsStream("net/sourceforge/jnlp/basic.jnlp"); root = Parser.getRootNode(jnlpStream); - parser = new Parser(null, null, root, false, false); + parser = new Parser(new DummyJNLPFile(), null, root, false, false); } @Test diff --git a/tests/netx/unit/net/sourceforge/jnlp/SecurityDescTest.java b/tests/netx/unit/net/sourceforge/jnlp/SecurityDescTest.java new file mode 100644 index 0000000..88a7046 --- /dev/null +++ b/tests/netx/unit/net/sourceforge/jnlp/SecurityDescTest.java @@ -0,0 +1,70 @@ +/* +Copyright (C) 2012 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. + */ +package net.sourceforge.jnlp; + +import net.sourceforge.jnlp.mock.DummyJNLPFile; +import org.junit.Assert; +import org.junit.Test; + +public class SecurityDescTest { + + @Test + public void testNotNullJnlpFile() { + Throwable t = null; + try { + SecurityDesc securityDesc = new SecurityDesc(new DummyJNLPFile(), SecurityDesc.SANDBOX_PERMISSIONS, "hey!"); + } catch (Exception ex) { + t = ex; + } + Assert.assertNull("securityDesc should not throw exception", t); + + + } + + @Test + public void testNullJnlpFile() { + Exception ex = null; + try { + SecurityDesc securityDesc = new SecurityDesc(null, SecurityDesc.SANDBOX_PERMISSIONS, "hey!"); + } catch (Exception eex) { + ex = eex; + } + Assert.assertNotNull("Exception should not be null", ex); + Assert.assertTrue("Exception should be " + NullJnlpFileException.class.getName(), ex instanceof NullJnlpFileException); + + } +} diff --git a/tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java b/tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java index 726cc79..ea8a230 100644 --- a/tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java +++ b/tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java @@ -1,41 +1,42 @@ /* CodeBaseClassLoaderTest.java -Copyright (C) 2012 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. + Copyright (C) 2012 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. */ package net.sourceforge.jnlp.runtime; +import net.sourceforge.jnlp.mock.DummyJNLPFile; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -47,6 +48,7 @@ import net.sourceforge.jnlp.JNLPFile; import net.sourceforge.jnlp.NullJnlpFileException; import net.sourceforge.jnlp.ResourcesDesc; import net.sourceforge.jnlp.SecurityDesc; +import net.sourceforge.jnlp.SecurityDescTest; import net.sourceforge.jnlp.ServerAccess; import net.sourceforge.jnlp.runtime.JNLPClassLoader.CodeBaseClassLoader; import net.sourceforge.jnlp.annotations.Bug; @@ -58,45 +60,6 @@ import org.junit.Test; public class CodeBaseClassLoaderTest { - private static final URL JAR_URL; - private static final URL CODEBASE_URL; - - static { - try { - JAR_URL = new URL("http://icedtea.classpath.org/netx/about.jar"); - CODEBASE_URL = new URL("http://icedtea.classpath.org/netx/"); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - private class DummyJNLPFile extends JNLPFile { - - final boolean haveSecurity; - - public DummyJNLPFile(boolean haveSecurity) { - this.haveSecurity = haveSecurity; - } - - @Override - public ResourcesDesc getResources() { - return new ResourcesDesc(null, new Locale[0], new String[0], new String[0]); - } - - @Override - public URL getCodeBase() { - return CODEBASE_URL; - } - - @Override - public SecurityDesc getSecurity() { - if (haveSecurity) { - return new SecurityDesc(this, SecurityDesc.SANDBOX_PERMISSIONS, null); - } else { - return new SecurityDesc(null, SecurityDesc.SANDBOX_PERMISSIONS, null); - } - } - }; private static final String isWSA = "isWebstartApplication"; static void setStaticField(Field field, Object newValue) throws Exception { @@ -159,10 +122,10 @@ public class CodeBaseClassLoaderTest { } public void testResourceCaching(String r, boolean shouldExists) throws Exception { - JNLPFile dummyJnlpFile = new DummyJNLPFile(true); + JNLPFile dummyJnlpFile = new DummyJNLPFile(); JNLPClassLoader parent = new JNLPClassLoader(dummyJnlpFile, null); - CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[]{JAR_URL, CODEBASE_URL}, parent); + CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[]{DummyJNLPFile.JAR_URL, DummyJNLPFile.CODEBASE_URL}, parent); int level = 10; if (shouldExists) { @@ -228,19 +191,18 @@ public class CodeBaseClassLoaderTest { } public void testParentClassLoaderIsAskedForClasses() throws Exception { - JNLPFile dummyJnlpFile = new DummyJNLPFile(true); + JNLPFile dummyJnlpFile = new DummyJNLPFile(); final boolean[] parentWasInvoked = new boolean[1]; JNLPClassLoader parent = new JNLPClassLoader(dummyJnlpFile, null) { - @Override protected Class<?> findClass(String name) throws ClassNotFoundException { parentWasInvoked[0] = true; throw new ClassNotFoundException(name); } }; - CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[]{JAR_URL, CODEBASE_URL}, parent); + CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[]{DummyJNLPFile.JAR_URL, DummyJNLPFile.CODEBASE_URL}, parent); try { classLoader.findClass("foo"); assertFalse("should not happen", true); @@ -252,68 +214,38 @@ public class CodeBaseClassLoaderTest { @Test public void testNullFileSecurityDescApplication() throws Exception { setWSA(); - testNullFileSecurityDesc(); + Exception ex = null; + try { + testNullFileSecurityDesc(); + } catch (Exception exx) { + ex = exx; + } + Assert.assertTrue("was expected exception", ex != null); + Assert.assertTrue("was expected " + NullJnlpFileException.class.getName(), ex instanceof NullJnlpFileException); } @Test @Remote public void testNullFileSecurityDescApplet() throws Exception { setApplet(); - testNullFileSecurityDesc(); - } - - public void testNullFileSecurityDesc() throws Exception { - JNLPFile dummyJnlpFile = new DummyJNLPFile(false); - - JNLPClassLoader parent = new JNLPClassLoader(dummyJnlpFile, null); - CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[]{JAR_URL, CODEBASE_URL}, parent); - Exception ex = null; try { - classLoader.findClass("foo"); + testNullFileSecurityDesc(); } catch (Exception exx) { ex = exx; - ServerAccess.logException(ex); } - Assert.assertNotNull(ex); - Assert.assertTrue(ex instanceof ClassNotFoundException); - + Assert.assertTrue("was expected exception", ex != null); + Assert.assertTrue("was expected " + NullJnlpFileException.class.getName(), ex instanceof NullJnlpFileException); + } - //search dor resources is not relvant to null jnlp file for applets - ex = null; - URL res = null; - try { - //not cached - res = classLoader.findResource("net/sourceforge/jnlp/about/resources/notes.html"); - } catch (Exception exx) { - ex = exx; - ServerAccess.logException(ex); - } - if (JNLPRuntime.isWebstartApplication()) { - Assert.assertNull(res); - Assert.assertNotNull(ex); - Assert.assertTrue(ex instanceof NullJnlpFileException); - } else { - Assert.assertNull(ex); - Assert.assertNotNull(res); - } + public void testNullFileSecurityDesc() throws Exception { + JNLPFile dummyJnlpFile = new DummyJNLPFile() { + @Override + public SecurityDesc getSecurity() { + return new SecurityDesc(null, SecurityDesc.SANDBOX_PERMISSIONS, null); + } + }; + JNLPClassLoader parent = new JNLPClassLoader(dummyJnlpFile, null); - ex = null; - res = null; - try { - //now cached - res = classLoader.findResource("net/sourceforge/jnlp/about/resources/notes.html"); - } catch (Exception exx) { - ex = exx; - ServerAccess.logException(ex); - } - if (JNLPRuntime.isWebstartApplication()) { - Assert.assertNotNull(ex); - Assert.assertTrue(ex instanceof NullJnlpFileException); - Assert.assertNull(res); - } else { - Assert.assertNull(ex); - Assert.assertNotNull(res); - } } } diff --git a/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageImplTest.java b/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageImplTest.java index 3f78502..49302e0 100644 --- a/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageImplTest.java +++ b/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageImplTest.java @@ -81,7 +81,7 @@ public class UnsignedAppletActionStorageImplTest { public void wildcards1() { UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(f3); UnsignedAppletActionEntry r1 = i1.getMatchingItem("http://www.walter-fendt.de/ph14e/inclplane.htm", "http://www.walter-fendt.de/ph14_jar/", Arrays.asList(new String[]{"Ph14English.jar","SchiefeEbene.jar"})); - System.out.println(r1.toString()); + ServerAccess.logOutputReprint(r1.toString()); } @Test public void allMatchingDocAndCode() { diff --git a/tests/netx/unit/sun/applet/PluginAppletViewerTest.java b/tests/netx/unit/sun/applet/PluginAppletViewerTest.java index aa15b47..510e948 100644 --- a/tests/netx/unit/sun/applet/PluginAppletViewerTest.java +++ b/tests/netx/unit/sun/applet/PluginAppletViewerTest.java @@ -5,6 +5,7 @@ import static org.junit.Assert.assertEquals; import java.util.concurrent.Callable; import net.sourceforge.jnlp.AsyncCall; +import net.sourceforge.jnlp.ServerAccess; import org.junit.After; import org.junit.Before; @@ -173,8 +174,8 @@ public class PluginAppletViewerTest { * reference number */ private static int parseAndCheckJSMessage(String message, int messageLength, - String messageType, int contextObjectID) { - System.out.println(message); + String messageType, int contextObjectID) { + ServerAccess.logOutputReprint(message); String[] parts = message.split(" "); assertEquals(messageLength, parts.length); diff --git a/tests/test-extensions/net/sourceforge/jnlp/mock/DummyJNLPFile.java b/tests/test-extensions/net/sourceforge/jnlp/mock/DummyJNLPFile.java new file mode 100644 index 0000000..33dc31a --- /dev/null +++ b/tests/test-extensions/net/sourceforge/jnlp/mock/DummyJNLPFile.java @@ -0,0 +1,77 @@ +/* +Copyright (C) 2012 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. + */ +package net.sourceforge.jnlp.mock; + +import java.net.URL; +import java.util.Locale; +import net.sourceforge.jnlp.JNLPFile; +import net.sourceforge.jnlp.ResourcesDesc; +import net.sourceforge.jnlp.SecurityDesc; + + +public class DummyJNLPFile extends JNLPFile { + + + public static final URL JAR_URL; + public static final URL CODEBASE_URL; + + static { + try { + JAR_URL = new URL("http://icedtea.classpath.org/netx/about.jar"); + CODEBASE_URL = new URL("http://icedtea.classpath.org/netx/"); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + + + @Override + public ResourcesDesc getResources() { + return new ResourcesDesc(null, new Locale[0], new String[0], new String[0]); + } + + @Override + public URL getCodeBase() { + return CODEBASE_URL; + } + + @Override + public SecurityDesc getSecurity() { + return new SecurityDesc(this, SecurityDesc.SANDBOX_PERMISSIONS, null); + } + +} |