Debian Codegraph @

tests/reproducers/simple/SandboxUnsignedMissing/testcases/SandboxUnsignedMissingTestHighSecurity.java

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