| 1 |
|
| 2 |
import java.io.IOException; |
| 3 |
import java.util.Arrays; |
| 4 |
import net.sourceforge.jnlp.OptionsDefinitions; |
| 5 |
import net.sourceforge.jnlp.ProcessResult; |
| 6 |
import net.sourceforge.jnlp.ProcessWrapper; |
| 7 |
import net.sourceforge.jnlp.ServerAccess; |
| 8 |
import net.sourceforge.jnlp.annotations.TestInBrowsers; |
| 9 |
import net.sourceforge.jnlp.browsertesting.BrowserTest; |
| 10 |
import static net.sourceforge.jnlp.browsertesting.BrowserTest.server; |
| 11 |
import net.sourceforge.jnlp.browsertesting.Browsers; |
| 12 |
import net.sourceforge.jnlp.closinglisteners.AutoErrorClosingListener; |
| 13 |
import net.sourceforge.jnlp.closinglisteners.AutoOkClosingListener; |
| 14 |
import net.sourceforge.jnlp.closinglisteners.StringBasedClosingListener; |
| 15 |
import net.sourceforge.jnlp.config.DeploymentConfiguration; |
| 16 |
import net.sourceforge.jnlp.runtime.ManifestAttributesChecker; |
| 17 |
import net.sourceforge.jnlp.security.appletextendedsecurity.AppletSecurityLevel; |
| 18 |
import net.sourceforge.jnlp.tools.DeploymentPropertiesModifier; |
| 19 |
import org.junit.AfterClass; |
| 20 |
import org.junit.Assert; |
| 21 |
import org.junit.BeforeClass; |
| 22 |
import org.junit.Test; |
| 23 |
|
| 24 |
/* AppletTest.java |
| 25 |
Copyright (C) 2011 Red Hat, Inc. |
| 26 |
|
| 27 |
This file is part of IcedTea. |
| 28 |
|
| 29 |
IcedTea is free software; you can redistribute it and/or |
| 30 |
modify it under the terms of the GNU General Public License as published by |
| 31 |
the Free Software Foundation, version 2. |
| 32 |
|
| 33 |
IcedTea is distributed in the hope that it will be useful, |
| 34 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 35 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 36 |
General Public License for more details. |
| 37 |
|
| 38 |
You should have received a copy of the GNU General Public License |
| 39 |
along with IcedTea; see the file COPYING. If not, write to |
| 40 |
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 41 |
02110-1301 USA. |
| 42 |
|
| 43 |
Linking this library statically or dynamically with other modules is |
| 44 |
making a combined work based on this library. Thus, the terms and |
| 45 |
conditions of the GNU General Public License cover the whole |
| 46 |
combination. |
| 47 |
|
| 48 |
As a special exception, the copyright holders of this library give you |
| 49 |
permission to link this library with independent modules to produce an |
| 50 |
executable, regardless of the license terms of these independent |
| 51 |
modules, and to copy and distribute the resulting executable under |
| 52 |
terms of your choice, provided that you also meet, for each linked |
| 53 |
independent module, the terms and conditions of the license of that |
| 54 |
module. An independent module is a module which is not derived from |
| 55 |
or based on this library. If you modify this library, you may extend |
| 56 |
this exception to your version of the library, but you are not |
| 57 |
obligated to do so. If you do not wish to do so, delete this |
| 58 |
exception statement from your version. |
| 59 |
*/ |
| 60 |
public class SandboxSignedMissingTestHighSecurity extends BrowserTest { |
| 61 |
|
| 62 |
private static final DeploymentPropertiesModifier dpm1 = new DeploymentPropertiesModifier(); |
| 63 |
private static final DeploymentPropertiesModifier dpm2 = new DeploymentPropertiesModifier(); |
| 64 |
private static final StringBasedClosingListener aok = new AutoOkClosingListener(); |
| 65 |
private static final StringBasedClosingListener aer = new AutoErrorClosingListener(); |
| 66 |
private static final String confirmation = "*** applet running ***"; |
| 67 |
|
| 68 |
|
| 69 |
@BeforeClass |
| 70 |
public static void setDeploymentManifestPermissionReadingOnly() throws IOException{ |
| 71 |
dpm1.setProperties(DeploymentConfiguration.KEY_ENABLE_MANIFEST_ATTRIBUTES_CHECK, ManifestAttributesChecker.MANIFEST_ATTRIBUTES_CHECK.PERMISSIONS.toString()); |
| 72 |
dpm2.setProperties(DeploymentConfiguration.KEY_SECURITY_LEVEL, AppletSecurityLevel.ASK_UNSIGNED.toChars()); |
| 73 |
} |
| 74 |
|
| 75 |
@AfterClass |
| 76 |
public static void restoreDeploymentProeprtiees() throws IOException{ |
| 77 |
dpm2.restoreProperties(); |
| 78 |
dpm1.restoreProperties(); |
| 79 |
} |
| 80 |
|
| 81 |
@Test |
| 82 |
// security dialog |
| 83 |
//crash (jnlp dont have all-permnissions) |
| 84 |
public void javawsAllPermNoSecurityYes() throws Exception{ |
| 85 |
ProcessWrapper pw = new ProcessWrapper(server.getJavawsLocation(), Arrays.asList("-headless"), server.getUrl("SandboxSignedMissing.jnlp")); |
| 86 |
pw.setWriter("YES\n"); |
| 87 |
ProcessResult p = pw.execute(); |
| 88 |
Assert.assertTrue(p.stdout.contains(confirmation)); |
| 89 |
Assert.assertFalse(p.stdout.contains(aok.getCondition())); |
| 90 |
Assert.assertTrue(p.stderr.contains(aer.getCondition())); |
| 91 |
} |
| 92 |
|
| 93 |
// security dialog |
| 94 |
//crash (jnlp dont have all-permnissions) |
| 95 |
@Test |
| 96 |
public void javawsAllPermNoSecurityNo() throws Exception{ |
| 97 |
ProcessWrapper pw = new ProcessWrapper(server.getJavawsLocation(), Arrays.asList("-headless"), server.getUrl("SandboxSignedMissing.jnlp")); |
| 98 |
pw.setWriter("NO\n"); |
| 99 |
ProcessResult p = pw.execute(); |
| 100 |
Assert.assertFalse(p.stdout.contains(confirmation)); |
| 101 |
Assert.assertFalse(p.stdout.contains(aok.getCondition())); |
| 102 |
Assert.assertTrue(p.stderr.contains(aer.getCondition())); |
| 103 |
} |
| 104 |
|
| 105 |
@Test |
| 106 |
// security dialog |
| 107 |
//pass |
| 108 |
public void javawsAllPermAllSecurityYes() throws Exception{ |
| 109 |
ProcessWrapper pw = new ProcessWrapper(server.getJavawsLocation(), Arrays.asList("-headless"), server.getUrl("SandboxSignedMissing_security.jnlp")); |
| 110 |
pw.setWriter("YES\n"); |
| 111 |
ProcessResult p = pw.execute(); |
| 112 |
Assert.assertTrue(p.stdout.contains(confirmation)); |
| 113 |
Assert.assertTrue(p.stdout.contains(aok.getCondition())); |
| 114 |
Assert.assertFalse(p.stderr.contains(aer.getCondition())); |
| 115 |
} |
| 116 |
|
| 117 |
@Test |
| 118 |
// security dialog |
| 119 |
//pass |
| 120 |
public void javawsAllPermAllSecurityNo() throws Exception{ |
| 121 |
ProcessWrapper pw = new ProcessWrapper(server.getJavawsLocation(), Arrays.asList("-headless"), server.getUrl("SandboxSignedMissing_security.jnlp")); |
| 122 |
pw.setWriter("NO\n"); |
| 123 |
ProcessResult p = pw.execute(); |
| 124 |
Assert.assertFalse(p.stdout.contains(confirmation)); |
| 125 |
Assert.assertFalse(p.stdout.contains(aok.getCondition())); |
| 126 |
Assert.assertTrue(p.stderr.contains(aer.getCondition())); |
| 127 |
} |
| 128 |
|
| 129 |
@Test |
| 130 |
// security dialog |
| 131 |
//crash (jnlp dont have all-permnissions) |
| 132 |
public void javawsAppletAllPermNoSecurityYes() throws Exception{ |
| 133 |
ProcessWrapper pw = new ProcessWrapper(server.getJavawsLocation(), Arrays.asList("-headless", "-verbose"), server.getUrl("SandboxSignedMissing_applet.jnlp")); |
| 134 |
pw.addStdOutListener(new AutoOkClosingListener()); |
| 135 |
pw.setWriter("YES\n"); |
| 136 |
ProcessResult p = pw.execute(); |
| 137 |
Assert.assertTrue(p.stdout.contains(confirmation)); |
| 138 |
Assert.assertFalse(p.stdout.contains(aok.getCondition())); |
| 139 |
Assert.assertTrue(p.stderr.contains(aer.getCondition()));//applets have exception flused only in verbose mode? strange... |
| 140 |
} |
| 141 |
|
| 142 |
@Test |
| 143 |
// security dialog |
| 144 |
//crash (jnlp dont have all-permnissions) |
| 145 |
public void javawsAppletAllPermNoSecurityNo() throws Exception{ |
| 146 |
ProcessWrapper pw = new ProcessWrapper(server.getJavawsLocation(), Arrays.asList("-headless", "-verbose"), server.getUrl("SandboxSignedMissing_applet.jnlp")); |
| 147 |
pw.addStdErrListener(new AutoErrorClosingListener()); |
| 148 |
pw.addStdOutListener(new AutoOkClosingListener()); |
| 149 |
pw.setWriter("NO\n"); |
| 150 |
ProcessResult p = pw.execute(); |
| 151 |
Assert.assertFalse(p.stdout.contains(confirmation)); |
| 152 |
Assert.assertFalse(p.stdout.contains(aok.getCondition())); |
| 153 |
Assert.assertTrue(p.stderr.contains(aer.getCondition()));//applets have exception flused only in verbose mode? strange... |
| 154 |
} |
| 155 |
|
| 156 |
@Test |
| 157 |
//security dialog |
| 158 |
//pass |
| 159 |
public void javawsAppletAllPermAllSecurityYes() throws Exception{ |
| 160 |
ProcessWrapper pw = new ProcessWrapper(server.getJavawsLocation(), Arrays.asList("-headless"), server.getUrl("SandboxSignedMissing_applet_security.jnlp")); |
| 161 |
pw.addStdOutListener(new AutoOkClosingListener()); |
| 162 |
pw.setWriter("YES\n"); |
| 163 |
ProcessResult p = pw.execute(); |
| 164 |
Assert.assertTrue(p.stdout.contains(confirmation)); |
| 165 |
Assert.assertTrue(p.stdout.contains(aok.getCondition())); |
| 166 |
Assert.assertFalse(p.stderr.contains(aer.getCondition())); |
| 167 |
} |
| 168 |
@Test |
| 169 |
//security dialog |
| 170 |
//pass |
| 171 |
public void javawsAppletAllPermAllSecurityNo() throws Exception{ |
| 172 |
ProcessWrapper pw = new ProcessWrapper(server.getJavawsLocation(), Arrays.asList("-headless"), server.getUrl("SandboxSignedMissing_applet_security.jnlp")); |
| 173 |
pw.addStdErrListener(new AutoErrorClosingListener()); |
| 174 |
pw.addStdOutListener(new AutoOkClosingListener()); |
| 175 |
pw.setWriter("NO\n"); |
| 176 |
ProcessResult p = pw.execute(); |
| 177 |
Assert.assertFalse(p.stdout.contains(confirmation)); |
| 178 |
Assert.assertFalse(p.stdout.contains(aok.getCondition())); |
| 179 |
Assert.assertTrue(p.stderr.contains(aer.getCondition())); |
| 180 |
} |
| 181 |
|
| 182 |
//browser do not support headless dialogues |
| 183 |
//@Test |
| 184 |
//@TestInBrowsers(testIn = Browsers.one) |
| 185 |
//no security dialog |
| 186 |
//pass |
| 187 |
public void appletAllPermAllSecurity() throws Exception{ |
| 188 |
server.getBrowserLocation(); |
| 189 |
ProcessResult p = server.executeBrowser("SandboxSignedMissing.html", ServerAccess.AutoClose.CLOSE_ON_BOTH); |
| 190 |
Assert.assertTrue(p.stdout.contains(confirmation)); |
| 191 |
Assert.assertTrue(p.stdout.contains(aok.getCondition())); |
| 192 |
Assert.assertFalse(p.stderr.contains(aer.getCondition())); |
| 193 |
} |
| 194 |
|
| 195 |
@Test |
| 196 |
public void javawsHtmlYes() throws Exception{ |
| 197 |
ProcessWrapper pw = new ProcessWrapper(server.getJavawsLocation(), Arrays.asList("-headless", "-html"), server.getUrl("SandboxSignedMissing.html")); |
| 198 |
pw.addStdOutListener(new AutoOkClosingListener()); |
| 199 |
pw.setWriter("YES\n"); |
| 200 |
ProcessResult p = pw.execute(); |
| 201 |
Assert.assertTrue(p.stdout.contains(confirmation)); |
| 202 |
Assert.assertTrue(p.stdout.contains(aok.getCondition())); |
| 203 |
Assert.assertFalse(p.stderr.contains(aer.getCondition())); |
| 204 |
} |
| 205 |
|
| 206 |
@Test |
| 207 |
public void javawsHtmlNo() throws Exception{ |
| 208 |
ProcessWrapper pw = new ProcessWrapper(server.getJavawsLocation(), Arrays.asList("-headless", "-html"), server.getUrl("SandboxSignedMissing.html")); |
| 209 |
pw.addStdOutListener(new AutoOkClosingListener()); |
| 210 |
pw.setWriter("NO\n"); |
| 211 |
ProcessResult p = pw.execute(); |
| 212 |
Assert.assertFalse(p.stdout.contains(confirmation)); |
| 213 |
Assert.assertFalse(p.stdout.contains(aok.getCondition())); |
| 214 |
Assert.assertTrue(p.stderr.contains(aer.getCondition())); |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
} |