diff options
Diffstat (limited to 'tests/netx/unit/net')
4 files changed, 134 insertions, 130 deletions
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() { |