1 /* 2 Copyright (C) 2013 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 package net.sourceforge.jnlp.runtime; 38 39 import java.io.File; 40 import java.net.URL; 41 import java.util.Arrays; 42 import java.util.List; 43 import java.util.Locale; 44 import java.util.jar.Attributes; 45 import java.util.jar.Manifest; 46 import net.sourceforge.jnlp.InformationDesc; 47 import net.sourceforge.jnlp.JNLPFile; 48 import net.sourceforge.jnlp.SecurityDesc; 49 import net.sourceforge.jnlp.cache.UpdatePolicy; 50 import net.sourceforge.jnlp.config.DeploymentConfiguration; 51 import net.sourceforge.jnlp.mock.DummyJNLPFileWithJar; 52 import net.sourceforge.jnlp.security.appletextendedsecurity.AppletSecurityLevel; 53 import net.sourceforge.jnlp.security.appletextendedsecurity.AppletStartupSecuritySettings; 54 import net.sourceforge.jnlp.util.FileTestUtils; 55 import net.sourceforge.jnlp.util.logging.NoStdOutErrTest; 56 import org.junit.AfterClass; 57 import org.junit.Assert; 58 import org.junit.BeforeClass; 59 import org.junit.Test; 60 61 public class JNLPFileTest extends NoStdOutErrTest { 62 63 private static AppletSecurityLevel level; 64 private static List<ManifestAttributesChecker.MANIFEST_ATTRIBUTES_CHECK> attCheckValue; 65 66 @BeforeClass setPermissions()67 public static void setPermissions() { 68 level = AppletStartupSecuritySettings.getInstance().getSecurityLevel(); 69 attCheckValue = ManifestAttributesChecker.getAttributesCheck(); 70 JNLPRuntime.getConfiguration().setProperty(DeploymentConfiguration.KEY_SECURITY_LEVEL, AppletSecurityLevel.ALLOW_UNSIGNED.toChars()); 71 JNLPRuntime.getConfiguration().setProperty(DeploymentConfiguration.KEY_ENABLE_MANIFEST_ATTRIBUTES_CHECK, String.valueOf(ManifestAttributesChecker.MANIFEST_ATTRIBUTES_CHECK.ALL)); 72 } 73 74 @AfterClass resetPermissions()75 public static void resetPermissions() { 76 JNLPRuntime.getConfiguration().setProperty(DeploymentConfiguration.KEY_SECURITY_LEVEL, level.toChars()); 77 JNLPRuntime.getConfiguration().setProperty(DeploymentConfiguration.KEY_ENABLE_MANIFEST_ATTRIBUTES_CHECK, String.valueOf(attCheckValue)); 78 } 79 80 81 @Test newSecurityAttributesTestNotSet()82 public void newSecurityAttributesTestNotSet() throws Exception { 83 //oreder is tested in removeTitle 84 //here we go with pure loading and parsing of them 85 File tempDirectory = FileTestUtils.createTempDirectory(); 86 tempDirectory.deleteOnExit(); 87 File jarLocation66 = new File(tempDirectory, "test66.jar"); 88 File jarLocation77 = new File(tempDirectory, "test77.jar"); 89 Manifest manifest77 = new Manifest(); 90 91 FileTestUtils.createJarWithContents(jarLocation66); //no manifest 92 FileTestUtils.createJarWithContents(jarLocation77, manifest77); 93 94 final DummyJNLPFileWithJar jnlpFile = new DummyJNLPFileWithJar(0, jarLocation66, jarLocation77); //jar 6 should be main 95 final JNLPClassLoader classLoader = new JNLPClassLoader(jnlpFile, UpdatePolicy.ALWAYS);//jnlp file got its instance in classloaders constructor 96 //jnlpFile.getManifestsAttributes().setLoader(classLoader); //classloader set, but no att specified 97 98 Assert.assertNull("classloader attached, but should be null", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.APP_NAME))); 99 Assert.assertNull("classloader attached, but should be null", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.APP_LIBRARY_ALLOWABLE))); 100 Assert.assertNull("classloader attached, but should be null", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.CALLER_ALLOWABLE))); 101 Assert.assertNull("classloader attached, but should be null", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.CODEBASE))); 102 Assert.assertNull("classloader attached, but should be null", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.PERMISSIONS))); 103 Assert.assertNull("classloader attached, but should be null", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.TRUSTED_LIBRARY))); 104 Assert.assertNull("classloader attached, but should be null", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.TRUSTED_ONLY))); 105 Assert.assertNull("classloader attached, but should be null", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.ENTRY_POINT))); 106 107 Assert.assertNull("classloader attached, but should be null", jnlpFile.getManifestsAttributes().getMainClass()); 108 Assert.assertNull("classloader attached, but should be null", jnlpFile.getManifestsAttributes().getApplicationName()); 109 Assert.assertNull("classloader attached, but should be null", jnlpFile.getManifestsAttributes().getApplicationLibraryAllowableCodebase()); 110 Assert.assertNull("classloader attached, but should be null", jnlpFile.getManifestsAttributes().getCallerAllowableCodebase()); 111 Assert.assertNull("classloader attached, but should be null", jnlpFile.getManifestsAttributes().getCodebase()); 112 Assert.assertEquals("no classloader attached, should be null", JNLPFile.ManifestBoolean.UNDEFINED, jnlpFile.getManifestsAttributes().isSandboxForced()); 113 Assert.assertEquals("no classloader attached, should be null", JNLPFile.ManifestBoolean.UNDEFINED, jnlpFile.getManifestsAttributes().isTrustedLibrary()); 114 Assert.assertEquals("no classloader attached, should be null", JNLPFile.ManifestBoolean.UNDEFINED, jnlpFile.getManifestsAttributes().isTrustedOnly()); 115 } 116 117 @Test newSecurityAttributesTest()118 public void newSecurityAttributesTest() throws Exception { 119 //oreder is tested in removeTitle 120 //here we go with pure loading and aprsing of them 121 File tempDirectory = FileTestUtils.createTempDirectory(); 122 tempDirectory.deleteOnExit(); 123 File jarLocation6 = new File(tempDirectory, "test6.jar"); 124 File jarLocation7 = new File(tempDirectory, "test7.jar"); 125 Manifest manifest6 = new Manifest(); 126 manifest6.getMainAttributes().put(Attributes.Name.MAIN_CLASS, "DummyClass1"); //see DummyJNLPFileWithJar constructor with int 127 manifest6.getMainAttributes().put(new Attributes.Name(JNLPFile.ManifestsAttributes.APP_NAME), "DummyClass1 title"); 128 manifest6.getMainAttributes().put(new Attributes.Name(JNLPFile.ManifestsAttributes.ENTRY_POINT), "main1 main2"); 129 manifest6.getMainAttributes().put(new Attributes.Name(JNLPFile.ManifestsAttributes.APP_LIBRARY_ALLOWABLE), "*.com https://*.cz"); 130 manifest6.getMainAttributes().put(new Attributes.Name(JNLPFile.ManifestsAttributes.CALLER_ALLOWABLE), "*.net ftp://*uu.co.uk"); 131 manifest6.getMainAttributes().put(new Attributes.Name(JNLPFile.ManifestsAttributes.CODEBASE), "*.com *.net *.cz *.co.uk"); 132 /* 133 * "sandbox" or "all-permissions" 134 */ 135 /* TODO: Commented lines with "sandbox" permissions specified are causing failures after 136 * PR1769 ("Permissions: sandbox" manifest attribute) patch is applied. The problem 137 * appears to be that the JarCertVerifier thinks that DummyJNLPFileWithJars are 138 * signed (jcv.isFullySigned() falls into the isTriviallySigned() case) even though 139 * they are completely unsigned. This *may* be only be an issue with DummyJNLPFiles. 140 */ 141 // manifest6.getMainAttributes().put(new Attributes.Name(JNLPFile.ManifestsAttributes.PERMISSIONS), "sandbox"); /* commented due to DummyJNLP being "signed" */ 142 manifest6.getMainAttributes().put(new Attributes.Name(JNLPFile.ManifestsAttributes.PERMISSIONS), "all-permissions"); 143 manifest6.getMainAttributes().put(new Attributes.Name(JNLPFile.ManifestsAttributes.TRUSTED_LIBRARY), "false"); 144 manifest6.getMainAttributes().put(new Attributes.Name(JNLPFile.ManifestsAttributes.TRUSTED_ONLY), "false"); 145 146 Manifest manifest7 = new Manifest(); //6 must e main 147 manifest7.getMainAttributes().put(Attributes.Name.MAIN_CLASS, "DummyClass2"); 148 /* 149 * "sandbox" or "all-permissions" 150 */ 151 manifest7.getMainAttributes().put(new Attributes.Name(JNLPFile.ManifestsAttributes.PERMISSIONS), "erroronous one"); 152 manifest7.getMainAttributes().put(new Attributes.Name(JNLPFile.ManifestsAttributes.TRUSTED_LIBRARY), "erroronous one"); 153 manifest7.getMainAttributes().put(new Attributes.Name(JNLPFile.ManifestsAttributes.TRUSTED_ONLY), "erroronous one"); 154 155 FileTestUtils.createJarWithContents(jarLocation6, manifest6); 156 FileTestUtils.createJarWithContents(jarLocation7, manifest7); 157 158 final DummyJNLPFileWithJar jnlpFile = new DummyJNLPFileWithJar(1, jarLocation7, jarLocation6); //jar 6 should be main. Jar 7 have wrong items, but they are never laoded as in main jar are the correct one 159 final DummyJNLPFileWithJar errorJnlpFile = new DummyJNLPFileWithJar(0, jarLocation7); //jar 7 should be main 160 Assert.assertNull("no classloader attached, should be null", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.APP_NAME))); 161 Assert.assertNull("no classloader attached, should be null", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.ENTRY_POINT))); 162 Assert.assertNull("no classloader attached, should be null", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.APP_LIBRARY_ALLOWABLE))); 163 Assert.assertNull("no classloader attached, should be null", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.CALLER_ALLOWABLE))); 164 Assert.assertNull("no classloader attached, should be null", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.CODEBASE))); 165 Assert.assertNull("no classloader attached, should be null", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.PERMISSIONS))); 166 Assert.assertNull("no classloader attached, should be null", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.TRUSTED_LIBRARY))); 167 Assert.assertNull("no classloader attached, should be null", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.TRUSTED_ONLY))); 168 169 Assert.assertNull("no classloader attached, should be null", jnlpFile.getManifestsAttributes().getApplicationName()); 170 Assert.assertNull("no classloader attached, should be null", jnlpFile.getManifestsAttributes().getApplicationLibraryAllowableCodebase()); 171 Assert.assertNull("no classloader attached, should be null", jnlpFile.getManifestsAttributes().getCallerAllowableCodebase()); 172 Assert.assertNull("no classloader attached, should be null", jnlpFile.getManifestsAttributes().getCodebase()); 173 Assert.assertEquals("no classloader attached, should be null", JNLPFile.ManifestBoolean.UNDEFINED, jnlpFile.getManifestsAttributes().isSandboxForced()); 174 Assert.assertEquals("no classloader attached, should be null", JNLPFile.ManifestBoolean.UNDEFINED, jnlpFile.getManifestsAttributes().isTrustedLibrary()); 175 Assert.assertEquals("no classloader attached, should be null", JNLPFile.ManifestBoolean.UNDEFINED, jnlpFile.getManifestsAttributes().isTrustedOnly()); 176 177 final JNLPClassLoader classLoader = new JNLPClassLoader(jnlpFile, UpdatePolicy.ALWAYS); //jnlp file got its instance in classloaders constructor 178 //jnlpFile.getManifestsAttributes().setLoader(classLoader); 179 180 Exception ex = null; 181 try { 182 final JNLPClassLoader errorClassLoader = new JNLPClassLoader(errorJnlpFile, UpdatePolicy.ALWAYS);//jnlp file got its instance in classloaders constructor 183 //errorJnlpFile.getManifestsAttributes().setLoader(errorClassLoader); 184 } catch (Exception e){ 185 //correct exception 186 ex = e; 187 } 188 Assert.assertNotNull(ex); 189 190 Assert.assertEquals("DummyClass1 title", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.APP_NAME))); 191 Assert.assertEquals("main1 main2", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.ENTRY_POINT))); 192 Assert.assertEquals("*.com https://*.cz", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.APP_LIBRARY_ALLOWABLE))); 193 Assert.assertEquals("*.net ftp://*uu.co.uk", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.CALLER_ALLOWABLE))); 194 Assert.assertEquals("*.com *.net *.cz *.co.uk", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.CODEBASE))); 195 // Assert.assertEquals(SecurityDesc.RequestedPermissionLevel.SANDBOX.toHtmlString(), jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.PERMISSIONS))); /* commented due to DummyJNLP being "signed" */ 196 Assert.assertEquals(SecurityDesc.RequestedPermissionLevel.ALL.toHtmlString(), jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.PERMISSIONS))); 197 Assert.assertEquals("false", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.TRUSTED_LIBRARY))); 198 Assert.assertEquals("false", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.TRUSTED_ONLY))); 199 200 201 Assert.assertNull(errorJnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.APP_NAME))); 202 Assert.assertNull(errorJnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.ENTRY_POINT))); 203 Assert.assertNull(errorJnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.APP_LIBRARY_ALLOWABLE))); 204 Assert.assertNull(errorJnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.CALLER_ALLOWABLE))); 205 Assert.assertNull(errorJnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.CODEBASE))); 206 Assert.assertEquals("erroronous one", errorJnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.PERMISSIONS))); 207 Assert.assertEquals("erroronous one", errorJnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.TRUSTED_LIBRARY))); 208 Assert.assertEquals("erroronous one", errorJnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.TRUSTED_ONLY))); 209 210 Assert.assertEquals("DummyClass1 title", jnlpFile.getManifestsAttributes().getApplicationName()); 211 Assert.assertEquals(true, jnlpFile.getManifestsAttributes().getApplicationLibraryAllowableCodebase().matches(new URL("http://aa.com"))); 212 Assert.assertEquals(true, jnlpFile.getManifestsAttributes().getApplicationLibraryAllowableCodebase().matches(new URL("https://aa.cz"))); 213 Assert.assertEquals(true, jnlpFile.getManifestsAttributes().getApplicationLibraryAllowableCodebase().matches(new URL("https://aa.com"))); 214 Assert.assertEquals(false, jnlpFile.getManifestsAttributes().getApplicationLibraryAllowableCodebase().matches(new URL("http://aa.cz"))); 215 Assert.assertEquals(true, jnlpFile.getManifestsAttributes().getCallerAllowableCodebase().matches(new URL("http://aa.net"))); 216 Assert.assertEquals(true, jnlpFile.getManifestsAttributes().getCallerAllowableCodebase().matches(new URL("ftp://aa.uu.co.uk"))); 217 Assert.assertEquals(false, jnlpFile.getManifestsAttributes().getCallerAllowableCodebase().matches(new URL("http://aa.uu.co.uk"))); 218 Assert.assertEquals("*.com *.net *.cz *.co.uk", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.CODEBASE))); 219 Assert.assertEquals(true, jnlpFile.getManifestsAttributes().getCodebase().matches(new URL("http://aa.com"))); 220 Assert.assertEquals(true, jnlpFile.getManifestsAttributes().getCodebase().matches(new URL("ftp://aa.bb.net"))); 221 Assert.assertEquals(true, jnlpFile.getManifestsAttributes().getCodebase().matches(new URL("https://x.net"))); 222 Assert.assertEquals(false, jnlpFile.getManifestsAttributes().getCodebase().matches(new URL("http://aa.bb/com"))); 223 // Assert.assertEquals(JNLPFile.ManifestBoolean.TRUE, jnlpFile.getManifestsAttributes().isSandboxForced()); /* commented due to DummyJNLP being "signed" */ 224 Assert.assertEquals(JNLPFile.ManifestBoolean.FALSE, jnlpFile.getManifestsAttributes().isSandboxForced()); 225 Assert.assertEquals(JNLPFile.ManifestBoolean.FALSE, jnlpFile.getManifestsAttributes().isTrustedLibrary()); 226 Assert.assertEquals(JNLPFile.ManifestBoolean.FALSE, jnlpFile.getManifestsAttributes().isTrustedOnly()); 227 228 ex = null; 229 try { 230 errorJnlpFile.getManifestsAttributes().isSandboxForced(); 231 } catch (Exception e) { 232 ex = e; 233 } 234 Assert.assertNotNull(ex); 235 ex = null; 236 try { 237 Assert.assertEquals("erroronous one", errorJnlpFile.getManifestsAttributes().isTrustedLibrary()); 238 } catch (Exception e) { 239 ex = e; 240 } 241 Assert.assertNotNull(ex); 242 ex = null; 243 try { 244 Assert.assertEquals("erroronous one", errorJnlpFile.getManifestsAttributes().isTrustedOnly()); 245 } catch (Exception e) { 246 ex = e; 247 } 248 Assert.assertNotNull(ex); 249 250 251 } 252 253 @Test removeTitle()254 public void removeTitle() throws Exception { 255 File tempDirectory = FileTestUtils.createTempDirectory(); 256 tempDirectory.deleteOnExit(); 257 File jarLocation1 = new File(tempDirectory, "test1.jar"); 258 File jarLocation2 = new File(tempDirectory, "test2.jar"); 259 File jarLocation3 = new File(tempDirectory, "test3.jar"); 260 File jarLocation4 = new File(tempDirectory, "test4.jar"); 261 File jarLocation5 = new File(tempDirectory, "test5.jar"); 262 263 /* Test with various attributes in manifest!s! */ 264 Manifest manifest1 = new Manifest(); 265 manifest1.getMainAttributes().put(Attributes.Name.MAIN_CLASS, "DummyClass1"); //two times, but one in main jar, see DummyJNLPFileWithJar constructor with int 266 267 Manifest manifest2 = new Manifest(); 268 manifest2.getMainAttributes().put(Attributes.Name.IMPLEMENTATION_VENDOR, "rh1"); //two times, both in not main jar, see DummyJNLPFileWithJar constructor with int 269 270 Manifest manifest3 = new Manifest(); 271 manifest3.getMainAttributes().put(Attributes.Name.IMPLEMENTATION_TITLE, "it"); //jsut once in not main jar, see DummyJNLPFileWithJar constructor with int 272 manifest3.getMainAttributes().put(Attributes.Name.IMPLEMENTATION_VENDOR, "rh2"); 273 274 Manifest manifest4 = new Manifest(); 275 manifest4.getMainAttributes().put(Attributes.Name.MAIN_CLASS, "DummyClass2"); //see jnlpFile.setMainJar(3); 276 manifest4.getMainAttributes().put(Attributes.Name.IMPLEMENTATION_URL, "some url2"); //see DummyJNLPFileWithJar constructor with int 277 278 //first jar 279 Manifest manifest5 = new Manifest(); 280 manifest5.getMainAttributes().put(Attributes.Name.IMPLEMENTATION_URL, "some url1"); //see DummyJNLPFileWithJar constructor with int 281 manifest5.getMainAttributes().put(new Attributes.Name(JNLPFile.ManifestsAttributes.APP_NAME), "Manifested Name"); 282 283 284 FileTestUtils.createJarWithContents(jarLocation1, manifest1); 285 FileTestUtils.createJarWithContents(jarLocation2, manifest2); 286 FileTestUtils.createJarWithContents(jarLocation3, manifest3); 287 FileTestUtils.createJarWithContents(jarLocation4, manifest4); 288 FileTestUtils.createJarWithContents(jarLocation5, manifest5); 289 290 final DummyJNLPFileWithJar jnlpFile = new DummyJNLPFileWithJar(3, jarLocation5, jarLocation3, jarLocation4, jarLocation1, jarLocation2); //jar 1 should be main 291 Assert.assertNull("no classloader attached, should be null", jnlpFile.getManifestsAttributes().getMainClass()); 292 Assert.assertNull("no classloader attached, should be null", jnlpFile.getManifestsAttributes().getAttribute(Attributes.Name.IMPLEMENTATION_VENDOR)); 293 Assert.assertNull("no classloader attached, should be null", jnlpFile.getManifestsAttributes().getAttribute(Attributes.Name.IMPLEMENTATION_TITLE)); 294 Assert.assertNull("no classloader attached, should be null", jnlpFile.getManifestsAttributes().getAttribute(Attributes.Name.MAIN_CLASS)); 295 Assert.assertNull("no classloader attached, should be null", jnlpFile.getManifestsAttributes().getAttribute(Attributes.Name.IMPLEMENTATION_VENDOR_ID)); 296 Assert.assertNull("no classloader attached, should be null", jnlpFile.getManifestsAttributes().getAttribute(Attributes.Name.IMPLEMENTATION_URL)); 297 Assert.assertNull("no classloader attached, should be null", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.APP_NAME))); 298 299 Assert.assertNull(jnlpFile.getTitleFromJnlp()); 300 Assert.assertNull(jnlpFile.getTitleFromManifest()); 301 Assert.assertNull(jnlpFile.getTitle()); 302 303 setTitle(jnlpFile); 304 305 Assert.assertEquals("jnlp title", jnlpFile.getTitleFromJnlp()); 306 Assert.assertNull(jnlpFile.getTitleFromManifest()); 307 Assert.assertEquals("jnlp title", jnlpFile.getTitle()); 308 309 removeTitle(jnlpFile); 310 311 Assert.assertNull(jnlpFile.getTitleFromJnlp()); 312 Assert.assertNull(jnlpFile.getTitleFromManifest()); 313 Assert.assertNull(jnlpFile.getTitle()); 314 315 final JNLPClassLoader classLoader = new JNLPClassLoader(jnlpFile, UpdatePolicy.ALWAYS);//jnlp file got its instance in classloaders constructor 316 //jnlpFile.getManifestsAttributes().setLoader(classLoader); 317 Assert.assertNotNull("classloader attached, should be not null", jnlpFile.getManifestsAttributes().getMainClass()); 318 Assert.assertNull("defined twice, shoud be null", jnlpFile.getManifestsAttributes().getAttribute(Attributes.Name.IMPLEMENTATION_VENDOR)); 319 Assert.assertNotNull("classloader attached, should be not null", jnlpFile.getManifestsAttributes().getAttribute(Attributes.Name.IMPLEMENTATION_TITLE)); 320 Assert.assertNotNull("classloader attached, should be not null", jnlpFile.getManifestsAttributes().getAttribute(Attributes.Name.MAIN_CLASS)); 321 Assert.assertNull("not deffined, should benull", jnlpFile.getManifestsAttributes().getAttribute(Attributes.Name.IMPLEMENTATION_VENDOR_ID)); 322 Assert.assertNotNull("classloader attached, should be not null", jnlpFile.getManifestsAttributes().getAttribute(Attributes.Name.IMPLEMENTATION_URL)); 323 Assert.assertNotNull("classloader attached, should be not null", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.APP_NAME))); 324 //correct values are also tested in JnlpClassloaderTest 325 Assert.assertEquals("classloader attached, should be not null", "it", jnlpFile.getManifestsAttributes().getAttribute(Attributes.Name.IMPLEMENTATION_TITLE)); 326 Assert.assertEquals("classloader attached, should be not null", "DummyClass1", jnlpFile.getManifestsAttributes().getAttribute(Attributes.Name.MAIN_CLASS)); 327 Assert.assertEquals("classloader attached, should be not null", "some url1", jnlpFile.getManifestsAttributes().getAttribute(Attributes.Name.IMPLEMENTATION_URL)); 328 Assert.assertEquals("classloader attached, should be not null", "Manifested Name", jnlpFile.getManifestsAttributes().getAttribute(new Attributes.Name(JNLPFile.ManifestsAttributes.APP_NAME))); 329 330 Assert.assertNull(jnlpFile.getTitleFromJnlp()); 331 Assert.assertEquals("Manifested Name", jnlpFile.getTitleFromManifest()); 332 Assert.assertEquals("Manifested Name", jnlpFile.getTitle()); 333 334 setTitle(jnlpFile); 335 336 Assert.assertEquals("jnlp title", jnlpFile.getTitleFromJnlp()); 337 Assert.assertEquals("Manifested Name", jnlpFile.getTitleFromManifest()); 338 Assert.assertEquals("jnlp title (Manifested Name)", jnlpFile.getTitle()); 339 340 } 341 setTitle(final DummyJNLPFileWithJar jnlpFile)342 private void setTitle(final DummyJNLPFileWithJar jnlpFile) { 343 setTitle(jnlpFile, "jnlp title"); 344 } 345 setTitle(final DummyJNLPFileWithJar jnlpFile, final String title)346 private void setTitle(final DummyJNLPFileWithJar jnlpFile, final String title) { 347 jnlpFile.setInfo(Arrays.asList(new InformationDesc[]{ 348 new InformationDesc(new Locale[]{}, false) { 349 @Override 350 public String getTitle() { 351 return title; 352 } 353 } 354 })); 355 } 356 removeTitle(final DummyJNLPFileWithJar jnlpFile)357 private void removeTitle(final DummyJNLPFileWithJar jnlpFile) { 358 jnlpFile.setInfo(Arrays.asList(new InformationDesc[]{})); 359 } 360 } 361