1 2 import java.io.IOException; 3 import java.util.Arrays; 4 import net.sourceforge.jnlp.ProcessResult; 5 import net.sourceforge.jnlp.ServerAccess; 6 import net.sourceforge.jnlp.annotations.TestInBrowsers; 7 import net.sourceforge.jnlp.browsertesting.BrowserTest; 8 import static net.sourceforge.jnlp.browsertesting.BrowserTest.server; 9 import net.sourceforge.jnlp.browsertesting.Browsers; 10 import net.sourceforge.jnlp.closinglisteners.AutoErrorClosingListener; 11 import net.sourceforge.jnlp.closinglisteners.AutoOkClosingListener; 12 import net.sourceforge.jnlp.closinglisteners.StringBasedClosingListener; 13 import net.sourceforge.jnlp.config.DeploymentConfiguration; 14 import net.sourceforge.jnlp.runtime.ManifestAttributesChecker; 15 import net.sourceforge.jnlp.tools.DeploymentPropertiesModifier; 16 import org.junit.AfterClass; 17 import org.junit.Assert; 18 import org.junit.BeforeClass; 19 import org.junit.Test; 20 21 /* AppletTest.java 22 Copyright (C) 2011 Red Hat, Inc. 23 24 This file is part of IcedTea. 25 26 IcedTea is free software; you can redistribute it and/or 27 modify it under the terms of the GNU General Public License as published by 28 the Free Software Foundation, version 2. 29 30 IcedTea is distributed in the hope that it will be useful, 31 but WITHOUT ANY WARRANTY; without even the implied warranty of 32 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 33 General Public License for more details. 34 35 You should have received a copy of the GNU General Public License 36 along with IcedTea; see the file COPYING. If not, write to 37 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 38 02110-1301 USA. 39 40 Linking this library statically or dynamically with other modules is 41 making a combined work based on this library. Thus, the terms and 42 conditions of the GNU General Public License cover the whole 43 combination. 44 45 As a special exception, the copyright holders of this library give you 46 permission to link this library with independent modules to produce an 47 executable, regardless of the license terms of these independent 48 modules, and to copy and distribute the resulting executable under 49 terms of your choice, provided that you also meet, for each linked 50 independent module, the terms and conditions of the license of that 51 module. An independent module is a module which is not derived from 52 or based on this library. If you modify this library, you may extend 53 this exception to your version of the library, but you are not 54 obligated to do so. If you do not wish to do so, delete this 55 exception statement from your version. 56 */ 57 public class SandboxSignedSandboxTest extends BrowserTest { 58 59 private static final DeploymentPropertiesModifier dpm = new DeploymentPropertiesModifier(); 60 private static final StringBasedClosingListener aok = new AutoOkClosingListener(); 61 private static final StringBasedClosingListener aer = new AutoErrorClosingListener(); 62 private static final String confirmation = "*** applet running ***"; 63 64 65 @BeforeClass setDeploymentManifestPermissionReadingOnly()66 public static void setDeploymentManifestPermissionReadingOnly() throws IOException{ 67 dpm.setProperties(DeploymentConfiguration.KEY_ENABLE_MANIFEST_ATTRIBUTES_CHECK, ManifestAttributesChecker.MANIFEST_ATTRIBUTES_CHECK.PERMISSIONS.toString()); 68 } 69 70 @AfterClass restoreDeploymentProeprtiees()71 public static void restoreDeploymentProeprtiees() throws IOException{ 72 dpm.restoreProperties(); 73 } 74 75 @Test 76 //no security dialog 77 //should run in snadbox (jnlp dont have all-permnissions) javawsAllPermNoSecurity()78 public void javawsAllPermNoSecurity() throws Exception{ 79 ProcessResult p = server.executeJavawsHeadless("SandboxSignedSandbox.jnlp"); 80 Assert.assertTrue(p.stdout.contains(confirmation)); 81 Assert.assertFalse(p.stdout.contains(aok.getCondition())); 82 Assert.assertTrue(p.stderr.contains(aer.getCondition())); 83 } 84 @Test 85 //no security dialog 86 //pass, crash, invalid combination all-permissions x sandbox javawsAllPermAllSecurity()87 public void javawsAllPermAllSecurity() throws Exception{ 88 ProcessResult p = server.executeJavawsHeadless("SandboxSignedSandbox_security.jnlp"); 89 Assert.assertFalse(p.stdout.contains(confirmation)); 90 Assert.assertFalse(p.stdout.contains(aok.getCondition())); 91 Assert.assertTrue(p.stderr.contains(aer.getCondition())); 92 } 93 94 @Test 95 //no security dialog 96 //should run in snadbox (jnlp dont have all-permnissions) javawsAppletAllPermNoSecurity()97 public void javawsAppletAllPermNoSecurity() throws Exception{ 98 ProcessResult p = server.executeJavaws(Arrays.asList(new String[]{"-headless", "-verbose"}),"SandboxSignedSandbox_applet.jnlp", new AutoOkClosingListener(), new AutoErrorClosingListener()); 99 Assert.assertTrue(p.stdout.contains(confirmation)); 100 Assert.assertFalse(p.stdout.contains(aok.getCondition())); 101 Assert.assertTrue(p.stderr.contains(aer.getCondition()));//applets have exception flused only in verbose mode? strange... 102 } 103 @Test 104 //no security dialog 105 //pass, crash, invalid combination all-permissions x sandbox javawsAppletAllPermAllSecurity()106 public void javawsAppletAllPermAllSecurity() throws Exception{ 107 ProcessResult p = server.executeJavawsHeadless("SandboxSignedSandbox_applet_security.jnlp", new AutoOkClosingListener(), new AutoErrorClosingListener()); 108 Assert.assertFalse(p.stdout.contains(confirmation)); 109 Assert.assertFalse(p.stdout.contains(aok.getCondition())); 110 Assert.assertTrue(p.stderr.contains(aer.getCondition())); 111 } 112 113 @Test 114 @TestInBrowsers(testIn = Browsers.one) 115 //no security dialog 116 //started in sandbox appletAllPermAllSecurity()117 public void appletAllPermAllSecurity() throws Exception{ 118 server.getBrowserLocation(); 119 ProcessResult p = server.executeBrowser("SandboxSignedSandbox.html", ServerAccess.AutoClose.CLOSE_ON_BOTH); 120 Assert.assertTrue(p.stdout.contains(confirmation)); 121 Assert.assertFalse(p.stdout.contains(aok.getCondition())); 122 Assert.assertTrue(p.stderr.contains(aer.getCondition())); 123 } 124 125 126 } 127