Debian Codegraph @

tests/reproducers/signed/Kemtrakpro/testcases/KemtrakTests.java

raw symbols SCIP
1 /*
2 Copyright (C) 20121 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 java.io.File;
39 import java.io.IOException;
40 import java.util.AbstractMap;
41 import java.util.Arrays;
42 import net.sourceforge.jnlp.OptionsDefinitions;
43 import net.sourceforge.jnlp.browsertesting.BrowserTest;
44
45 import net.sourceforge.jnlp.ProcessResult;
46 import net.sourceforge.jnlp.ProcessWrapper;
47 import net.sourceforge.jnlp.ServerAccess;
48 import net.sourceforge.jnlp.annotations.Bug;
49 import net.sourceforge.jnlp.annotations.KnownToFail;
50 import net.sourceforge.jnlp.closinglisteners.StringBasedClosingListener;
51 import net.sourceforge.jnlp.config.DeploymentConfiguration;
52 import net.sourceforge.jnlp.runtime.ManifestAttributesChecker;
53 import net.sourceforge.jnlp.security.appletextendedsecurity.AppletSecurityLevel;
54 import net.sourceforge.jnlp.tools.DeploymentPropertiesModifier;
55 import net.sourceforge.jnlp.util.FileUtils;
56
57 import org.junit.Assert;
58 import org.junit.BeforeClass;
59
60 import org.junit.Test;
61
62 @Bug(id = {"PR3350"})
63 /**
64 * The issue is visible only in manifest attributes on, so this is manual
65 * reproducer, automated in head
66 */
67 public class KemtrakTests extends BrowserTest {
68
69 private static final ServerAccess SERVER = new ServerAccess();
70 private static final String JNLP_APPLET_ORIG = "Kemtrak.jnlp";
71 private static final String JNLP_APP_ORIG = "Kemtrak_javaws.jnlp";
72
73 private static final String JNLP_APPLET_CODEBASED = "Kemtrak_cb.jnlp";
74 private static final String JNLP_APP_CODEBASED = "Kemtrak_javaws_cb.jnlp";
75
76 @BeforeClass
77 public static void prepareCodebasedFiles() throws IOException {
78 /**
79 * Kemtrak added the codebase="." during fixing the pr3350 then pr3351
80 * rised
81 */
82 File dir = SERVER.getDir();
83 File jnlp1 = new File(dir, JNLP_APPLET_ORIG);
84 File jnlp2 = new File(dir, JNLP_APP_ORIG);
85
86 File jnlp12 = new File(dir, JNLP_APPLET_CODEBASED);
87 File jnlp22 = new File(dir, JNLP_APP_CODEBASED);
88 String file1 = FileUtils.loadFileAsString(jnlp1);
89 String file2 = FileUtils.loadFileAsString(jnlp2);
90 file1=addCodebase(file1);
91 file2=addCodebase(file2);
92 file1 = file1.replaceAll(JNLP_APPLET_ORIG, JNLP_APPLET_CODEBASED);
93 file2 = file2.replaceAll(JNLP_APP_ORIG, JNLP_APP_CODEBASED);
94 FileUtils.saveFile(file1, jnlp12);
95 FileUtils.saveFile(file2, jnlp22);
96 }
97
98 private static String addCodebase(String s){
99 return s.replaceFirst("version=\"1.302.1.29\"", "version=\"1.302.1.29\" codebase=\".\"");
100 }
101
102 @Bug(id = "PR3350")
103 @Test
104 public void KemtrakTest1() throws Exception {
105 DeploymentPropertiesModifier.MultipleDeploymentPropertiesModifier dm
106 = new DeploymentPropertiesModifier.MultipleDeploymentPropertiesModifier(
107 new AbstractMap.SimpleEntry<>(
108 DeploymentConfiguration.KEY_ENABLE_MANIFEST_ATTRIBUTES_CHECK,
109 ManifestAttributesChecker.MANIFEST_ATTRIBUTES_CHECK.ALL.name()),
110 new AbstractMap.SimpleEntry<>(
111 DeploymentConfiguration.KEY_SECURITY_LEVEL,
112 AppletSecurityLevel.ASK_UNSIGNED.name()));
113 try {
114 dm.setProperties();
115 ProcessWrapper pw = new ProcessWrapper(SERVER.getJavawsLocation(), Arrays.asList(new String[]{ServerAccess.HEADLES_OPTION}), SERVER.getUrl(JNLP_APPLET_ORIG));
116 pw.setWriter("YES\nYES\n");
117 pw.addStdOutListener(new StringBasedClosingListener("kemtrak finished"));
118 ProcessResult pr = pw.execute();
119 Assert.assertTrue("Stdout should contain Kemtrak1 but did not", pr.stdout.contains("Kemtrak1"));
120 Assert.assertTrue("Stdout should contain Kemtrak2 but did not", pr.stdout.contains("Kemtrak2"));
121 Assert.assertTrue("Stdout should contain jcalendar1 but did not", pr.stdout.contains("jcalendar1"));
122 } finally {
123 dm.restoreProperties();
124 }
125 }
126
127 @Bug(id = "PR3351")
128 @KnownToFail
129 @Test
130 public void KemtrakTest2() throws Exception {
131 ProcessWrapper pw = new ProcessWrapper(SERVER.getJavawsLocation(), Arrays.asList(new String[]{
132 ServerAccess.HEADLES_OPTION, OptionsDefinitions.OPTIONS.PARAM.option, "closeJar=closeJar", OptionsDefinitions.OPTIONS.JNLP.option}), SERVER.getUrl(JNLP_APPLET_CODEBASED));
133 pw.setWriter("YES\nYES\n");
134 pw.addStdOutListener(new StringBasedClosingListener("kemtrak finished"));
135 ProcessResult pr = pw.execute();
136 Assert.assertTrue("Stdout should contain Kemtrak1 but did not", pr.stdout.contains("Kemtrak1"));
137 Assert.assertTrue("Stdout should contain Kemtrak2 but did not", pr.stdout.contains("Kemtrak2"));
138 Assert.assertTrue("Stdout should contain jcalendar2 but did not", pr.stdout.contains("jcalendar2"));
139 }
140
141 @Test
142 public void KemtrakTest_javaws1() throws Exception {
143 DeploymentPropertiesModifier.MultipleDeploymentPropertiesModifier dm
144 = new DeploymentPropertiesModifier.MultipleDeploymentPropertiesModifier(
145 new AbstractMap.SimpleEntry<>(
146 DeploymentConfiguration.KEY_ENABLE_MANIFEST_ATTRIBUTES_CHECK,
147 ManifestAttributesChecker.MANIFEST_ATTRIBUTES_CHECK.ALL.name()),
148 new AbstractMap.SimpleEntry<>(
149 DeploymentConfiguration.KEY_SECURITY_LEVEL,
150 AppletSecurityLevel.ASK_UNSIGNED.name()));
151 try {
152 dm.setProperties();
153 ProcessWrapper pw = new ProcessWrapper(SERVER.getJavawsLocation(), Arrays.asList(new String[]{ServerAccess.HEADLES_OPTION}), SERVER.getUrl(JNLP_APP_ORIG));
154 pw.setWriter("YES\nYES\n");
155 pw.addStdOutListener(new StringBasedClosingListener("kemtrak finished"));
156 ProcessResult pr = pw.execute();
157 Assert.assertFalse("Stdout must nor contain Kemtrak1 but did not", pr.stdout.contains("Kemtrak1"));
158 Assert.assertTrue("Stdout should contain Kemtrak2 but did not", pr.stdout.contains("Kemtrak2"));
159 Assert.assertTrue("Stdout should contain jcalendar1 but did not", pr.stdout.contains("jcalendar1"));
160 } finally {
161 dm.restoreProperties();
162 }
163 }
164
165 @Bug(id = "PR3351")
166 @KnownToFail
167 @Test
168 public void KemtrakTest_javaws2() throws Exception {
169 ProcessWrapper pw = new ProcessWrapper(SERVER.getJavawsLocation(), Arrays.asList(new String[]{
170 ServerAccess.HEADLES_OPTION, OptionsDefinitions.OPTIONS.ARG.option, "closeJar", SERVER.getUrl().toExternalForm()+"/", OptionsDefinitions.OPTIONS.JNLP.option}), SERVER.getUrl(JNLP_APP_CODEBASED));
171 pw.setWriter("YES\nYES\n");
172 pw.addStdOutListener(new StringBasedClosingListener("kemtrak finished"));
173 ProcessResult pr = pw.execute();
174 Assert.assertFalse("Stdout must not contain Kemtrak1 but did not", pr.stdout.contains("Kemtrak1"));
175 Assert.assertTrue("Stdout should contain Kemtrak2 but did not", pr.stdout.contains("Kemtrak2"));
176 Assert.assertTrue("Stdout should contain jcalendar2 but did not", pr.stdout.contains("jcalendar2"));
177 }
178
179
180 @Test
181 /**
182 * We can see that issue is not reproducible outside itw
183 */
184 public void KemtrakTest_java() throws Exception {
185 ProcessWrapper pw = new ProcessWrapper(System.getProperty("java.home")+"/bin/java", Arrays.asList(new String[]{
186 "-cp",
187 new File(SERVER.getDir(), "jcalendar.jar").getAbsolutePath()+File.pathSeparator+new File(SERVER.getDir(), "Kemtrakpro.jar").getAbsolutePath(),
188 "Kemtrak",
189 "closeJar",
190 }), SERVER.getDir().toURI().toURL().toExternalForm()+"/");
191 pw.setWriter("YES\nYES\n");
192 pw.addStdOutListener(new StringBasedClosingListener("kemtrak finished"));
193 ProcessResult pr = pw.execute();
194 Assert.assertFalse("Stdout must not contain Kemtrak1 but did not", pr.stdout.contains("Kemtrak1"));
195 Assert.assertTrue("Stdout should contain Kemtrak2 but did not", pr.stdout.contains("Kemtrak2"));
196 Assert.assertTrue("Stdout should contain jcalendar2 but did not", pr.stdout.contains("jcalendar2"));
197 }
198
199 }