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