| 1 |
/* SignedAppletManifestSpecifiesSandboxTests.java |
| 2 |
Copyright (C) 2014 Red Hat, Inc. |
| 3 |
|
| 4 |
This file is part of IcedTea. |
| 5 |
|
| 6 |
IcedTea is free software; you can redistribute it and/or |
| 7 |
modify it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation, version 2. |
| 9 |
|
| 10 |
IcedTea is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public License |
| 16 |
along with IcedTea; see the file COPYING. If not, write to |
| 17 |
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 18 |
02110-1301 USA. |
| 19 |
|
| 20 |
Linking this library statically or dynamically with other modules is |
| 21 |
making a combined work based on this library. Thus, the terms and |
| 22 |
conditions of the GNU General Public License cover the whole |
| 23 |
combination. |
| 24 |
|
| 25 |
As a special exception, the copyright holders of this library give you |
| 26 |
permission to link this library with independent modules to produce an |
| 27 |
executable, regardless of the license terms of these independent |
| 28 |
modules, and to copy and distribute the resulting executable under |
| 29 |
terms of your choice, provided that you also meet, for each linked |
| 30 |
independent module, the terms and conditions of the license of that |
| 31 |
module. An independent module is a module which is not derived from |
| 32 |
or based on this library. If you modify this library, you may extend |
| 33 |
this exception to your version of the library, but you are not |
| 34 |
obligated to do so. If you do not wish to do so, delete this |
| 35 |
exception statement from your version. |
| 36 |
*/ |
| 37 |
|
| 38 |
import static org.junit.Assert.assertTrue; |
| 39 |
|
| 40 |
import java.io.IOException; |
| 41 |
|
| 42 |
import net.sourceforge.jnlp.ProcessResult; |
| 43 |
import net.sourceforge.jnlp.annotations.Bug; |
| 44 |
import net.sourceforge.jnlp.annotations.NeedsDisplay; |
| 45 |
import net.sourceforge.jnlp.annotations.TestInBrowsers; |
| 46 |
import net.sourceforge.jnlp.browsertesting.BrowserTest; |
| 47 |
import net.sourceforge.jnlp.browsertesting.Browsers; |
| 48 |
import net.sourceforge.jnlp.closinglisteners.AutoOkClosingListener; |
| 49 |
import net.sourceforge.jnlp.config.DeploymentConfiguration; |
| 50 |
import net.sourceforge.jnlp.runtime.ManifestAttributesChecker; |
| 51 |
import net.sourceforge.jnlp.tools.DeploymentPropertiesModifier; |
| 52 |
|
| 53 |
import org.junit.AfterClass; |
| 54 |
import org.junit.BeforeClass; |
| 55 |
import org.junit.Test; |
| 56 |
|
| 57 |
public class SignedAppletManifestSpecifiesSandboxTests extends BrowserTest { |
| 58 |
|
| 59 |
private static final String STARTING_STRING = "SignedAppletManifestSpecifiesSandbox applet starting"; |
| 60 |
private static final String CLOSE_STRING = AutoOkClosingListener.MAGICAL_OK_CLOSING_STRING; |
| 61 |
private static final String EXPECTED_STDOUT_PRINT = "SECURITY EXCEPTION"; |
| 62 |
private static final String STACKTRACE_EX_TYPE = "AccessControlException"; |
| 63 |
|
| 64 |
private static final String JNLP_EXPECTED_STDOUT = "Initialization Error"; |
| 65 |
private static final String JNLP_EXPECTED_STDERR = "net.sourceforge.jnlp.LaunchException"; |
| 66 |
|
| 67 |
private static DeploymentPropertiesModifier deploymentPropertiesModifier; |
| 68 |
|
| 69 |
@BeforeClass |
| 70 |
public static void setupDeploymentProperties() throws IOException { |
| 71 |
deploymentPropertiesModifier = new DeploymentPropertiesModifier(); |
| 72 |
deploymentPropertiesModifier.setProperties(DeploymentConfiguration.KEY_ENABLE_MANIFEST_ATTRIBUTES_CHECK, ManifestAttributesChecker.MANIFEST_ATTRIBUTES_CHECK.PERMISSIONS.toString()); |
| 73 |
} |
| 74 |
|
| 75 |
@AfterClass |
| 76 |
public static void setbackDeploymentProperties() throws IOException { |
| 77 |
deploymentPropertiesModifier.restoreProperties(); |
| 78 |
} |
| 79 |
|
| 80 |
@Test |
| 81 |
@NeedsDisplay |
| 82 |
@TestInBrowsers(testIn={Browsers.one}) |
| 83 |
@Bug(id="PR1769") |
| 84 |
public void testSignedAppletWithSandboxPermissionsInManifestHtml() throws Exception { |
| 85 |
final ProcessResult pr = server.executeBrowser("SignedAppletManifestSpecifiesSandbox.html", new AutoOkClosingListener(), null); |
| 86 |
assertHtmlAppletInitializes(pr); |
| 87 |
assertHtmlAppletSecurityException(pr); |
| 88 |
assertHtmlAppletCloses(pr); |
| 89 |
} |
| 90 |
|
| 91 |
@Test |
| 92 |
@NeedsDisplay |
| 93 |
@TestInBrowsers(testIn={Browsers.one}) |
| 94 |
@Bug(id="PR1769") |
| 95 |
public void testSignedAppletWithSandboxPermissionsInManifestHtmlJnlpHref() throws Exception { |
| 96 |
final ProcessResult pr = server.executeBrowser("SignedAppletManifestSpecifiesSandboxJnlpHref.html", new AutoOkClosingListener(), null); |
| 97 |
assertHtmlAppletInitializes(pr); |
| 98 |
assertHtmlAppletSecurityException(pr); |
| 99 |
assertHtmlAppletCloses(pr); |
| 100 |
} |
| 101 |
|
| 102 |
/* |
| 103 |
* JNLP applets and applications are not allowed to have mismatched <security> tags and manifest attributes |
| 104 |
*/ |
| 105 |
@Test |
| 106 |
@Bug(id="PR1769") |
| 107 |
public void testSignedAppletWithSandboxPermissionsInManifestJnlpApplet() throws Exception { |
| 108 |
final ProcessResult pr = server.executeJavawsHeadless("SignedAppletManifestSpecifiesSandboxApplet.jnlp"); |
| 109 |
assertJnlpFailsToLaunch(pr); |
| 110 |
} |
| 111 |
|
| 112 |
/* |
| 113 |
* JNLP applets and applications are not allowed to have mismatched <security> tags and manifest attributes |
| 114 |
*/ |
| 115 |
@Test |
| 116 |
@Bug(id="PR1769") |
| 117 |
public void testSignedAppletWithSandboxPermissionsInManifestJnlpApplication() throws Exception { |
| 118 |
final ProcessResult pr = server.executeJavawsHeadless("SignedAppletManifestSpecifiesSandboxApplication.jnlp"); |
| 119 |
assertJnlpFailsToLaunch(pr); |
| 120 |
} |
| 121 |
|
| 122 |
private static void assertHtmlAppletInitializes(final ProcessResult pr) { |
| 123 |
assertTrue("Applet should have initialized", pr.stdout.contains(STARTING_STRING)); |
| 124 |
} |
| 125 |
|
| 126 |
private static void assertHtmlAppletSecurityException(final ProcessResult pr) { |
| 127 |
assertTrue("Applet should have printed SECURITY EXCEPTION", pr.stdout.contains(EXPECTED_STDOUT_PRINT)); |
| 128 |
assertTrue("Applet should have produced an AccessControlException stacktrace", pr.stderr.contains(STACKTRACE_EX_TYPE)); |
| 129 |
} |
| 130 |
|
| 131 |
private static void assertHtmlAppletCloses(final ProcessResult pr) { |
| 132 |
assertTrue("Applet should have printed its exit string", pr.stdout.contains(CLOSE_STRING)); |
| 133 |
} |
| 134 |
|
| 135 |
private static void assertJnlpFailsToLaunch(final ProcessResult pr) { |
| 136 |
assertTrue("stdout should have contained Initialization Error", pr.stdout.contains(JNLP_EXPECTED_STDOUT)); |
| 137 |
assertTrue("stderr should have contained LaunchException", pr.stderr.contains(JNLP_EXPECTED_STDERR)); |
| 138 |
} |
| 139 |
} |