Mercurial > hg > release > icedtea-web-1.8
changeset 1253:6f6aa0416960
DummyJNLPFileWithJar enhanced to accept urls only, added test to UnsignedAppletTrustConfirmationTest
* netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmation.java: (updateAppletAction) fixed wrong type, Class<RememberableDialog> become Class<? extends RememberableDialog>
* tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmationTest.java: Added updateAppletActionTest1
* tests/reproducers/signed/CodeBaseManifestEntrySignedMatching/testcases/CodeBaseManifestEntrySignedMatching.java: moved to diamond
* tests/test-extensions/net/sourceforge/jnlp/mock/DummyJNLPFileWithJar.java: constructors hierarchy enhanced to accept also plain URLs as resources. They are dummy anyway
author | Jiri Vanek <jvanek@redhat.com> |
---|---|
date | Mon, 22 Jun 2015 16:44:52 +0200 |
parents | ad35d90a0ee9 |
children | 01d833792fbd |
files | ChangeLog netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmation.java tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmationTest.java tests/reproducers/signed/CodeBaseManifestEntrySignedMatching/testcases/CodeBaseManifestEntrySignedMatching.java tests/test-extensions/net/sourceforge/jnlp/mock/DummyJNLPFileWithJar.java |
diffstat | 5 files changed, 184 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Fri Jun 19 16:00:59 2015 +0200 +++ b/ChangeLog Mon Jun 22 16:44:52 2015 +0200 @@ -1,3 +1,16 @@ + + DummyJNLPFileWithJar enhanced to accept urls only, added test to UnsignedAppletTrustConfirmationTest + * netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmation.java: + (updateAppletAction) fixed wrong type, Class<RememberableDialog> become + Class<? extends RememberableDialog> + * tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmationTest.java: + Added updateAppletActionTest1 + * tests/reproducers/signed/CodeBaseManifestEntrySignedMatching/testcases/CodeBaseManifestEntrySignedMatching.java: + moved to diamond + * tests/test-extensions/net/sourceforge/jnlp/mock/DummyJNLPFileWithJar.java: + constructors hierarchy enhanced to accept also plain URLs as resources. + They are dummy anyway + 2015-06-19 Jiri Vanek <jvanek@redhat.com> Cache reproducer adapted to newest state
--- a/netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmation.java Fri Jun 19 16:00:59 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmation.java Mon Jun 22 16:44:52 2015 +0200 @@ -133,7 +133,7 @@ return fileNames; } - public static void updateAppletAction(JNLPFile file, SavedRememberAction behaviour, Boolean rememberForCodeBase, Class<RememberableDialog> id) { + public static void updateAppletAction(JNLPFile file, SavedRememberAction behaviour, Boolean rememberForCodeBase, Class<? extends RememberableDialog> id) { UnsignedAppletActionStorage userActionStorage = securitySettings.getUnsignedAppletActionCustomStorage(); userActionStorage.lock(); // We should ensure this operation is atomic
--- a/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmationTest.java Fri Jun 19 16:00:59 2015 +0200 +++ b/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmationTest.java Mon Jun 22 16:44:52 2015 +0200 @@ -1,53 +1,164 @@ /* Copyright (C) 2014 Red Hat, Inc. -This file is part of IcedTea. + 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 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. + 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. + 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. + 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. + 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.security.appletextendedsecurity; +import java.io.File; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.net.MalformedURLException; +import java.net.URL; import static org.junit.Assert.assertEquals; -import java.net.URL; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; +import net.sourceforge.jnlp.InformationDesc; +import net.sourceforge.jnlp.config.InfrastructureFileDescriptor; +import net.sourceforge.jnlp.config.PathsAndFiles; +import net.sourceforge.jnlp.mock.DummyJNLPFileWithJar; +import net.sourceforge.jnlp.security.dialogs.apptrustwarningpanel.UnsignedAppletTrustWarningPanel; +import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; +import net.sourceforge.jnlp.security.dialogs.remember.SavedRememberAction; +import net.sourceforge.jnlp.util.FileUtils; +import org.junit.After; +import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; public class UnsignedAppletTrustConfirmationTest { + private static final String surl1 = "http://codeba.se/app"; + private static final String url41 = "http://my.url/app/"; + private static final String url42 = "resource.jar"; + private static URL url; + private static URL url4; + private static InfrastructureFileDescriptor APPLET_TRUST_SETTINGS_USER_BACKUP; + + private static class DummyJnlpWithTitleAndUrls extends DummyJNLPFileWithJar { + + public DummyJnlpWithTitleAndUrls(URL u) throws MalformedURLException { + super(u); + } + + @Override + public InformationDesc getInformation() { + return new InformationDesc(null, false) { + + @Override + public String getTitle() { + return "Demo App"; + } + + }; + } + + @Override + public URL getCodeBase() { + return url; + } + + @Override + public URL getSourceLocation() { + return url; + } + + }; + + @BeforeClass + public static void initUrl() throws MalformedURLException { + url=new URL(surl1); + url4=new URL(url41+url42); + } + + + @BeforeClass + public static void backupAppTrsSets() { + APPLET_TRUST_SETTINGS_USER_BACKUP = PathsAndFiles.APPLET_TRUST_SETTINGS_USER; + } + + @After + public void restoreAppTrsSets() throws Exception { + fakeAppTrsSets(APPLET_TRUST_SETTINGS_USER_BACKUP); + } + + private static void fakeAppTrsSets(final File f) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException { + fakeAppTrsSets(new InfrastructureFileDescriptor() { + + @Override + public String getFullPath() { + return f.getAbsolutePath(); + } + + }); + } + private static void fakeAppTrsSets(InfrastructureFileDescriptor fake) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException { + Field field = PathsAndFiles.class.getDeclaredField("APPLET_TRUST_SETTINGS_USER"); + field.setAccessible(true); + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); + field.set(null, fake); + } + + + @Test + public void updateAppletActionTest1() throws Exception { + File f = File.createTempFile("appletExtendedSecurity", "itwUnittest"); + f.deleteOnExit(); + fakeAppTrsSets(f); + UnsignedAppletTrustConfirmation.updateAppletAction( + new DummyJnlpWithTitleAndUrls(url4), + new SavedRememberAction(ExecuteAppletAction.ALWAYS, "YES"), + Boolean.FALSE, + UnsignedAppletTrustWarningPanel.class); + String s = FileUtils.loadFileAsString(f); + Assert.assertTrue(s.contains("UnsignedAppletTrustWarningPanel:A{YES}")); + Assert.assertTrue(s.contains(url41+url42)); + Assert.assertTrue(s.contains(surl1)); + UnsignedAppletTrustConfirmation.updateAppletAction( + new DummyJnlpWithTitleAndUrls(url4), + new SavedRememberAction(ExecuteAppletAction.NEVER, "NO"), + Boolean.TRUE, + UnsignedAppletTrustWarningPanel.class); + s = FileUtils.loadFileAsString(f); + Assert.assertTrue(s.contains("UnsignedAppletTrustWarningPanel:N{NO}")); + Assert.assertFalse(s.contains(url41+url42)); + Assert.assertTrue(s.contains(surl1)); + } + + @Test public void testToRelativePaths() throws Exception { /* Absolute -> Relative */
--- a/tests/reproducers/signed/CodeBaseManifestEntrySignedMatching/testcases/CodeBaseManifestEntrySignedMatching.java Fri Jun 19 16:00:59 2015 +0200 +++ b/tests/reproducers/signed/CodeBaseManifestEntrySignedMatching/testcases/CodeBaseManifestEntrySignedMatching.java Mon Jun 22 16:44:52 2015 +0200 @@ -118,7 +118,7 @@ @Test public void ApplicationJNLPLocalTest() throws Exception { - List<String> commands = new ArrayList<String>(3); + List<String> commands = new ArrayList<>(3); commands.add(server.getJavawsLocation()); commands.add(ServerAccess.HEADLES_OPTION); commands.add(GENERAL_NAME + SIGNATURE + ".jnlp"); @@ -140,7 +140,7 @@ @Test public void ApplicationJNLPLocalTestWithRemoteCodebase() throws Exception { prepareCopyFile(); - List<String> commands = new ArrayList<String>(3); + List<String> commands = new ArrayList<>(3); commands.add(server.getJavawsLocation()); commands.add(ServerAccess.HEADLES_OPTION); commands.add(GENERAL_NAME + SIGNATURE + "_copy.jnlp"); @@ -160,7 +160,7 @@ @NeedsDisplay @Test public void AppletJNLPRLocalTest() throws Exception { - List<String> commands = new ArrayList<String>(3); + List<String> commands = new ArrayList<>(3); commands.add(server.getJavawsLocation()); commands.add(ServerAccess.HEADLES_OPTION); commands.add(GENERAL_NAME + SIGNATURE + "Applet.jnlp"); @@ -182,7 +182,7 @@ @TestInBrowsers(testIn = {Browsers.one}) @Test public void BrowserJNLPHrefLocalTest() throws Exception { - List<String> commands = new ArrayList<String>(2); + List<String> commands = new ArrayList<>(2); commands.add(server.getBrowserLocation()); commands.add(GENERAL_NAME + SIGNATURE + "Jnlp.html"); ProcessResult pr = ServerAccess.executeProcess(commands, server.getDir(), new AutoOkClosingListener(), null); @@ -194,7 +194,7 @@ @TestInBrowsers(testIn = {Browsers.one}) @Test public void BrowserAppletLocalTest() throws Exception { - List<String> commands = new ArrayList<String>(2); + List<String> commands = new ArrayList<>(2); commands.add(server.getBrowserLocation()); commands.add(GENERAL_NAME + SIGNATURE + ".html"); ProcessResult pr = ServerAccess.executeProcess(commands, server.getDir(), new AutoOkClosingListener(), null);
--- a/tests/test-extensions/net/sourceforge/jnlp/mock/DummyJNLPFileWithJar.java Fri Jun 19 16:00:59 2015 +0200 +++ b/tests/test-extensions/net/sourceforge/jnlp/mock/DummyJNLPFileWithJar.java Mon Jun 22 16:44:52 2015 +0200 @@ -23,38 +23,46 @@ } private final JARDesc[] jarDescs; - private final File[] jarFiles; + private final URL[] jarFiles; public DummyJNLPFileWithJar(File... jarFiles) throws MalformedURLException { this(-1, jarFiles); } + + public DummyJNLPFileWithJar(URL... jarFiles) throws MalformedURLException { + this(-1, jarFiles); + } public DummyJNLPFileWithJar(int main, File... jarFiles) throws MalformedURLException { - codeBase = jarFiles[0].getParentFile().toURI().toURL(); + this(main, filesToUrls(jarFiles)); + } + + private static URL[] filesToUrls(File[] f) throws MalformedURLException{ + URL[] r = new URL[f.length]; + for (int i = 0; i < f.length; i++) { + r[i]=f[i].getParentFile().toURI().toURL(); + } + return r; + } + + public DummyJNLPFileWithJar(int main, URL... jarFiles) throws MalformedURLException { + codeBase = jarFiles[0]; this.jarFiles = jarFiles; jarDescs = new JARDesc[jarFiles.length]; for (int i = 0; i < jarFiles.length; i++) { - jarDescs[i] = makeJarDesc(jarFiles[i].toURI().toURL(), i==main); + jarDescs[i] = makeJarDesc(jarFiles[i], i==main); } - info = new ArrayList<InformationDesc>(); + info = new ArrayList<>(); this.security = new SecurityDesc(this, SecurityDesc.SANDBOX_PERMISSIONS, null); } public URL getJarLocation() { - try { - return jarFiles[0].toURI().toURL(); - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } + return jarFiles[0]; } public URL getJarLocation(int i) { - try { - return jarFiles[i].toURI().toURL(); - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } + return jarFiles[i]; } public JARDesc[] getJarDescs() {