Changeset 429 for trunk/icedtea-web/tests/netx/unit
- Timestamp:
- Sep 24, 2014, 9:34:21 PM (11 years ago)
- Location:
- trunk/icedtea-web/tests/netx/unit
- Files:
-
- 14 edited
- 28 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/icedtea-web/tests/netx/unit/net/sourceforge/jnlp/DefaultLaunchHandlerTest.java
r418 r429 43 43 import java.io.ByteArrayOutputStream; 44 44 import java.io.PrintStream; 45 import java.lang.reflect.Field; 46 import net.sourceforge.jnlp.util.logging.LogConfig; 47 import net.sourceforge.jnlp.util.logging.OutputController; 45 48 46 49 import org.junit.Test; … … 48 51 public class DefaultLaunchHandlerTest { 49 52 53 private static class LocalLogger extends OutputController { 54 55 private static class AccessibleStream extends PrintStream { 56 57 public AccessibleStream(ByteArrayOutputStream out) { 58 super(out); 59 } 60 61 public ByteArrayOutputStream getOut() { 62 return (ByteArrayOutputStream) out; 63 } 64 } 65 66 LocalLogger() { 67 super(new AccessibleStream(new ByteArrayOutputStream()), new AccessibleStream(new ByteArrayOutputStream())); 68 try{ 69 Field f = LogConfig.class.getDeclaredField("logToStreams"); 70 f.setAccessible(true); 71 f.set(LogConfig.getLogConfig(), true); 72 }catch(Exception ex){ 73 ServerAccess.logException(ex); 74 } 75 } 76 77 public String getStream1() { 78 return ((AccessibleStream) (super.getOut())).getOut().toString(); 79 } 80 81 public String getStream2() { 82 return ((AccessibleStream) (super.getErr())).getOut().toString(); 83 } 84 } 85 50 86 @Test 51 87 public void testBasicLaunch() { 52 ByteArrayOutputStream baos = new ByteArrayOutputStream();53 DefaultLaunchHandler handler = new DefaultLaunchHandler( new PrintStream(baos));88 LocalLogger l = new LocalLogger(); 89 DefaultLaunchHandler handler = new DefaultLaunchHandler(l); 54 90 55 91 // all no-ops with no output … … 58 94 handler.launchCompleted(null); 59 95 60 String output = baos.toString();61 assertEquals("", output);96 assertEquals("", l.getStream1()); 97 assertEquals("", l.getStream2()); 62 98 } 63 99 64 100 @Test 65 101 public void testLaunchWarning() { 66 ByteArrayOutputStream baos = new ByteArrayOutputStream();67 DefaultLaunchHandler handler = new DefaultLaunchHandler( new PrintStream(baos));102 LocalLogger l = new LocalLogger(); 103 DefaultLaunchHandler handler = new DefaultLaunchHandler(l); 68 104 69 105 LaunchException warning = new LaunchException(null, null, … … 72 108 73 109 assertTrue(continueLaunch); 74 String output = baos.toString(); 75 assertEquals("netx: warning type: test warning\n", output); 110 assertEquals("netx: warning type: test warning\n", l.getStream1()); 76 111 } 77 112 78 113 @Test 79 114 public void testLaunchError() { 80 ByteArrayOutputStream baos = new ByteArrayOutputStream();81 DefaultLaunchHandler handler = new DefaultLaunchHandler( new PrintStream(baos));115 LocalLogger l = new LocalLogger(); 116 DefaultLaunchHandler handler = new DefaultLaunchHandler(l); 82 117 83 118 LaunchException error = new LaunchException(null, null, … … 85 120 handler.launchError(error); 86 121 87 String output = baos.toString(); 88 assertEquals("netx: error type: test error\n", output); 122 assertEquals("netx: error type: test error\n", l.getStream1()); 89 123 } 90 124 91 125 @Test 92 126 public void testLaunchErrorWithCause() { 93 ByteArrayOutputStream baos = new ByteArrayOutputStream();94 DefaultLaunchHandler handler = new DefaultLaunchHandler( new PrintStream(baos));127 LocalLogger l = new LocalLogger(); 128 DefaultLaunchHandler handler = new DefaultLaunchHandler(l); 95 129 96 130 ParseException parse = new ParseException("no information element"); … … 99 133 handler.launchError(error); 100 134 101 String output = baos.toString(); 102 assertEquals("netx: error type: test error (no information element)\n", output); 135 assertEquals("netx: error type: test error (no information element)\n", l.getStream1()); 103 136 } 104 137 105 138 @Test 106 139 public void testLaunchErrorWithNestedCause() { 107 ByteArrayOutputStream baos = new ByteArrayOutputStream();108 DefaultLaunchHandler handler = new DefaultLaunchHandler( new PrintStream(baos));140 LocalLogger l = new LocalLogger(); 141 DefaultLaunchHandler handler = new DefaultLaunchHandler(l); 109 142 110 143 ParseException parse = new ParseException("no information element"); … … 114 147 handler.launchError(error); 115 148 116 String output = baos.toString(); 117 assertEquals("netx: error type: test error (programmer made a mistake (no information element))\n", output); 149 assertEquals("netx: error type: test error (programmer made a mistake (no information element))\n", l.getStream1()); 118 150 } 119 120 151 121 152 @Test 122 153 public void testValidationError() { 123 ByteArrayOutputStream baos = new ByteArrayOutputStream();124 DefaultLaunchHandler handler = new DefaultLaunchHandler( new PrintStream(baos));154 LocalLogger l = new LocalLogger(); 155 DefaultLaunchHandler handler = new DefaultLaunchHandler(l); 125 156 126 157 LaunchException error = new LaunchException(null, null, … … 128 159 handler.validationError(error); 129 160 130 String output = baos.toString(); 131 assertEquals("netx: validation-error type: test validation-error\n", output); 161 assertEquals("netx: validation-error type: test validation-error\n", l.getStream1()); 132 162 } 133 163 } -
trunk/icedtea-web/tests/netx/unit/net/sourceforge/jnlp/JNLPFileTest.java
r418 r429 38 38 package net.sourceforge.jnlp; 39 39 40 import java.io.ByteArrayInputStream; 41 import java.io.InputStream; 42 import java.net.MalformedURLException; 43 import java.net.URL; 40 44 import java.util.Locale; 45 import java.util.Map; 41 46 42 47 import net.sourceforge.jnlp.JNLPFile.Match; 48 import net.sourceforge.jnlp.annotations.Bug; 43 49 import net.sourceforge.jnlp.mock.MockJNLPFile; 50 import net.sourceforge.jnlp.util.logging.NoStdOutErrTest; 44 51 45 52 import org.junit.Assert; 46 53 import org.junit.Test; 47 54 48 public class JNLPFileTest {55 public class JNLPFileTest extends NoStdOutErrTest{ 49 56 Locale jvmLocale = new Locale("en", "CA", "utf8"); 50 57 MockJNLPFile file = new MockJNLPFile(jvmLocale); … … 104 111 file.localeMatches(jvmLocale, mismatchAvailable, Match.GENERALIZED)); 105 112 } 113 114 @Test 115 public void testCodebaseConstructorWithInputstreamAndCodebase() throws Exception { 116 String jnlpContext = "<?xml version=\"1.0\"?>\n" + 117 "<jnlp spec=\"1.5+\"\n" + 118 "href=\"EmbeddedJnlpFile.jnlp\"\n" + 119 "codebase=\"http://icedtea.claspath.org\"\n" + 120 ">\n" + 121 "" + 122 "<information>\n" + 123 "<title>Sample Test</title>\n" + 124 "<vendor>RedHat</vendor>\n" + 125 "<offline-allowed/>\n" + 126 "</information>\n" + 127 "\n" + 128 "<resources>\n" + 129 "<j2se version='1.6+' />\n" + 130 "<jar href='EmbeddedJnlpJarOne.jar' main='true'/>\n" + 131 "<jar href='EmbeddedJnlpJarTwo.jar' main='true'/>\n" + 132 "</resources>\n" + 133 "\n" + 134 "<applet-desc\n" + 135 "documentBase=\".\"\n" + 136 "name=\"redhat.embeddedjnlp\"\n" + 137 "main-class=\"redhat.embeddedjnlp\"\n" + 138 "width=\"0\"\n" + 139 "height=\"0\"\n" + 140 "/>\n" + 141 "</jnlp>"; 142 143 URL codeBase = new URL("http://www.redhat.com/"); 144 145 InputStream is = new ByteArrayInputStream(jnlpContext.getBytes()); 146 147 JNLPFile jnlpFile = new JNLPFile(is, codeBase, new ParserSettings(false,false,false)); 148 149 Assert.assertEquals("http://icedtea.claspath.org/", jnlpFile.getCodeBase().toExternalForm()); 150 Assert.assertEquals("redhat.embeddedjnlp", jnlpFile.getApplet().getMainClass()); 151 Assert.assertEquals("Sample Test", jnlpFile.getTitle()); 152 Assert.assertEquals(2, jnlpFile.getResources().getJARs().length); 153 } 154 155 @Test 156 public void testPropertyRestrictions() throws MalformedURLException, ParseException { 157 String jnlpContents = "<?xml version='1.0'?>\n" + 158 "<jnlp spec='1.5' href='foo' codebase='bar'>\n" + 159 " <information>\n" + 160 " <title>Parsing Test</title>\n" + 161 " <vendor>IcedTea</vendor>\n" + 162 " <offline-allowed/>\n" + 163 " </information>\n" + 164 " <resources>\n" + 165 " <property name='general' value='general'/>\n" + 166 " <property name='os' value='general'/>\n" + 167 " <property name='arch' value='general'/>\n" + 168 " </resources>\n" + 169 " <resources os='os1'>" + 170 " <property name='os' value='os1'/>\n" + 171 " </resources>\n" + 172 " <resources os='os1' arch='arch1'>" + 173 " <property name='arch' value='arch1'/>\n" + 174 " </resources>\n" + 175 " <resources os='os2' arch='arch2'>\n" + 176 " <property name='os' value='os2'/>\n" + 177 " <property name='arch' value='arch2'/>\n" + 178 " </resources>\n" + 179 " <installer-desc/>\n" + 180 "</jnlp>"; 181 182 URL codeBase = new URL("http://www.redhat.com/"); 183 InputStream is = new ByteArrayInputStream(jnlpContents.getBytes()); 184 JNLPFile jnlpFile = new JNLPFile(is, codeBase, new ParserSettings(false,false,false)); 185 186 ResourcesDesc resources; 187 Map<String,String> properties; 188 189 resources = jnlpFile.getResources(Locale.getDefault(), "os0", "arch0"); 190 properties = resources.getPropertiesMap(); 191 Assert.assertEquals("general", properties.get("general")); 192 Assert.assertEquals("general", properties.get("os")); 193 Assert.assertEquals("general", properties.get("arch")); 194 195 resources = jnlpFile.getResources(Locale.getDefault(), "os1", "arch0"); 196 properties = resources.getPropertiesMap(); 197 Assert.assertEquals("general", properties.get("general")); 198 Assert.assertEquals("os1", properties.get("os")); 199 Assert.assertEquals("general", properties.get("arch")); 200 201 resources = jnlpFile.getResources(Locale.getDefault(), "os1", "arch1"); 202 properties = resources.getPropertiesMap(); 203 Assert.assertEquals("general", properties.get("general")); 204 Assert.assertEquals("os1", properties.get("os")); 205 Assert.assertEquals("arch1", properties.get("arch")); 206 207 resources = jnlpFile.getResources(Locale.getDefault(), "os2", "arch2"); 208 properties = resources.getPropertiesMap(); 209 Assert.assertEquals("general", properties.get("general")); 210 Assert.assertEquals("os2", properties.get("os")); 211 Assert.assertEquals("arch2", properties.get("arch")); 212 } 213 214 @Bug(id={"PR1533"}) 215 @Test 216 public void testDownloadOptionsAppliedEverywhere() throws MalformedURLException, ParseException { 217 String os = System.getProperty("os.name"); 218 String arch = System.getProperty("os.arch"); 219 220 String jnlpContents = "<?xml version='1.0'?>\n" + 221 "<jnlp spec='1.5' href='foo' codebase='bar'>\n" + 222 " <information>\n" + 223 " <title>Parsing Test</title>\n" + 224 " <vendor>IcedTea</vendor>\n" + 225 " <offline-allowed/>\n" + 226 " </information>\n" + 227 " <resources>\n" + 228 " <property name='jnlp.packEnabled' value='false'/>" + 229 " <property name='jnlp.versionEnabled' value='false'/>" + 230 " </resources>\n" + 231 " <resources os='" + os + "'>" + 232 " <property name='jnlp.packEnabled' value='true'/>" + 233 " </resources>\n" + 234 " <resources arch='" + arch + "'>" + 235 " <property name='jnlp.versionEnabled' value='true'/>" + 236 " </resources>\n" + 237 " <installer-desc/>\n" + 238 "</jnlp>"; 239 240 URL codeBase = new URL("http://icedtea.classpath.org"); 241 InputStream is = new ByteArrayInputStream(jnlpContents.getBytes()); 242 JNLPFile jnlpFile = new JNLPFile(is, codeBase, new ParserSettings(false,false,false)); 243 DownloadOptions downloadOptions = jnlpFile.getDownloadOptions(); 244 245 Assert.assertTrue(downloadOptions.useExplicitPack()); 246 Assert.assertTrue(downloadOptions.useExplicitVersion()); 247 } 248 249 @Bug(id={"PR1533"}) 250 @Test 251 public void testDownloadOptionsFilteredOut() throws MalformedURLException, ParseException { 252 String jnlpContents = "<?xml version='1.0'?>\n" + 253 "<jnlp spec='1.5' href='foo' codebase='bar'>\n" + 254 " <information>\n" + 255 " <title>Parsing Test</title>\n" + 256 " <vendor>IcedTea</vendor>\n" + 257 " <offline-allowed/>\n" + 258 " </information>\n" + 259 " <resources>\n" + 260 " <property name='jnlp.packEnabled' value='false'/>" + 261 " <property name='jnlp.versionEnabled' value='false'/>" + 262 " </resources>\n" + 263 " <resources os='someOtherOs'>" + 264 " <property name='jnlp.packEnabled' value='true'/>" + 265 " </resources>\n" + 266 " <resources arch='someOtherArch'>" + 267 " <property name='jnlp.versionEnabled' value='true'/>" + 268 " </resources>\n" + 269 " <installer-desc/>\n" + 270 "</jnlp>"; 271 272 URL codeBase = new URL("http://icedtea.classpath.org"); 273 InputStream is = new ByteArrayInputStream(jnlpContents.getBytes()); 274 JNLPFile jnlpFile = new JNLPFile(is, codeBase, new ParserSettings(false,false,false)); 275 DownloadOptions downloadOptions = jnlpFile.getDownloadOptions(); 276 277 Assert.assertFalse(downloadOptions.useExplicitPack()); 278 Assert.assertFalse(downloadOptions.useExplicitVersion()); 279 } 280 281 282 public static final String minimalJnlp = "<?xml version='1.0'?>\n" 283 + "<jnlp spec='1.5' href='foo' codebase='.'>\n" 284 + " <information>\n" 285 + " <title>Parsing Test</title>\n" 286 + " <vendor>IcedTea</vendor>\n" 287 + " </information>\n" 288 + "<resources>\n" 289 + " </resources>\n" 290 + "SECURITY" 291 + "</jnlp>"; 292 293 @Test 294 public void testGetRequestedPermissionLevel1() throws MalformedURLException, ParseException { 295 String jnlpContents = minimalJnlp.replace("SECURITY", ""); 296 URL codeBase = new URL("http://icedtea.classpath.org"); 297 InputStream is = new ByteArrayInputStream(jnlpContents.getBytes()); 298 JNLPFile jnlpFile = new JNLPFile(is, codeBase, new ParserSettings(false, false, false)); 299 Assert.assertEquals(SecurityDesc.RequestedPermissionLevel.NONE, jnlpFile.getRequestedPermissionLevel()); 300 } 301 302 @Test 303 public void testGetRequestedPermissionLevel2() throws MalformedURLException, ParseException { 304 String jnlpContents = minimalJnlp.replace("SECURITY", "<security><"+SecurityDesc.RequestedPermissionLevel.ALL.toJnlpString()+"/></security>"); 305 306 URL codeBase = new URL("http://icedtea.classpath.org"); 307 InputStream is = new ByteArrayInputStream(jnlpContents.getBytes()); 308 JNLPFile jnlpFile = new JNLPFile(is, codeBase, new ParserSettings(false, false, false)); 309 Assert.assertEquals(SecurityDesc.RequestedPermissionLevel.ALL, jnlpFile.getRequestedPermissionLevel()); 310 } 311 312 @Test 313 public void testGetRequestedPermissionLevel3() throws MalformedURLException, ParseException { 314 String jnlpContents = minimalJnlp.replace("SECURITY", "<security></security>"); 315 316 URL codeBase = new URL("http://icedtea.classpath.org"); 317 InputStream is = new ByteArrayInputStream(jnlpContents.getBytes()); 318 JNLPFile jnlpFile = new JNLPFile(is, codeBase, new ParserSettings(false, false, false)); 319 Assert.assertEquals(SecurityDesc.RequestedPermissionLevel.NONE, jnlpFile.getRequestedPermissionLevel()); 320 } 321 322 @Test 323 public void testGetRequestedPermissionLevel4() throws MalformedURLException, ParseException { 324 String jnlpContents = minimalJnlp.replace("SECURITY", "<security>whatever</security>"); 325 326 URL codeBase = new URL("http://icedtea.classpath.org"); 327 InputStream is = new ByteArrayInputStream(jnlpContents.getBytes()); 328 JNLPFile jnlpFile = new JNLPFile(is, codeBase, new ParserSettings(false, false, false)); 329 Assert.assertEquals(SecurityDesc.RequestedPermissionLevel.NONE, jnlpFile.getRequestedPermissionLevel()); 330 } 331 332 @Test 333 public void testGetRequestedPermissionLevel5() throws MalformedURLException, ParseException { 334 String jnlpContents = minimalJnlp.replace("SECURITY", "<security><"+SecurityDesc.RequestedPermissionLevel.J2EE.toJnlpString()+"/></security>"); 335 336 URL codeBase = new URL("http://icedtea.classpath.org"); 337 InputStream is = new ByteArrayInputStream(jnlpContents.getBytes()); 338 JNLPFile jnlpFile = new JNLPFile(is, codeBase, new ParserSettings(false, false, false)); 339 Assert.assertEquals(SecurityDesc.RequestedPermissionLevel.J2EE, jnlpFile.getRequestedPermissionLevel()); 340 } 341 342 @Test 343 //unknown for jnlp 344 public void testGetRequestedPermissionLevel6() throws MalformedURLException, ParseException { 345 String jnlpContents = minimalJnlp.replace("SECURITY", "<security><" + SecurityDesc.RequestedPermissionLevel.SANDBOX.toHtmlString() + "/></security>"); 346 347 URL codeBase = new URL("http://icedtea.classpath.org"); 348 InputStream is = new ByteArrayInputStream(jnlpContents.getBytes()); 349 JNLPFile jnlpFile = new JNLPFile(is, codeBase, new ParserSettings(false, false, false)); 350 Assert.assertEquals(SecurityDesc.RequestedPermissionLevel.NONE, jnlpFile.getRequestedPermissionLevel()); 351 } 352 353 @Test 354 //unknown for jnlp 355 public void testGetRequestedPermissionLevel7() throws MalformedURLException, ParseException { 356 String jnlpContents = minimalJnlp.replace("SECURITY", "<security><" + SecurityDesc.RequestedPermissionLevel.DEFAULT.toHtmlString() + "/></security>"); 357 358 URL codeBase = new URL("http://icedtea.classpath.org"); 359 InputStream is = new ByteArrayInputStream(jnlpContents.getBytes()); 360 JNLPFile jnlpFile = new JNLPFile(is, codeBase, new ParserSettings(false, false, false)); 361 Assert.assertEquals(SecurityDesc.RequestedPermissionLevel.NONE, jnlpFile.getRequestedPermissionLevel()); 362 } 106 363 } -
trunk/icedtea-web/tests/netx/unit/net/sourceforge/jnlp/JNLPMatcherTest.java
r418 r429 72 72 "Testing by calling JNLPMatcher.match() multiple times. Checking to see if the returns value is consistent" }; 73 73 74 final ClassLoader cl = JNLPMatcherTest.class.getClassLoader();74 final ClassLoader cl = ClassLoader.getSystemClassLoader(); 75 75 76 76 private InputStreamReader getLaunchReader() { … … 467 467 } 468 468 469 @Test (timeout= 1000 /*ms*/)469 @Test (timeout=5000 /*ms*/) 470 470 public void testIsMatchDoesNotHangOnLargeData() throws JNLPMatcherException { 471 471 /* construct an alphabet containing characters 'a' to 'z' */ -
trunk/icedtea-web/tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java
r348 r429 38 38 package net.sourceforge.jnlp; 39 39 40 import java.io.ByteArrayInputStream;41 40 import java.io.InputStream; 42 41 import java.util.List; 43 44 import org.junit.After; 42 import net.sourceforge.jnlp.mock.DummyJNLPFile; 43 import net.sourceforge.jnlp.util.logging.NoStdOutErrTest; 44 45 45 import org.junit.Assert; 46 import org.junit.Before;47 46 import org.junit.BeforeClass; 48 47 import org.junit.Test; 49 48 50 49 /** Test that the parser works with basic jnlp files */ 51 public class ParserBasic {50 public class ParserBasic extends NoStdOutErrTest{ 52 51 53 52 private static Node root; … … 60 59 cl = ClassLoader.getSystemClassLoader(); 61 60 } 61 ParserSettings defaultParser = new ParserSettings(); 62 62 InputStream jnlpStream = cl.getResourceAsStream("net/sourceforge/jnlp/basic.jnlp"); 63 root = Parser.getRootNode(jnlpStream );64 parser = new Parser(n ull, null, root, false, false);63 root = Parser.getRootNode(jnlpStream, defaultParser); 64 parser = new Parser(new DummyJNLPFile(), null, root, defaultParser); 65 65 } 66 66 -
trunk/icedtea-web/tests/netx/unit/net/sourceforge/jnlp/ParserCornerCases.java
r418 r429 51 51 /** Test various corner cases of the parser */ 52 52 public class ParserCornerCases { 53 private static final ParserSettings defaultParser = new ParserSettings(false, true,true); 53 54 54 55 @Test … … 64 65 Assert.assertTrue(target.getContent().contains("<entry key=\"key\">value</entry>")); 65 66 66 Node node = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );67 Node node = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 67 68 Assert.assertEquals("argument", node.getNodeName()); 68 69 String contents = node.getNodeValue(); … … 84 85 XMLElement elem = new XMLElement(); 85 86 elem.parseFromReader(new StringReader(data)); 86 XMLElement target = ( XMLElement) ((XMLElement)elem.enumerateChildren().nextElement()).enumerateChildren().nextElement();87 XMLElement target = (elem.enumerateChildren().nextElement()).enumerateChildren().nextElement(); 87 88 Assert.assertEquals("argument", target.getName()); 88 89 Assert.assertTrue("too small", target.getContent().length() > 20); … … 91 92 Assert.assertTrue(target.getContent().contains("<entry key=\"key\">value</entry>")); 92 93 93 Node node = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );94 Node node = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 94 95 node = node.getFirstChild().getFirstChild(); 95 96 Assert.assertEquals("argument", node.getNodeName()); … … 127 128 public void testUnsupportedSpecNumber() throws ParseException { 128 129 String malformedJnlp = "<?xml?><jnlp spec='11.11'></jnlp>"; 129 Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()) );130 Parser parser = new Parser(null, null, root, false, false);130 Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), defaultParser); 131 Parser parser = new Parser(null, null, root, defaultParser); 131 132 Assert.assertEquals("11.11", parser.getSpecVersion().toString()); 132 133 } … … 135 136 public void testApplicationAndComponent() throws ParseException { 136 137 String malformedJnlp = "<?xml?><jnlp><application-desc/><component-desc/></jnlp>"; 137 Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()) );138 Parser parser = new Parser(null, null, root, false, false);138 Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), defaultParser); 139 Parser parser = new Parser(null, null, root, defaultParser); 139 140 Assert.assertNotNull(parser.getLauncher(root)); 140 141 } … … 143 144 public void testCommentInElements() throws ParseException { 144 145 String malformedJnlp = "<?xml?><jnlp spec='1.0' <!-- comment -->> </jnlp>"; 145 Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()) );146 Parser p = new Parser(null, null, root, false, false);146 Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), defaultParser); 147 Parser p = new Parser(null, null, root, defaultParser); 147 148 Assert.assertEquals("1.0", p.getSpecVersion().toString()); 148 }149 150 @Test151 public void testCommentInElements2() throws ParseException {152 String malformedJnlp = "<?xml?><jnlp <!-- comment --> spec='1.0'> </jnlp>";153 Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()));154 Parser p = new Parser(null, null, root, false, false);155 Assert.assertEquals("1.0", p.getSpecVersion().toString());156 }157 158 @Test159 @KnownToFail160 public void testCommentInAttributes() throws ParseException {161 String malformedJnlp = "<?xml?><jnlp spec='<!-- something -->'></jnlp>";162 Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()));163 Parser p = new Parser(null, null, root, false, false);164 Assert.assertEquals("<!-- something -->", p.getSpecVersion().toString());165 149 } 166 150 … … 172 156 "<!-- outer <!-- inner --> -->" + 173 157 "</description></information></jnlp>"; 174 Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()) );175 Parser p = new Parser(null, null, root, false, false);158 Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), defaultParser); 159 Parser p = new Parser(null, null, root, defaultParser); 176 160 Assert.assertEquals(" -->", p.getInfo(root).get(0).getDescription()); 177 161 } … … 187 171 " <information/>" + 188 172 "</jnlp>"; 189 Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes())); 190 Parser p = new Parser(null, null, root, false, false); 191 } 192 173 Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), defaultParser); 174 Parser p = new Parser(null, null, root, defaultParser); 175 } 176 177 178 @Test 179 public void testCommentInElements2() throws ParseException { 180 String malformedJnlp = "<?xml?><jnlp <!-- comment --> spec='1.0'> </jnlp>"; 181 Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), new ParserSettings(false, true,true)); 182 Parser p = new Parser(null, null, root, defaultParser); 183 //defaultis used 184 Assert.assertEquals("1.0+", p.getSpecVersion().toString()); 185 } 186 187 @Test 188 public void testCommentInElements2_malformedOff() throws ParseException { 189 String malformedJnlp = "<?xml?><jnlp <!-- comment --> spec='1.0'> </jnlp>"; 190 Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), new ParserSettings(false, true,false)); 191 Parser p = new Parser(null, null, root, defaultParser); 192 Assert.assertEquals("1.0", p.getSpecVersion().toString()); 193 } 194 @Test 195 public void testCommentInAttributes() throws ParseException { 196 String malformedJnlp = "<?xml?><jnlp spec='<!-- something -->'></jnlp>"; 197 Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), new ParserSettings(false, true,true)); 198 Parser p = new Parser(null, null, root, defaultParser); 199 Assert.assertEquals("<!-- something -->", p.getSpecVersion().toString()); 200 } 201 202 203 @Test 204 public void testCommentInAttributes_malformedOff() throws ParseException { 205 String malformedJnlp = "<?xml?><jnlp spec='<!-- something -->'></jnlp>"; 206 Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), new ParserSettings(false, true,false)); 207 Parser p = new Parser(null, null, root, defaultParser); 208 //defaultis used 209 Assert.assertEquals("1.0+", p.getSpecVersion().toString()); 210 } 193 211 } -
trunk/icedtea-web/tests/netx/unit/net/sourceforge/jnlp/ParserMalformedXml.java
r418 r429 52 52 53 53 private static String originalJnlp = null; 54 private static ParserSettings lenientParserSettings = new ParserSettings(false, true, true); 54 55 55 56 @BeforeClass … … 72 73 public void testMissingXmlDecleration() throws ParseException { 73 74 String malformedJnlp = originalJnlp.replaceFirst("<\\?xml.*\\?>", ""); 74 Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()) );75 Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), lenientParserSettings); 75 76 } 76 77 … … 79 80 public void testMalformedArguments() throws ParseException { 80 81 String malformedJnlp = originalJnlp.replace("arg2</argument", "arg2<argument"); 81 Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()) );82 Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), lenientParserSettings); 82 83 } 83 84 84 85 @Test 85 @KnownToFail86 86 public void testTagNotClosed() throws ParseException { 87 87 String malformedJnlp = originalJnlp.replace("</jnlp>", "<jnlp>"); 88 Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()) );88 Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), lenientParserSettings); 89 89 } 90 90 91 91 @Test 92 @KnownToFail93 92 public void testUnquotedAttributes() throws ParseException { 94 93 String malformedJnlp = originalJnlp.replace("'jnlp.jnlp'", "jnlp.jnlp"); 95 Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes())); 94 Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), lenientParserSettings); 95 } 96 97 @Test(expected = ParseException.class) 98 public void testTagNotClosedNoTagSoup() throws ParseException { 99 String malformedJnlp = originalJnlp.replace("</jnlp>", "<jnlp>"); 100 Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), new ParserSettings(false, true, false)); 101 } 102 103 @Test(expected = ParseException.class) 104 public void testUnquotedAttributesNoTagSoup() throws ParseException { 105 String malformedJnlp = originalJnlp.replace("'jnlp.jnlp'", "jnlp.jnlp"); 106 Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), new ParserSettings(false, true, false)); 96 107 } 97 108 -
trunk/icedtea-web/tests/netx/unit/net/sourceforge/jnlp/ParserTest.java
r418 r429 39 39 40 40 import java.io.ByteArrayInputStream; 41 import java.net.URL; 41 42 import java.util.ArrayList; 42 43 import java.util.List; … … 58 59 private static final Locale ALL_LOCALE = new Locale(LANG, COUNTRY, VARIANT); 59 60 61 ParserSettings defaultParser=new ParserSettings(); 60 62 @Test(expected = MissingInformationException.class) 61 63 public void testMissingInfoFullLocale() throws ParseException { 62 64 String data = "<jnlp></jnlp>\n"; 63 65 64 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );65 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 66 67 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 68 Parser parser = new Parser(file, null, root, false, false);66 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 67 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 68 69 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 70 Parser parser = new Parser(file, null, root, defaultParser); 69 71 parser.getInfo(root); 70 72 } … … 77 79 + "</jnlp>\n"; 78 80 79 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );80 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 81 82 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 83 Parser parser = new Parser(file, null, root, false, false);81 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 82 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 83 84 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 85 Parser parser = new Parser(file, null, root, defaultParser); 84 86 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 85 87 infoDescs.addAll(parser.getInfo(root)); … … 100 102 + "</jnlp>\n"; 101 103 102 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );103 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 104 105 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 106 Parser parser = new Parser(file, null, root, false, false);104 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 105 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 106 107 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 108 Parser parser = new Parser(file, null, root, defaultParser); 107 109 List<InformationDesc> infoDescs = parser.getInfo(root); 108 110 … … 130 132 + "</jnlp>\n"; 131 133 132 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );133 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 134 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 135 Parser parser = new Parser(file, null, root, false, false);134 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 135 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 136 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 137 Parser parser = new Parser(file, null, root, defaultParser); 136 138 List<InformationDesc> infoDescs = parser.getInfo(root); 137 139 Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); … … 157 159 + "</jnlp>\n"; 158 160 159 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );160 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 161 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 162 Parser parser = new Parser(file, null, root, false, false);161 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 162 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 163 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 164 Parser parser = new Parser(file, null, root, defaultParser); 163 165 List<InformationDesc> infoDescs = parser.getInfo(root); 164 166 Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); … … 180 182 + "</jnlp>\n"; 181 183 182 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );183 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 184 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 185 Parser parser = new Parser(file, null, root, false, false);184 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 185 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 186 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 187 Parser parser = new Parser(file, null, root, defaultParser); 186 188 List<InformationDesc> infoDescs = parser.getInfo(root); 187 189 Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); … … 211 213 + "</jnlp>\n"; 212 214 213 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );214 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 215 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 216 Parser parser = new Parser(file, null, root, false, false);215 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 216 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 217 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 218 Parser parser = new Parser(file, null, root, defaultParser); 217 219 List<InformationDesc> infoDescs = parser.getInfo(root); 218 220 Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); … … 242 244 + "</jnlp>\n"; 243 245 244 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );245 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 246 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 247 Parser parser = new Parser(file, null, root, false, false);246 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 247 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 248 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 249 Parser parser = new Parser(file, null, root, defaultParser); 248 250 List<InformationDesc> infoDescs = parser.getInfo(root); 249 251 Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); … … 272 274 + "</jnlp>\n"; 273 275 274 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );275 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 276 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 277 Parser parser = new Parser(file, null, root, false, false);276 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 277 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 278 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 279 Parser parser = new Parser(file, null, root, defaultParser); 278 280 List<InformationDesc> infoDescs = parser.getInfo(root); 279 281 Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); … … 301 303 + "</jnlp>\n"; 302 304 303 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );304 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 305 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 306 Parser parser = new Parser(file, null, root, false, false);305 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 306 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 307 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 308 Parser parser = new Parser(file, null, root, defaultParser); 307 309 List<InformationDesc> infoDescs = parser.getInfo(root); 308 310 Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); … … 329 331 + "</jnlp>\n"; 330 332 331 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );332 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 333 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 334 Parser parser = new Parser(file, null, root, false, false);333 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 334 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 335 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 336 Parser parser = new Parser(file, null, root, defaultParser); 335 337 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 336 338 infoDescs.addAll(parser.getInfo(root)); … … 356 358 + "</jnlp>\n"; 357 359 358 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );359 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 360 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 361 Parser parser = new Parser(file, null, root, false, false);360 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 361 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 362 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 363 Parser parser = new Parser(file, null, root, defaultParser); 362 364 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 363 365 infoDescs.addAll(parser.getInfo(root)); … … 380 382 + "</jnlp>\n"; 381 383 382 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );383 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 384 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 385 Parser parser = new Parser(file, null, root, false, false);384 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 385 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 386 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 387 Parser parser = new Parser(file, null, root, defaultParser); 386 388 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 387 389 infoDescs.addAll(parser.getInfo(root)); … … 404 406 + "</jnlp>\n"; 405 407 406 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );407 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 408 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 409 Parser parser = new Parser(file, null, root, false, false);408 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 409 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 410 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 411 Parser parser = new Parser(file, null, root, defaultParser); 410 412 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 411 413 infoDescs.addAll(parser.getInfo(root)); … … 426 428 + "</jnlp>\n"; 427 429 428 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );429 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 430 431 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 432 Parser parser = new Parser(file, null, root, false, false);430 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 431 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 432 433 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 434 Parser parser = new Parser(file, null, root, defaultParser); 433 435 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 434 436 infoDescs.addAll(parser.getInfo(root)); … … 449 451 + "</jnlp>\n"; 450 452 451 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );452 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 453 454 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 455 Parser parser = new Parser(file, null, root, false, false);453 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 454 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 455 456 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 457 Parser parser = new Parser(file, null, root, defaultParser); 456 458 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 457 459 infoDescs.addAll(parser.getInfo(root)); … … 488 490 + "</jnlp>\n"; 489 491 490 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );491 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 492 493 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 494 Parser parser = new Parser(file, null, root, false, false);492 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 493 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 494 495 MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); 496 Parser parser = new Parser(file, null, root, defaultParser); 495 497 List<InformationDesc> infoDescs = parser.getInfo(root); 496 498 … … 511 513 String data = "<jnlp></jnlp>\n"; 512 514 513 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );514 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 515 516 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 517 Parser parser = new Parser(file, null, root, false, false);515 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 516 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 517 518 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 519 Parser parser = new Parser(file, null, root, defaultParser); 518 520 parser.getInfo(root); 519 521 } … … 526 528 + "</jnlp>\n"; 527 529 528 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );529 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 530 531 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 532 Parser parser = new Parser(file, null, root, false, false);530 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 531 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 532 533 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 534 Parser parser = new Parser(file, null, root, defaultParser); 533 535 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 534 536 infoDescs.addAll(parser.getInfo(root)); … … 549 551 + "</jnlp>\n"; 550 552 551 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );552 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 553 554 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 555 Parser parser = new Parser(file, null, root, false, false);553 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 554 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 555 556 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 557 Parser parser = new Parser(file, null, root, defaultParser); 556 558 List<InformationDesc> infoDescs = parser.getInfo(root); 557 559 … … 575 577 + "</jnlp>\n"; 576 578 577 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );578 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 579 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 580 Parser parser = new Parser(file, null, root, false, false);579 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 580 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 581 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 582 Parser parser = new Parser(file, null, root, defaultParser); 581 583 List<InformationDesc> infoDescs = parser.getInfo(root); 582 584 Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); … … 602 604 + "</jnlp>\n"; 603 605 604 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );605 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 606 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 607 Parser parser = new Parser(file, null, root, false, false);606 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 607 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 608 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 609 Parser parser = new Parser(file, null, root, defaultParser); 608 610 List<InformationDesc> infoDescs = parser.getInfo(root); 609 611 Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); … … 625 627 + "</jnlp>\n"; 626 628 627 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );628 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 629 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 630 Parser parser = new Parser(file, null, root, false, false);629 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 630 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 631 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 632 Parser parser = new Parser(file, null, root, defaultParser); 631 633 List<InformationDesc> infoDescs = parser.getInfo(root); 632 634 Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); … … 656 658 + "</jnlp>\n"; 657 659 658 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );659 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 660 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 661 Parser parser = new Parser(file, null, root, false, false);660 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 661 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 662 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 663 Parser parser = new Parser(file, null, root, defaultParser); 662 664 List<InformationDesc> infoDescs = parser.getInfo(root); 663 665 Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); … … 687 689 + "</jnlp>\n"; 688 690 689 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );690 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 691 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 692 Parser parser = new Parser(file, null, root, false, false);691 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 692 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 693 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 694 Parser parser = new Parser(file, null, root, defaultParser); 693 695 List<InformationDesc> infoDescs = parser.getInfo(root); 694 696 Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); … … 717 719 + "</jnlp>\n"; 718 720 719 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );720 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 721 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 722 Parser parser = new Parser(file, null, root, false, false);721 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 722 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 723 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 724 Parser parser = new Parser(file, null, root, defaultParser); 723 725 List<InformationDesc> infoDescs = parser.getInfo(root); 724 726 Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); … … 746 748 + "</jnlp>\n"; 747 749 748 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );749 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 750 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 751 Parser parser = new Parser(file, null, root, false, false);750 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 751 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 752 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 753 Parser parser = new Parser(file, null, root, defaultParser); 752 754 List<InformationDesc> infoDescs = parser.getInfo(root); 753 755 Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); … … 774 776 + "</jnlp>\n"; 775 777 776 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );777 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 778 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 779 Parser parser = new Parser(file, null, root, false, false);778 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 779 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 780 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 781 Parser parser = new Parser(file, null, root, defaultParser); 780 782 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 781 783 infoDescs.addAll(parser.getInfo(root)); … … 801 803 + "</jnlp>\n"; 802 804 803 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );804 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 805 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 806 Parser parser = new Parser(file, null, root, false, false);805 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 806 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 807 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 808 Parser parser = new Parser(file, null, root, defaultParser); 807 809 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 808 810 infoDescs.addAll(parser.getInfo(root)); … … 825 827 + "</jnlp>\n"; 826 828 827 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );828 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 829 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 830 Parser parser = new Parser(file, null, root, false, false);829 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 830 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 831 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 832 Parser parser = new Parser(file, null, root, defaultParser); 831 833 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 832 834 infoDescs.addAll(parser.getInfo(root)); … … 849 851 + "</jnlp>\n"; 850 852 851 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );852 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 853 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 854 Parser parser = new Parser(file, null, root, false, false);853 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 854 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 855 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 856 Parser parser = new Parser(file, null, root, defaultParser); 855 857 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 856 858 infoDescs.addAll(parser.getInfo(root)); … … 871 873 + "</jnlp>\n"; 872 874 873 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );874 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 875 876 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 877 Parser parser = new Parser(file, null, root, false, false);875 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 876 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 877 878 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 879 Parser parser = new Parser(file, null, root, defaultParser); 878 880 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 879 881 infoDescs.addAll(parser.getInfo(root)); … … 894 896 + "</jnlp>\n"; 895 897 896 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );897 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 898 899 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 900 Parser parser = new Parser(file, null, root, false, false);898 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 899 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 900 901 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 902 Parser parser = new Parser(file, null, root, defaultParser); 901 903 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 902 904 infoDescs.addAll(parser.getInfo(root)); … … 933 935 + "</jnlp>\n"; 934 936 935 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );936 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 937 938 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 939 Parser parser = new Parser(file, null, root, false, false);937 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 938 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 939 940 MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); 941 Parser parser = new Parser(file, null, root, defaultParser); 940 942 List<InformationDesc> infoDescs = parser.getInfo(root); 941 943 … … 956 958 String data = "<jnlp></jnlp>\n"; 957 959 958 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );959 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 960 961 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 962 Parser parser = new Parser(file, null, root, false, false);960 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 961 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 962 963 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 964 Parser parser = new Parser(file, null, root, defaultParser); 963 965 parser.getInfo(root); 964 966 } … … 971 973 + "</jnlp>\n"; 972 974 973 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );974 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 975 976 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 977 Parser parser = new Parser(file, null, root, false, false);975 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 976 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 977 978 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 979 Parser parser = new Parser(file, null, root, defaultParser); 978 980 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 979 981 infoDescs.addAll(parser.getInfo(root)); … … 994 996 + "</jnlp>\n"; 995 997 996 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );997 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 998 999 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1000 Parser parser = new Parser(file, null, root, false, false);998 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 999 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1000 1001 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1002 Parser parser = new Parser(file, null, root, defaultParser); 1001 1003 List<InformationDesc> infoDescs = parser.getInfo(root); 1002 1004 … … 1016 1018 + "</jnlp>\n"; 1017 1019 1018 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );1019 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1020 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1021 Parser parser = new Parser(file, null, root, false, false);1020 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 1021 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1022 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1023 Parser parser = new Parser(file, null, root, defaultParser); 1022 1024 List<InformationDesc> infoDescs = parser.getInfo(root); 1023 1025 Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); … … 1040 1042 + "</jnlp>\n"; 1041 1043 1042 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );1043 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1044 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1045 Parser parser = new Parser(file, null, root, false, false);1044 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 1045 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1046 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1047 Parser parser = new Parser(file, null, root, defaultParser); 1046 1048 List<InformationDesc> infoDescs = parser.getInfo(root); 1047 1049 Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); … … 1063 1065 + "</jnlp>\n"; 1064 1066 1065 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );1066 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1067 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1068 Parser parser = new Parser(file, null, root, false, false);1067 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 1068 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1069 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1070 Parser parser = new Parser(file, null, root, defaultParser); 1069 1071 List<InformationDesc> infoDescs = parser.getInfo(root); 1070 1072 Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); … … 1094 1096 + "</jnlp>\n"; 1095 1097 1096 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );1097 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1098 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1099 Parser parser = new Parser(file, null, root, false, false);1098 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 1099 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1100 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1101 Parser parser = new Parser(file, null, root, defaultParser); 1100 1102 List<InformationDesc> infoDescs = parser.getInfo(root); 1101 1103 Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); … … 1125 1127 + "</jnlp>\n"; 1126 1128 1127 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );1128 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1129 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1130 Parser parser = new Parser(file, null, root, false, false);1129 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 1130 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1131 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1132 Parser parser = new Parser(file, null, root, defaultParser); 1131 1133 List<InformationDesc> infoDescs = parser.getInfo(root); 1132 1134 Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); … … 1151 1153 + "</jnlp>\n"; 1152 1154 1153 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );1154 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1155 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1156 Parser parser = new Parser(file, null, root, false, false);1155 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 1156 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1157 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1158 Parser parser = new Parser(file, null, root, defaultParser); 1157 1159 List<InformationDesc> infoDescs = parser.getInfo(root); 1158 1160 Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); … … 1179 1181 + "</jnlp>\n"; 1180 1182 1181 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );1182 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1183 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1184 Parser parser = new Parser(file, null, root, false, false);1183 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 1184 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1185 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1186 Parser parser = new Parser(file, null, root, defaultParser); 1185 1187 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 1186 1188 infoDescs.addAll(parser.getInfo(root)); … … 1206 1208 + "</jnlp>\n"; 1207 1209 1208 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );1209 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1210 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1211 Parser parser = new Parser(file, null, root, false, false);1210 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 1211 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1212 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1213 Parser parser = new Parser(file, null, root, defaultParser); 1212 1214 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 1213 1215 infoDescs.addAll(parser.getInfo(root)); … … 1230 1232 + "</jnlp>\n"; 1231 1233 1232 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );1233 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1234 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1235 Parser parser = new Parser(file, null, root, false, false);1234 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 1235 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1236 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1237 Parser parser = new Parser(file, null, root, defaultParser); 1236 1238 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 1237 1239 infoDescs.addAll(parser.getInfo(root)); … … 1254 1256 + "</jnlp>\n"; 1255 1257 1256 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );1257 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1258 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1259 Parser parser = new Parser(file, null, root, false, false);1258 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 1259 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1260 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1261 Parser parser = new Parser(file, null, root, defaultParser); 1260 1262 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 1261 1263 infoDescs.addAll(parser.getInfo(root)); … … 1276 1278 + "</jnlp>\n"; 1277 1279 1278 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );1279 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1280 1281 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1282 Parser parser = new Parser(file, null, root, false, false);1280 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 1281 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1282 1283 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1284 Parser parser = new Parser(file, null, root, defaultParser); 1283 1285 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 1284 1286 infoDescs.addAll(parser.getInfo(root)); … … 1299 1301 + "</jnlp>\n"; 1300 1302 1301 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );1302 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1303 1304 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1305 Parser parser = new Parser(file, null, root, false, false);1303 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 1304 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1305 1306 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1307 Parser parser = new Parser(file, null, root, defaultParser); 1306 1308 List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); 1307 1309 infoDescs.addAll(parser.getInfo(root)); … … 1338 1340 + "</jnlp>\n"; 1339 1341 1340 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()) );1341 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1342 1343 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1344 Parser parser = new Parser(file, null, root, false, false);1342 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 1343 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1344 1345 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1346 Parser parser = new Parser(file, null, root, defaultParser); 1345 1347 List<InformationDesc> infoDescs = parser.getInfo(root); 1346 1348 … … 1356 1358 parser.checkForInformation(); 1357 1359 } 1360 1361 @Test 1362 public void testOverwrittenCodebaseWithValidJnlpCodebase() throws Exception { 1363 String data = "<?xml version=\"1.0\"?>\n" + 1364 "<jnlp spec=\"1.5+\"\n" + 1365 "href=\"EmbeddedJnlpFile.jnlp\"\n" + 1366 "codebase=\"http://www.redhat.com/\"\n" + 1367 ">\n" + 1368 "</jnlp>"; 1369 1370 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 1371 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1372 URL overwrittenCodebase = new URL("http://icedtea.classpath.org"); 1373 1374 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1375 Parser parser = new Parser(file, null, root, defaultParser, overwrittenCodebase); 1376 1377 Assert.assertEquals("http://www.redhat.com/", parser.getCodeBase().toExternalForm()); 1378 } 1379 1380 @Test 1381 public void testOverwrittenCodebaseWithInvalidJnlpCodebase() throws Exception { 1382 String data = "<?xml version=\"1.0\"?>\n" + 1383 "<jnlp spec=\"1.5+\"\n" + 1384 "href=\"EmbeddedJnlpFile.jnlp\"\n" + 1385 "codebase=\"this codebase is incorrect\"\n" + 1386 ">\n" + 1387 "</jnlp>"; 1388 1389 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 1390 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1391 URL overwrittenCodebase = new URL("http://icedtea.classpath.org"); 1392 1393 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1394 Parser parser = new Parser(file, null, root, defaultParser, overwrittenCodebase); 1395 1396 Assert.assertEquals(overwrittenCodebase.toExternalForm(), parser.getCodeBase().toExternalForm()); 1397 } 1398 1399 @Test 1400 public void testOverwrittenCodebaseWithNoJnlpCodebase() throws Exception { 1401 String data = "<?xml version=\"1.0\"?>\n" + 1402 "<jnlp spec=\"1.5+\"\n" + 1403 "href=\"EmbeddedJnlpFile.jnlp\"\n" + 1404 ">\n" + 1405 "</jnlp>"; 1406 1407 Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); 1408 Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); 1409 URL overwrittenCodebase = new URL("http://icedtea.classpath.org"); 1410 1411 MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); 1412 Parser parser = new Parser(file, null, root, defaultParser, overwrittenCodebase); 1413 1414 Assert.assertEquals(overwrittenCodebase.toExternalForm(), parser.getCodeBase().toExternalForm()); 1415 } 1358 1416 } -
trunk/icedtea-web/tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java
r418 r429 28 28 import java.net.MalformedURLException; 29 29 import java.net.URL; 30 import java.util.ArrayList; 30 31 import java.util.HashMap; 32 import java.util.Map; 31 33 import java.util.Hashtable; 34 import java.util.List; 32 35 33 36 import net.sourceforge.jnlp.cache.UpdatePolicy; 37 import net.sourceforge.jnlp.util.replacements.BASE64Encoder; 38 import org.junit.Assert; 34 39 35 40 import org.junit.Test; … … 44 49 } 45 50 46 public JNLPFile create(URL location, Version version, boolean strict, 51 @Override 52 public JNLPFile create(URL location, Version version, ParserSettings settings, 47 53 UpdatePolicy policy, URL forceCodebase) throws IOException, ParseException { 48 54 JNLPHref = location; … … 61 67 } 62 68 69 static private PluginParameters createValidParamObject() { 70 Map<String, String> params = new HashMap<String, String>(); 71 params.put("code", ""); // Avoids an exception being thrown 72 return new PluginParameters(params); 73 } 74 63 75 @Test 64 76 public void testAbsoluteJNLPHref() throws MalformedURLException, Exception { 65 77 URL codeBase = new URL("http://undesired.absolute.codebase.com"); 66 78 String absoluteLocation = "http://absolute.href.com/test.jnlp"; 67 Hashtable<String, String> atts = new Hashtable<String, String>();68 atts.put("jnlp_href", absoluteLocation);69 MockJNLPCreator mockCreator = new MockJNLPCreator(); 70 PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, atts, "", mockCreator);79 PluginParameters params = createValidParamObject(); 80 params.put("jnlp_href", absoluteLocation); 81 MockJNLPCreator mockCreator = new MockJNLPCreator(); 82 PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, params, mockCreator); 71 83 assertEquals(absoluteLocation, mockCreator.getJNLPHref().toExternalForm()); 72 84 } … … 76 88 URL codeBase = new URL("http://desired.absolute.codebase.com/"); 77 89 String relativeLocation = "sub/dir/test.jnlp"; 78 Hashtable<String, String> atts = new Hashtable<String, String>();79 atts.put("jnlp_href", relativeLocation);80 MockJNLPCreator mockCreator = new MockJNLPCreator(); 81 PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, atts, "", mockCreator);90 PluginParameters params = createValidParamObject(); 91 params.put("jnlp_href", relativeLocation); 92 MockJNLPCreator mockCreator = new MockJNLPCreator(); 93 PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, params, mockCreator); 82 94 assertEquals(codeBase.toExternalForm() + relativeLocation, 83 95 mockCreator.getJNLPHref().toExternalForm()); 84 96 } 85 97 … … 89 101 URL codeBase = new URL(desiredDomain + "/undesired/sub/dir"); 90 102 String relativeLocation = "/app/test/test.jnlp"; 91 Hashtable<String, String> atts = new Hashtable<String, String>();92 atts.put("jnlp_href", relativeLocation);93 MockJNLPCreator mockCreator = new MockJNLPCreator(); 94 PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, atts, "", mockCreator);103 PluginParameters params = createValidParamObject(); 104 params.put("jnlp_href", relativeLocation); 105 MockJNLPCreator mockCreator = new MockJNLPCreator(); 106 PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, params, mockCreator); 95 107 assertEquals(desiredDomain + relativeLocation, 96 mockCreator.getJNLPHref().toExternalForm()); 97 } 98 108 mockCreator.getJNLPHref().toExternalForm()); 109 } 110 111 @Test 112 public void testGetRequestedPermissionLevel() throws MalformedURLException, Exception { 113 String desiredDomain = "http://desired.absolute.codebase.com"; 114 URL codeBase = new URL(desiredDomain + "/undesired/sub/dir"); 115 String relativeLocation = "/app/test/test.jnlp"; 116 PluginParameters params = createValidParamObject(); 117 params.put("jnlp_href", relativeLocation); 118 MockJNLPCreator mockCreator = new MockJNLPCreator(); 119 PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, params, mockCreator); 120 assertEquals(pb.getRequestedPermissionLevel(), SecurityDesc.RequestedPermissionLevel.NONE); 121 122 params.put(SecurityDesc.RequestedPermissionLevel.PERMISSIONS_NAME,SecurityDesc.RequestedPermissionLevel.ALL.toHtmlString()); 123 pb = new PluginBridge(codeBase, null, "", "", 0, 0, params, mockCreator); 124 assertEquals(pb.getRequestedPermissionLevel(), SecurityDesc.RequestedPermissionLevel.ALL); 125 126 //unknown for applets! 127 params.put(SecurityDesc.RequestedPermissionLevel.PERMISSIONS_NAME, SecurityDesc.RequestedPermissionLevel.J2EE.toJnlpString()); 128 pb = new PluginBridge(codeBase, null, "", "", 0, 0, params, mockCreator); 129 assertEquals(pb.getRequestedPermissionLevel(), SecurityDesc.RequestedPermissionLevel.NONE); 130 131 params.put(SecurityDesc.RequestedPermissionLevel.PERMISSIONS_NAME, SecurityDesc.RequestedPermissionLevel.SANDBOX.toHtmlString()); 132 pb = new PluginBridge(codeBase, null, "", "", 0, 0, params, mockCreator); 133 assertEquals(pb.getRequestedPermissionLevel(), SecurityDesc.RequestedPermissionLevel.SANDBOX); 134 135 params.put(SecurityDesc.RequestedPermissionLevel.PERMISSIONS_NAME, SecurityDesc.RequestedPermissionLevel.DEFAULT.toHtmlString()); 136 pb = new PluginBridge(codeBase, null, "", "", 0, 0, params, mockCreator); 137 assertEquals(pb.getRequestedPermissionLevel(), SecurityDesc.RequestedPermissionLevel.NONE); 138 } 139 140 @Test 141 public void testBase64StringDecoding() throws Exception { 142 String actualFile = "This is a sample string that will be encoded to" + 143 "a Base64 string and then decoded using PluginBridge's" + 144 "decoding method and compared."; 145 146 BASE64Encoder encoder = new BASE64Encoder(); 147 String encodedFile = encoder.encodeBuffer(actualFile.getBytes()); 148 149 byte[] decodedBytes = PluginBridge.decodeBase64String(encodedFile); 150 String decodedString = new String(decodedBytes); 151 Assert.assertEquals(actualFile, decodedString); 152 } 153 154 @Test 155 public void testEmbeddedJnlpWithValidCodebase() throws Exception { 156 URL codeBase = new URL("http://icedtea.classpath.org"); 157 String relativeLocation = "/EmbeddedJnlpFile.jnlp"; 158 159 //Codebase within jnlp file is VALID 160 /** 161 <?xml version="1.0"?> 162 <jnlp spec="1.5+" 163 href="EmbeddedJnlpFile.jnlp" 164 codebase="http://www.redhat.com" 165 > 166 167 <information> 168 <title>Sample Test</title> 169 <vendor>RedHat</vendor> 170 <offline-allowed/> 171 </information> 172 173 <resources> 174 <j2se version='1.6+' /> 175 <jar href='EmbeddedJnlpJarOne.jar' main='true' /> 176 <jar href='EmbeddedJnlpJarTwo.jar' main='true' /> 177 </resources> 178 179 <applet-desc 180 documentBase="." 181 name="redhat.embeddedjnlp" 182 main-class="redhat.embeddedjnlp" 183 width="0" 184 height="0" 185 /> 186 </jnlp> 187 **/ 188 189 String jnlpFileEncoded = "ICAgICAgICA8P3htbCB2ZXJzaW9uPSIxLjAiPz4NCiAgICAgICAgICAgIDxqbmxwIHNwZWM9IjEu" + 190 "NSsiIA0KICAgICAgICAgICAgICBocmVmPSJFbWJlZGRlZEpubHBGaWxlLmpubHAiIA0KICAgICAg" + 191 "ICAgICAgICBjb2RlYmFzZT0iaHR0cDovL3d3dy5yZWRoYXQuY29tIiAgICANCiAgICAgICAgICAg" + 192 "ID4NCg0KICAgICAgICAgICAgPGluZm9ybWF0aW9uPg0KICAgICAgICAgICAgICAgIDx0aXRsZT5T" + 193 "YW1wbGUgVGVzdDwvdGl0bGU+DQogICAgICAgICAgICAgICAgPHZlbmRvcj5SZWRIYXQ8L3ZlbmRv" + 194 "cj4NCiAgICAgICAgICAgICAgICA8b2ZmbGluZS1hbGxvd2VkLz4NCiAgICAgICAgICAgIDwvaW5m" + 195 "b3JtYXRpb24+DQoNCiAgICAgICAgICAgIDxyZXNvdXJjZXM+DQogICAgICAgICAgICAgICAgPGoy" + 196 "c2UgdmVyc2lvbj0nMS42KycgLz4NCiAgICAgICAgICAgICAgICA8amFyIGhyZWY9J0VtYmVkZGVk" + 197 "Sm5scEphck9uZS5qYXInIG1haW49J3RydWUnIC8+DQogICAgICAgICAgICAgICAgPGphciBocmVm" + 198 "PSdFbWJlZGRlZEpubHBKYXJUd28uamFyJyBtYWluPSd0cnVlJyAvPg0KICAgICAgICAgICAgPC9y" + 199 "ZXNvdXJjZXM+DQoNCiAgICAgICAgICAgIDxhcHBsZXQtZGVzYw0KICAgICAgICAgICAgICAgIGRv" + 200 "Y3VtZW50QmFzZT0iLiINCiAgICAgICAgICAgICAgICBuYW1lPSJyZWRoYXQuZW1iZWRkZWRqbmxw" + 201 "Ig0KICAgICAgICAgICAgICAgIG1haW4tY2xhc3M9InJlZGhhdC5lbWJlZGRlZGpubHAiDQogICAg" + 202 "ICAgICAgICAgICAgd2lkdGg9IjAiDQogICAgICAgICAgICAgICAgaGVpZ2h0PSIwIg0KICAgICAg" + 203 "ICAgICAgLz4NCiAgICAgICAgICAgIDwvam5scD4="; 204 205 MockJNLPCreator mockCreator = new MockJNLPCreator(); 206 PluginParameters params = createValidParamObject(); 207 params.put("jnlp_href", relativeLocation); 208 params.put("jnlp_embedded", jnlpFileEncoded); 209 210 String jnlpCodebase = "http://www.redhat.com"; 211 PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, params, mockCreator); 212 JARDesc[] jars = pb.getResources().getJARs(); 213 214 //Check if there are two jars cached 215 Assert.assertTrue(jars.length == 2); 216 217 //Resource can be in any order 218 List<String> resourceLocations = new ArrayList<String>(); 219 resourceLocations.add(jars[0].getLocation().toExternalForm()); 220 resourceLocations.add(jars[1].getLocation().toExternalForm()); 221 222 //Check URLs of jars 223 Assert.assertTrue(resourceLocations.contains(jnlpCodebase + "/EmbeddedJnlpJarOne.jar")); 224 Assert.assertTrue((resourceLocations.contains(jnlpCodebase + "/EmbeddedJnlpJarTwo.jar"))); 225 } 226 227 @Test 228 //http://docs.oracle.com/javase/6/docs/technotes/guides/jweb/applet/codebase_determination.html 229 //example 3 230 public void testEmbeddedJnlpWithInvalidCodebase() throws Exception { 231 URL overwrittenCodebase = new URL("http://icedtea.classpath.org"); 232 String relativeLocation = "/EmbeddedJnlpFile.jnlp"; 233 234 //Codebase within jnlp file is INVALID 235 /** 236 <?xml version="1.0"?> 237 <jnlp spec="1.5+" 238 href="EmbeddedJnlpFile.jnlp" 239 codebase="invalidPath" 240 > 241 242 <information> 243 <title>Sample Test</title> 244 <vendor>RedHat</vendor> 245 <offline-allowed/> 246 </information> 247 248 <resources> 249 <j2se version='1.6+' /> 250 <jar href='EmbeddedJnlpJarOne.jar' main='true' /> 251 <jar href='EmbeddedJnlpJarTwo.jar' main='true' /> 252 </resources> 253 254 <applet-desc 255 documentBase="." 256 name="redhat.embeddedjnlp" 257 main-class="redhat.embeddedjnlp" 258 width="0" 259 height="0" 260 /> 261 </jnlp> 262 **/ 263 264 String jnlpFileEncoded = "ICAgICAgICA8P3htbCB2ZXJzaW9uPSIxLjAiPz4NCiAgICAgICAgICAgIDxqbmxwIHNwZWM9IjEu" + 265 "NSsiIA0KICAgICAgICAgICAgICBocmVmPSJFbWJlZGRlZEpubHBGaWxlLmpubHAiIA0KICAgICAg" + 266 "ICAgICAgICBjb2RlYmFzZT0iaW52YWxpZFBhdGgiICAgIA0KICAgICAgICAgICAgPg0KDQogICAg" + 267 "ICAgICAgICA8aW5mb3JtYXRpb24+DQogICAgICAgICAgICAgICAgPHRpdGxlPlNhbXBsZSBUZXN0" + 268 "PC90aXRsZT4NCiAgICAgICAgICAgICAgICA8dmVuZG9yPlJlZEhhdDwvdmVuZG9yPg0KICAgICAg" + 269 "ICAgICAgICAgIDxvZmZsaW5lLWFsbG93ZWQvPg0KICAgICAgICAgICAgPC9pbmZvcm1hdGlvbj4N" + 270 "Cg0KICAgICAgICAgICAgPHJlc291cmNlcz4NCiAgICAgICAgICAgICAgICA8ajJzZSB2ZXJzaW9u" + 271 "PScxLjYrJyAvPg0KICAgICAgICAgICAgICAgIDxqYXIgaHJlZj0nRW1iZWRkZWRKbmxwSmFyT25l" + 272 "LmphcicgbWFpbj0ndHJ1ZScgLz4NCiAgICAgICAgICAgICAgICA8amFyIGhyZWY9J0VtYmVkZGVk" + 273 "Sm5scEphclR3by5qYXInIG1haW49J3RydWUnIC8+DQogICAgICAgICAgICA8L3Jlc291cmNlcz4N" + 274 "Cg0KICAgICAgICAgICAgPGFwcGxldC1kZXNjDQogICAgICAgICAgICAgICAgZG9jdW1lbnRCYXNl" + 275 "PSIuIg0KICAgICAgICAgICAgICAgIG5hbWU9InJlZGhhdC5lbWJlZGRlZGpubHAiDQogICAgICAg" + 276 "ICAgICAgICAgbWFpbi1jbGFzcz0icmVkaGF0LmVtYmVkZGVkam5scCINCiAgICAgICAgICAgICAg" + 277 "ICB3aWR0aD0iMCINCiAgICAgICAgICAgICAgICBoZWlnaHQ9IjAiDQogICAgICAgICAgICAvPg0K" + 278 "ICAgICAgICAgICAgPC9qbmxwPg=="; 279 280 MockJNLPCreator mockCreator = new MockJNLPCreator(); 281 PluginParameters params = createValidParamObject(); 282 params.put("jnlp_href", relativeLocation); 283 params.put("jnlp_embedded", jnlpFileEncoded); 284 285 PluginBridge pb = new PluginBridge(overwrittenCodebase, null, "", "", 0, 0, params, mockCreator); 286 JARDesc[] jars = pb.getResources().getJARs(); 287 288 //Check if there are two jars cached 289 Assert.assertTrue(jars.length == 2); 290 291 //Resource can be in any order 292 List<String> resourceLocations = new ArrayList<String>(); 293 resourceLocations.add(jars[0].getLocation().toExternalForm()); 294 resourceLocations.add(jars[1].getLocation().toExternalForm()); 295 296 //Check URLs of jars 297 Assert.assertTrue(resourceLocations.contains(overwrittenCodebase + "/EmbeddedJnlpJarOne.jar")); 298 Assert.assertTrue((resourceLocations.contains(overwrittenCodebase + "/EmbeddedJnlpJarTwo.jar"))); 299 } 300 301 @Test 302 public void testInvalidEmbeddedJnlp() throws Exception { 303 URL overwrittenCodebase = new URL("http://icedtea.classpath.org"); 304 String relativeLocation = "/EmbeddedJnlpFile.jnlp"; 305 306 //Embedded jnlp is invalid 307 String jnlpFileEncoded = "thisContextIsInvalid"; 308 309 MockJNLPCreator mockCreator = new MockJNLPCreator(); 310 PluginParameters params = createValidParamObject(); 311 params.put("jnlp_href", relativeLocation); 312 params.put("jnlp_embedded", jnlpFileEncoded); 313 314 try { 315 new PluginBridge(overwrittenCodebase, null, "", "", 0, 0, params, mockCreator); 316 } catch (Exception e) { 317 return; 318 } 319 Assert.fail("PluginBridge was successfully created with an invalid embedded jnlp value"); 320 } 99 321 } -
trunk/icedtea-web/tests/netx/unit/net/sourceforge/jnlp/cache/CacheLRUWrapperTest.java
r418 r429 43 43 import net.sourceforge.jnlp.ServerAccess; 44 44 45 import net.sourceforge.jnlp. config.DeploymentConfiguration;46 import net.sourceforge.jnlp.runtime.JNLPRuntime;45 import net.sourceforge.jnlp.util.PropertiesFile; 46 import org.junit.AfterClass; 47 47 48 48 import org.junit.BeforeClass; … … 51 51 public class CacheLRUWrapperTest { 52 52 53 private final CacheLRUWrapper clw = CacheLRUWrapper.getInstance(); 54 private final String cacheDir = new File(JNLPRuntime.getConfiguration() 55 .getProperty(DeploymentConfiguration.KEY_USER_CACHE_DIR)).getPath(); 56 53 private static final CacheLRUWrapper clw = CacheLRUWrapper.getInstance(); 54 private static String cacheDirBackup; 55 private static PropertiesFile cacheOrderBackup; 57 56 // does no DeploymentConfiguration exist for this file name? 58 private final String cacheIndexFileName = "recently_used";57 private static final String cacheIndexFileName = CacheLRUWrapper.CACHE_INDEX_FILE_NAME + "_testing"; 59 58 60 59 private final int noEntriesCacheFile = 1000; … … 62 61 @BeforeClass 63 62 static public void setupJNLPRuntimeConfig() { 64 JNLPRuntime.getConfiguration().setProperty(DeploymentConfiguration.KEY_USER_CACHE_DIR, System.getProperty("java.io.tmpdir")); 63 cacheDirBackup = clw.cacheDir; 64 cacheOrderBackup = clw.cacheOrder; 65 clw.cacheDir=System.getProperty("java.io.tmpdir"); 66 clw.cacheOrder = new PropertiesFile( new File(clw.cacheDir + File.separator + cacheIndexFileName)); 67 68 } 69 70 @AfterClass 71 static public void restoreJNLPRuntimeConfig() { 72 clw.cacheDir = cacheDirBackup; 73 clw.cacheOrder = cacheOrderBackup; 65 74 } 66 75 … … 68 77 public void testLoadStoreTiming() throws InterruptedException { 69 78 79 final File cacheIndexFile = new File(clw.cacheDir + File.separator + cacheIndexFileName); 80 cacheIndexFile.delete(); 81 //ensure it exists, so we can lock 82 clw.store(); 83 try{ 84 70 85 int noLoops = 1000; 71 86 … … 96 111 // wait more than 100 microseconds for noLoops = 1000 and noEntries=1000 is bad 97 112 assertTrue("load() must not take longer than 100 µs, but took in avg " + avg/1000 + "µs", avg < 100 * 1000); 98 99 clw.unlock(); 113 } finally { 114 clw.unlock(); 115 cacheIndexFile.delete(); 116 } 100 117 } 101 118 … … 104 121 // fill cache index file 105 122 for(int i = 0; i < noEntries; i++) { 106 String path = c acheDir + File.separatorChar + i + File.separatorChar + "test" + i + ".jar";123 String path = clw.cacheDir + File.separatorChar + i + File.separatorChar + "test" + i + ".jar"; 107 124 String key = clw.generateKey(path); 108 125 clw.addEntry(key, path); … … 113 130 public void testModTimestampAfterStore() throws InterruptedException { 114 131 115 final File cacheIndexFile = new File(cacheDir + File.separator + cacheIndexFileName); 116 132 final File cacheIndexFile = new File(clw.cacheDir + File.separator + cacheIndexFileName); 133 cacheIndexFile.delete(); 134 //ensure it exists, so we can lock 135 clw.store(); 136 try{ 117 137 clw.lock(); 118 138 119 139 // 1. clear cache entries + store 140 clw.addEntry("aa", "bb"); 141 clw.store(); 120 142 long lmBefore = cacheIndexFile.lastModified(); 143 Thread.sleep(1010); 121 144 clearCacheIndexFile(); 122 145 long lmAfter = cacheIndexFile.lastModified(); … … 124 147 125 148 // FIXME: wait a second, because of file modification timestamp only provides accuracy on seconds. 126 Thread.sleep(10 00);149 Thread.sleep(1010); 127 150 128 151 // 2. load cache file … … 139 162 assertTrue("modification timestamp hasn't changed! Before = " + lmBefore + " After = " + lmAfter, lmBefore < lmAfter); 140 163 141 clw.unlock(); 164 } finally { 165 cacheIndexFile.delete(); 166 clw.unlock(); 167 } 142 168 } 143 169 -
trunk/icedtea-web/tests/netx/unit/net/sourceforge/jnlp/cache/ResourceTrackerTest.java
r418 r429 1 1 /* ResourceTrackerTest.java 2 Copyright (C) 2012 Red Hat, Inc.3 4 This file is part of IcedTea.5 6 IcedTea is free software; you can redistribute it and/or7 modify it under the terms of the GNU General Public License as published by8 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 of12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU13 General Public License for more details.14 15 You should have received a copy of the GNU General Public License16 along with IcedTea; see the file COPYING. If not, write to17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA18 02110-1301 USA.19 20 Linking this library statically or dynamically with other modules is21 making a combined work based on this library. Thus, the terms and22 conditions of the GNU General Public License cover the whole23 combination.24 25 As a special exception, the copyright holders of this library give you26 permission to link this library with independent modules to produce an27 executable, regardless of the license terms of these independent28 modules, and to copy and distribute the resulting executable under29 terms of your choice, provided that you also meet, for each linked30 independent module, the terms and conditions of the license of that31 module. An independent module is a module which is not derived from32 or based on this library. If you modify this library, you may extend33 this exception to your version of the library, but you are not34 obligated to do so. If you do not wish to do so, delete this35 exception statement from your version.2 Copyright (C) 2012 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 36 */ 37 37 package net.sourceforge.jnlp.cache; 38 38 39 import java.io.ByteArrayOutputStream; 40 import java.io.File; 41 import java.io.IOException; 42 import java.io.PrintStream; 39 43 import java.io.UnsupportedEncodingException; 44 import java.net.HttpURLConnection; 40 45 import java.net.MalformedURLException; 46 import java.net.URISyntaxException; 41 47 import java.net.URL; 48 import java.util.HashMap; 49 import net.sourceforge.jnlp.ServerAccess; 50 import net.sourceforge.jnlp.ServerLauncher; 51 import net.sourceforge.jnlp.Version; 52 import net.sourceforge.jnlp.runtime.JNLPRuntime; 53 import net.sourceforge.jnlp.util.logging.OutputController; 54 import net.sourceforge.jnlp.util.UrlUtils; 55 import org.junit.AfterClass; 42 56 import org.junit.Assert; 57 import org.junit.BeforeClass; 43 58 import org.junit.Test; 44 59 45 /** Test various corner cases of the parser */46 60 public class ResourceTrackerTest { 61 62 public static ServerLauncher testServer; 63 public static ServerLauncher testServerWithBrokenHead; 64 private static PrintStream[] backedUpStream = new PrintStream[4]; 65 private static ByteArrayOutputStream currentErrorStream; 66 private static final String nameStub1 = "itw-server"; 67 private static final String nameStub2 = "test-file"; 47 68 48 69 @Test … … 55 76 Assert.assertNull("first normalized url should be null", n[0]); 56 77 for (int i = 1; i < CHANGE_BORDER; i++) { 57 Assert.assertTrue("url " + i + " must be equals too norm laized url " + i, u[i].equals(n[i]));78 Assert.assertTrue("url " + i + " must be equals too normalized url " + i, u[i].equals(n[i])); 58 79 } 59 80 for (int i = CHANGE_BORDER; i < n.length; i++) { 60 Assert.assertFalse("url " + i + " must be normalized (and so not equals) too normlaized url " + i, u[i].equals(n[i])); 61 } 62 } 63 64 private static URL normalizeUrl(URL uRL) throws MalformedURLException, UnsupportedEncodingException { 65 return ResourceTracker.normalizeUrl(uRL, false); 66 } 67 public static final int CHANGE_BORDER = 7; 81 Assert.assertFalse("url " + i + " must be normalized (and so not equals) too normalized url " + i, u[i].equals(n[i])); 82 } 83 } 84 public static final int CHANGE_BORDER = 8; 68 85 69 86 public static URL[] getUrls() throws MalformedURLException { … … 71 88 /*constant*/ 72 89 null, 73 new URL("http://localhost:44321/Spaces%20Can%20Be%20Everyw%2Fhere1.jnlp"),74 90 new URL("file:///home/jvanek/Desktop/icedtea-web/tests.build/jnlp_test_server/Spaces%20can%20be%20everywhere2.jnlp"), 75 new URL("http://localhost/Spaces+Can+Be+Everywhere1.jnlp"),76 91 new URL("http://localhost:44321/SpacesCanBeEverywhere1.jnlp"), 77 92 new URL("http:///SpacesCanBeEverywhere1.jnlp"), 78 93 new URL("file://localhost/home/jvanek/Desktop/icedtea-web/tests.build/jnlp_test_server/Spaces can be everywhere2.jnlp"), 94 new URL("http://localhost:44321/testpage.jnlp?applicationID=25"), 95 new URL("http://localhost:44321/Spaces%20Can%20Be%20Everyw%2Fhere1.jnlp"), 96 new URL("http://localhost/Spaces+Can+Be+Everywhere1.jnlp"), 79 97 /*changing*/ 80 98 new URL("http://localhost/SpacesC anBeEverywhere1.jnlp?a=5&b=10#df"), … … 86 104 } 87 105 88 public static URL[] getNormalizedUrls() throws MalformedURLException, UnsupportedEncodingException {106 public static URL[] getNormalizedUrls() throws MalformedURLException, UnsupportedEncodingException, URISyntaxException { 89 107 URL[] u = getUrls(); 90 108 91 109 URL[] n = new URL[u.length]; 92 110 for (int i = 0; i < n.length; i++) { 93 n[i] = normalizeUrl(u[i]);111 n[i] = UrlUtils.normalizeUrl(u[i]); 94 112 } 95 113 return n; 96 114 97 115 } 116 117 @BeforeClass 118 //keeping silent outputs from launched jvm 119 public static void redirectErr() throws IOException { 120 for (int i = 0; i < backedUpStream.length; i++) { 121 if (backedUpStream[i] == null) { 122 switch (i) { 123 case 0: 124 backedUpStream[i] = System.out; 125 break; 126 case 1: 127 backedUpStream[i] = System.err; 128 break; 129 case 2: 130 backedUpStream[i] = OutputController.getLogger().getOut(); 131 break; 132 case 3: 133 backedUpStream[i] = OutputController.getLogger().getErr(); 134 break; 135 } 136 137 } 138 139 } 140 currentErrorStream = new ByteArrayOutputStream(); 141 System.setOut(new PrintStream(currentErrorStream)); 142 System.setErr(new PrintStream(currentErrorStream)); 143 OutputController.getLogger().setOut(new PrintStream(currentErrorStream)); 144 OutputController.getLogger().setErr(new PrintStream(currentErrorStream)); 145 146 147 } 148 149 @AfterClass 150 public static void redirectErrBack() throws IOException { 151 ServerAccess.logErrorReprint(currentErrorStream.toString("utf-8")); 152 System.setOut(backedUpStream[0]); 153 System.setErr(backedUpStream[1]); 154 OutputController.getLogger().setOut(backedUpStream[2]); 155 OutputController.getLogger().setErr(backedUpStream[3]); 156 157 158 } 159 160 @BeforeClass 161 public static void onDebug() { 162 JNLPRuntime.setDebug(true); 163 } 164 165 @AfterClass 166 public static void offDebug() { 167 JNLPRuntime.setDebug(false); 168 } 169 170 @BeforeClass 171 public static void startServer() throws Exception { 172 redirectErr(); 173 testServer = ServerAccess.getIndependentInstance(System.getProperty("java.io.tmpdir"), ServerAccess.findFreePort()); 174 redirectErrBack(); 175 } 176 177 @BeforeClass 178 public static void startServer2() throws Exception { 179 redirectErr(); 180 testServerWithBrokenHead = ServerAccess.getIndependentInstance(System.getProperty("java.io.tmpdir"), ServerAccess.findFreePort()); 181 testServerWithBrokenHead.setSupportingHeadRequest(false); 182 redirectErrBack(); 183 } 184 185 @AfterClass 186 public static void stopServer() { 187 testServer.stop(); 188 } 189 190 @AfterClass 191 public static void stopServer2() { 192 testServerWithBrokenHead.stop(); 193 } 194 195 @Test 196 public void getUrlResponseCodeTestWorkingHeadRequest() throws Exception { 197 redirectErr(); 198 try { 199 File f = File.createTempFile(nameStub1, nameStub2); 200 int i = ResourceTracker.getUrlResponseCode(testServer.getUrl(f.getName()), new HashMap<String, String>(), "HEAD"); 201 Assert.assertEquals(HttpURLConnection.HTTP_OK, i); 202 f.delete(); 203 i = ResourceTracker.getUrlResponseCode(testServer.getUrl(f.getName()), new HashMap<String, String>(), "HEAD"); 204 Assert.assertEquals(HttpURLConnection.HTTP_NOT_FOUND, i); 205 } finally { 206 redirectErrBack(); 207 } 208 } 209 210 @Test 211 public void getUrlResponseCodeTestNotWorkingHeadRequest() throws Exception { 212 redirectErr(); 213 try { 214 File f = File.createTempFile(nameStub1, nameStub2); 215 int i = ResourceTracker.getUrlResponseCode(testServerWithBrokenHead.getUrl(f.getName()), new HashMap<String, String>(), "HEAD"); 216 Assert.assertEquals(HttpURLConnection.HTTP_NOT_IMPLEMENTED, i); 217 f.delete(); 218 i = ResourceTracker.getUrlResponseCode(testServerWithBrokenHead.getUrl(f.getName()), new HashMap<String, String>(), "HEAD"); 219 Assert.assertEquals(HttpURLConnection.HTTP_NOT_IMPLEMENTED, i); 220 } finally { 221 redirectErrBack(); 222 } 223 } 224 225 @Test 226 public void getUrlResponseCodeTestGetRequestOnNotWorkingHeadRequest() throws Exception { 227 redirectErr(); 228 try { 229 File f = File.createTempFile(nameStub1, nameStub2); 230 int i = ResourceTracker.getUrlResponseCode(testServerWithBrokenHead.getUrl(f.getName()), new HashMap<String, String>(), "GET"); 231 Assert.assertEquals(HttpURLConnection.HTTP_OK, i); 232 f.delete(); 233 i = ResourceTracker.getUrlResponseCode(testServerWithBrokenHead.getUrl(f.getName()), new HashMap<String, String>(), "GET"); 234 Assert.assertEquals(HttpURLConnection.HTTP_NOT_FOUND, i); 235 } finally { 236 redirectErrBack(); 237 } 238 } 239 240 @Test 241 public void getUrlResponseCodeTestGetRequest() throws Exception { 242 redirectErr(); 243 try { 244 File f = File.createTempFile(nameStub1, nameStub2); 245 int i = ResourceTracker.getUrlResponseCode(testServer.getUrl(f.getName()), new HashMap<String, String>(), "GET"); 246 Assert.assertEquals(HttpURLConnection.HTTP_OK, i); 247 f.delete(); 248 i = ResourceTracker.getUrlResponseCode(testServer.getUrl(f.getName()), new HashMap<String, String>(), "GET"); 249 Assert.assertEquals(HttpURLConnection.HTTP_NOT_FOUND, i); 250 } finally { 251 redirectErrBack(); 252 } 253 } 254 255 @Test 256 public void getUrlResponseCodeTestWrongRequest() throws Exception { 257 redirectErr(); 258 try { 259 File f = File.createTempFile(nameStub1, nameStub2); 260 Exception exception = null; 261 try { 262 ResourceTracker.getUrlResponseCode(testServer.getUrl(f.getName()), new HashMap<String, String>(), "SomethingWrong"); 263 } catch (Exception ex) { 264 exception = ex; 265 } 266 Assert.assertNotNull(exception); 267 exception = null; 268 f.delete(); 269 try { 270 ResourceTracker.getUrlResponseCode(testServer.getUrl(f.getName()), new HashMap<String, String>(), "SomethingWrong"); 271 } catch (Exception ex) { 272 exception = ex; 273 } 274 Assert.assertNotNull(exception);; 275 } finally { 276 redirectErrBack(); 277 } 278 279 } 280 281 @Test 282 public void findBestUrltest() throws Exception { 283 redirectErr(); 284 try { 285 File fileForServerWithHeader = File.createTempFile(nameStub1, nameStub2); 286 File versionedFileForServerWithHeader = new File(fileForServerWithHeader.getParentFile(), fileForServerWithHeader.getName() + "-2.0"); 287 versionedFileForServerWithHeader.createNewFile(); 288 289 File fileForServerWithoutHeader = File.createTempFile(nameStub1, nameStub2); 290 File versionedFileForServerWithoutHeader = new File(fileForServerWithoutHeader.getParentFile(), fileForServerWithoutHeader.getName() + "-2.0"); 291 versionedFileForServerWithoutHeader.createNewFile(); 292 293 ResourceTracker rt = new ResourceTracker(); 294 Resource r1 = Resource.getResource(testServer.getUrl(fileForServerWithHeader.getName()), null, UpdatePolicy.NEVER); 295 Resource r2 = Resource.getResource(testServerWithBrokenHead.getUrl(fileForServerWithoutHeader.getName()), null, UpdatePolicy.NEVER); 296 Resource r3 = Resource.getResource(testServer.getUrl(versionedFileForServerWithHeader.getName()), new Version("1.0"), UpdatePolicy.NEVER); 297 Resource r4 = Resource.getResource(testServerWithBrokenHead.getUrl(versionedFileForServerWithoutHeader.getName()), new Version("1.0"), UpdatePolicy.NEVER); 298 assertOnServerWithHeader(rt.findBestUrl(r1)); 299 assertVersionedOneOnServerWithHeader(rt.findBestUrl(r3)); 300 assertOnServerWithoutHeader(rt.findBestUrl(r2)); 301 assertVersionedOneOnServerWithoutHeader(rt.findBestUrl(r4)); 302 303 fileForServerWithHeader.delete(); 304 Assert.assertNull(rt.findBestUrl(r1)); 305 assertVersionedOneOnServerWithHeader(rt.findBestUrl(r3)); 306 assertOnServerWithoutHeader(rt.findBestUrl(r2)); 307 assertVersionedOneOnServerWithoutHeader(rt.findBestUrl(r4)); 308 309 versionedFileForServerWithHeader.delete(); 310 Assert.assertNull(rt.findBestUrl(r1)); 311 Assert.assertNull(rt.findBestUrl(r3)); 312 assertOnServerWithoutHeader(rt.findBestUrl(r2)); 313 assertVersionedOneOnServerWithoutHeader(rt.findBestUrl(r4)); 314 315 versionedFileForServerWithoutHeader.delete(); 316 Assert.assertNull(rt.findBestUrl(r1)); 317 Assert.assertNull(rt.findBestUrl(r3)); 318 assertOnServerWithoutHeader(rt.findBestUrl(r2)); 319 Assert.assertNull(rt.findBestUrl(r4)); 320 321 322 fileForServerWithoutHeader.delete(); 323 Assert.assertNull(rt.findBestUrl(r1)); 324 Assert.assertNull(rt.findBestUrl(r3)); 325 Assert.assertNull(rt.findBestUrl(r2)); 326 Assert.assertNull(rt.findBestUrl(r4)); 327 } finally { 328 redirectErrBack(); 329 } 330 331 } 332 333 private void assertOnServerWithHeader(URL u) { 334 assertCommonComponentsOfUrl(u); 335 assertPort(u, testServer.getPort()); 336 } 337 338 private void assertVersionedOneOnServerWithHeader(URL u) { 339 assertCommonComponentsOfUrl(u); 340 assertPort(u, testServer.getPort()); 341 assertVersion(u); 342 } 343 344 private void assertOnServerWithoutHeader(URL u) { 345 assertCommonComponentsOfUrl(u); 346 assertPort(u, testServerWithBrokenHead.getPort()); 347 } 348 349 private void assertVersionedOneOnServerWithoutHeader(URL u) { 350 assertCommonComponentsOfUrl(u); 351 assertPort(u, testServerWithBrokenHead.getPort()); 352 assertVersion(u); 353 } 354 355 private void assertCommonComponentsOfUrl(URL u) { 356 Assert.assertTrue(u.getProtocol().equals("http")); 357 Assert.assertTrue(u.getHost().equals("localhost")); 358 Assert.assertTrue(u.getPath().contains(nameStub1)); 359 Assert.assertTrue(u.getPath().contains(nameStub2)); 360 ServerAccess.logOutputReprint(u.toExternalForm()); 361 } 362 363 private void assertPort(URL u, int port) { 364 Assert.assertTrue(u.getPort() == port); 365 } 366 367 private void assertVersion(URL u) { 368 Assert.assertTrue(u.getPath().contains("-2.0")); 369 Assert.assertTrue(u.getQuery().contains("version-id=1.0")); 370 } 98 371 } -
trunk/icedtea-web/tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java
r418 r429 1 1 /* CodeBaseClassLoaderTest.java 2 Copyright (C) 2012 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 2 Copyright (C) 2012 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 */ 38 37 package net.sourceforge.jnlp.runtime; 39 38 39 import net.sourceforge.jnlp.mock.DummyJNLPFile; 40 40 import static org.junit.Assert.assertFalse; 41 41 import static org.junit.Assert.assertTrue; 42 42 43 import java.io.IOException; 44 import java.net.MalformedURLException; 43 import java.lang.reflect.Field; 45 44 import java.net.URL; 46 45 import java.util.Locale; 47 46 48 47 import net.sourceforge.jnlp.JNLPFile; 49 import net.sourceforge.jnlp.LaunchException; 50 import net.sourceforge.jnlp.ParseException; 48 import net.sourceforge.jnlp.NullJnlpFileException; 51 49 import net.sourceforge.jnlp.ResourcesDesc; 52 50 import net.sourceforge.jnlp.SecurityDesc; 51 import net.sourceforge.jnlp.SecurityDescTest; 53 52 import net.sourceforge.jnlp.ServerAccess; 54 import net.sourceforge.jnlp.runtime.JNLPClassLoader;55 53 import net.sourceforge.jnlp.runtime.JNLPClassLoader.CodeBaseClassLoader; 56 54 import net.sourceforge.jnlp.annotations.Bug; 55 import net.sourceforge.jnlp.annotations.Remote; 56 import net.sourceforge.jnlp.config.DeploymentConfiguration; 57 import net.sourceforge.jnlp.security.appletextendedsecurity.AppletSecurityLevel; 58 import net.sourceforge.jnlp.security.appletextendedsecurity.AppletStartupSecuritySettings; 59 import net.sourceforge.jnlp.util.logging.NoStdOutErrTest; 60 import org.junit.AfterClass; 61 import org.junit.Assert; 62 import org.junit.BeforeClass; 57 63 58 64 import org.junit.Test; 59 65 60 public class CodeBaseClassLoaderTest { 61 62 @Bug(id={"PR895", 63 "http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2012-March/017626.html", 64 "http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2012-March/017667.html"}) 65 @Test 66 public void testResourceLoadSuccessCaching() throws LaunchException, ClassNotFoundException, IOException, ParseException { 67 final URL JAR_URL = new URL("http://icedtea.classpath.org/netx/about.jar"); 68 final URL CODEBASE_URL = new URL("http://icedtea.classpath.org/netx/"); 69 70 JNLPFile dummyJnlpFile = new JNLPFile() { 71 @Override 72 public ResourcesDesc getResources() { 73 return new ResourcesDesc(null, new Locale[0], new String[0], new String[0]); 74 } 75 76 @Override 77 public URL getCodeBase() { 78 return CODEBASE_URL; 79 } 80 81 @Override 82 public SecurityDesc getSecurity() { 83 return new SecurityDesc(null, SecurityDesc.SANDBOX_PERMISSIONS, null); 84 } 85 }; 66 public class CodeBaseClassLoaderTest extends NoStdOutErrTest { 67 68 private static AppletSecurityLevel level; 69 70 @BeforeClass 71 public static void setPermissions() { 72 level = AppletStartupSecuritySettings.getInstance().getSecurityLevel(); 73 JNLPRuntime.getConfiguration().setProperty(DeploymentConfiguration.KEY_SECURITY_LEVEL, AppletSecurityLevel.ALLOW_UNSIGNED.toChars()); 74 } 75 76 @AfterClass 77 public static void resetPermissions() { 78 JNLPRuntime.getConfiguration().setProperty(DeploymentConfiguration.KEY_SECURITY_LEVEL, level.toChars()); 79 } 80 81 private static final String isWSA = "isWebstartApplication"; 82 83 static void setStaticField(Field field, Object newValue) throws Exception { 84 field.setAccessible(true); 85 field.set(null, newValue); 86 } 87 88 private void setWSA() throws Exception { 89 setStaticField(JNLPRuntime.class.getDeclaredField(isWSA), true); 90 } 91 92 private void setApplet() throws Exception { 93 setStaticField(JNLPRuntime.class.getDeclaredField(isWSA), false); 94 } 95 96 @AfterClass 97 public static void tearDown() throws Exception { 98 setStaticField(JNLPRuntime.class.getDeclaredField(isWSA), false); 99 100 101 } 102 103 @Bug(id = {"PR895", 104 "http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2012-March/017626.html", 105 "http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2012-March/017667.html"}) 106 @Test 107 @Remote 108 public void testClassResourceLoadSuccessCachingApplication() throws Exception { 109 setWSA(); 110 //we are testing new resource not in cache 111 testResourceCaching("net/sourceforge/jnlp/about/Main.class"); 112 } 113 114 @Test 115 @Remote 116 public void testClassResourceLoadSuccessCachingApplet() throws Exception { 117 setApplet(); 118 //so new resource again not in cache 119 testResourceCaching("net/sourceforge/jnlp/about/Main.class"); 120 } 121 122 @Test 123 @Remote 124 public void testResourceLoadSuccessCachingApplication() throws Exception { 125 setWSA(); 126 //we are testing new resource not in cache 127 testResourceCaching("net/sourceforge/jnlp/about/resources/about.html"); 128 } 129 130 @Test 131 @Remote 132 public void testResourceLoadSuccessCachingApplet() throws Exception { 133 setApplet(); 134 //so new resource again not in cache 135 testResourceCaching("net/sourceforge/jnlp/about/resources/about.html"); 136 } 137 138 public void testResourceCaching(String r) throws Exception { 139 testResourceCaching(r, true); 140 } 141 142 public void testResourceCaching(String r, boolean shouldExists) throws Exception { 143 JNLPFile dummyJnlpFile = new DummyJNLPFile(); 86 144 87 145 JNLPClassLoader parent = new JNLPClassLoader(dummyJnlpFile, null); 88 CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[] { JAR_URL, CODEBASE_URL }, parent); 89 146 CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[]{DummyJNLPFile.JAR_URL, DummyJNLPFile.CODEBASE_URL}, parent); 147 148 int level = 10; 149 if (shouldExists) { 150 //for found the "caching" is by internal logic.Always faster, but who knows how... 151 //to keep the test stabile keep the difference minimal 152 level = 1; 153 } 90 154 long startTime, stopTime; 91 155 92 156 startTime = System.nanoTime(); 93 classLoader.findResource("net/sourceforge/jnlp/about/Main.class"); 157 URL u1 = classLoader.findResource(r); 158 if (shouldExists) { 159 Assert.assertNotNull(u1); 160 } else { 161 Assert.assertNull(u1); 162 } 94 163 stopTime = System.nanoTime(); 95 164 long timeOnFirstTry = stopTime - startTime; 96 ServerAccess.logErrorReprint("" +timeOnFirstTry);165 ServerAccess.logErrorReprint("" + timeOnFirstTry); 97 166 98 167 startTime = System.nanoTime(); 99 classLoader.findResource("net/sourceforge/jnlp/about/Main.class"); 168 URL u2 = classLoader.findResource(r); 169 if (shouldExists) { 170 Assert.assertNotNull(u1); 171 } else { 172 Assert.assertNull(u2); 173 } 100 174 stopTime = System.nanoTime(); 101 175 long timeOnSecondTry = stopTime - startTime; 102 ServerAccess.logErrorReprint(""+timeOnSecondTry); 103 104 assertTrue(timeOnSecondTry < (timeOnFirstTry / 10)); 105 } 106 107 @Bug(id={"PR895", 108 "http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2012-March/017626.html", 109 "http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2012-March/017667.html"}) 110 @Test 111 public void testResourceLoadFailureCaching() throws LaunchException, ClassNotFoundException, IOException, ParseException { 112 final URL JAR_URL = new URL("http://icedtea.classpath.org/netx/about.jar"); 113 final URL CODEBASE_URL = new URL("http://icedtea.classpath.org/netx/"); 114 115 JNLPFile dummyJnlpFile = new JNLPFile() { 116 @Override 117 public ResourcesDesc getResources() { 118 return new ResourcesDesc(null, new Locale[0], new String[0], new String[0]); 119 } 120 121 @Override 122 public URL getCodeBase() { 123 return CODEBASE_URL; 124 } 125 126 @Override 127 public SecurityDesc getSecurity() { 128 return new SecurityDesc(null, SecurityDesc.SANDBOX_PERMISSIONS, null); 129 } 130 }; 131 132 JNLPClassLoader parent = new JNLPClassLoader(dummyJnlpFile, null); 133 CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[] { JAR_URL, CODEBASE_URL }, parent); 134 135 long startTime, stopTime; 136 137 startTime = System.nanoTime(); 138 classLoader.findResource("net/sourceforge/jnlp/about/Main_FOO_.class"); 139 stopTime = System.nanoTime(); 140 long timeOnFirstTry = stopTime - startTime; 141 ServerAccess.logErrorReprint(""+timeOnFirstTry); 142 143 startTime = System.nanoTime(); 144 classLoader.findResource("net/sourceforge/jnlp/about/Main_FOO_.class"); 145 stopTime = System.nanoTime(); 146 long timeOnSecondTry = stopTime - startTime; 147 ServerAccess.logErrorReprint(""+timeOnSecondTry); 148 149 assertTrue(timeOnSecondTry < (timeOnFirstTry / 10)); 150 } 151 152 @Test 153 public void testParentClassLoaderIsAskedForClasses() throws MalformedURLException, LaunchException { 154 final URL JAR_URL = new URL("http://icedtea.classpath.org/netx/about.jar"); 155 final URL CODEBASE_URL = new URL("http://icedtea.classpath.org/netx/"); 156 157 JNLPFile dummyJnlpFile = new JNLPFile() { 158 @Override 159 public ResourcesDesc getResources() { 160 return new ResourcesDesc(null, new Locale[0], new String[0], new String[0]); 161 } 162 163 @Override 164 public URL getCodeBase() { 165 return CODEBASE_URL; 166 } 167 168 @Override 169 public SecurityDesc getSecurity() { 170 return new SecurityDesc(null, SecurityDesc.SANDBOX_PERMISSIONS, null); 171 } 172 }; 176 ServerAccess.logErrorReprint("" + timeOnSecondTry); 177 178 assertTrue(timeOnSecondTry < (timeOnFirstTry / level)); 179 } 180 181 @Bug(id = {"PR895", 182 "http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2012-March/017626.html", 183 "http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2012-March/017667.html"}) 184 @Test 185 @Remote 186 public void testResourceLoadFailureCachingApplication() throws Exception { 187 setWSA(); 188 testResourceCaching("net/sourceforge/jnlp/about/Main_FOO_.class", false); 189 } 190 191 @Test 192 public void testResourceLoadFailureCachingApplet() throws Exception { 193 setApplet(); 194 testResourceCaching("net/sourceforge/jnlp/about/Main_FOO_.class", false); 195 } 196 197 @Test 198 @Remote 199 public void testParentClassLoaderIsAskedForClassesApplication() throws Exception { 200 setWSA(); 201 testParentClassLoaderIsAskedForClasses(); 202 } 203 204 @Test 205 @Remote 206 public void testParentClassLoaderIsAskedForClassesApplet() throws Exception { 207 setApplet(); 208 testParentClassLoaderIsAskedForClasses(); 209 } 210 211 public void testParentClassLoaderIsAskedForClasses() throws Exception { 212 JNLPFile dummyJnlpFile = new DummyJNLPFile(); 173 213 174 214 final boolean[] parentWasInvoked = new boolean[1]; … … 181 221 } 182 222 }; 183 CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[] { JAR_URL, CODEBASE_URL}, parent);223 CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[]{DummyJNLPFile.JAR_URL, DummyJNLPFile.CODEBASE_URL}, parent); 184 224 try { 185 225 classLoader.findClass("foo"); … … 189 229 assertTrue(parentWasInvoked[0]); 190 230 } 231 232 @Test 233 public void testNullFileSecurityDescApplication() throws Exception { 234 setWSA(); 235 Exception ex = null; 236 try { 237 testNullFileSecurityDesc(); 238 } catch (Exception exx) { 239 ex = exx; 240 } 241 Assert.assertTrue("was expected exception", ex != null); 242 Assert.assertTrue("was expected " + NullJnlpFileException.class.getName(), ex instanceof NullJnlpFileException); 243 } 244 245 @Test 246 @Remote 247 public void testNullFileSecurityDescApplet() throws Exception { 248 setApplet(); 249 Exception ex = null; 250 try { 251 testNullFileSecurityDesc(); 252 } catch (Exception exx) { 253 ex = exx; 254 } 255 Assert.assertTrue("was expected exception", ex != null); 256 Assert.assertTrue("was expected " + NullJnlpFileException.class.getName(), ex instanceof NullJnlpFileException); 257 } 258 259 public void testNullFileSecurityDesc() throws Exception { 260 JNLPFile dummyJnlpFile = new DummyJNLPFile() { 261 @Override 262 public SecurityDesc getSecurity() { 263 return new SecurityDesc(null, SecurityDesc.SANDBOX_PERMISSIONS, null); 264 } 265 }; 266 JNLPClassLoader parent = new JNLPClassLoader(dummyJnlpFile, null); 267 268 } 191 269 } -
trunk/icedtea-web/tests/netx/unit/net/sourceforge/jnlp/tools/JarCertVerifierTest.java
r418 r429 38 38 package net.sourceforge.jnlp.tools; 39 39 40 import static org.junit.Assert.*; 41 40 import static net.sourceforge.jnlp.runtime.Translator.R; 41 import static org.junit.Assert.assertFalse; 42 import static org.junit.Assert.assertTrue; 43 44 import java.security.CodeSigner; 45 import java.util.Date; 46 import java.util.List; 47 import java.util.Vector; 48 import java.util.jar.JarEntry; 49 50 import net.sourceforge.jnlp.JARDesc; 51 import net.sourceforge.jnlp.tools.JarCertVerifier.VerifyResult; 52 53 import org.junit.Assert; 54 import org.junit.BeforeClass; 42 55 import org.junit.Test; 43 56 … … 46 59 @Test 47 60 public void testIsMetaInfFile() { 48 final String METAINF = "META-INF";61 final String METAINF = "META-INF"; 49 62 assertFalse(JarCertVerifier.isMetaInfFile("some_dir/" + METAINF + "/filename")); 50 63 assertFalse(JarCertVerifier.isMetaInfFile(METAINF + "filename")); … … 52 65 } 53 66 67 class JarCertVerifierEntry extends JarEntry { 68 CodeSigner[] signers; 69 70 public JarCertVerifierEntry(String name, CodeSigner[] codesigners) { 71 super(name); 72 signers = codesigners; 73 } 74 75 public JarCertVerifierEntry(String name) { 76 this(name, null); 77 } 78 79 public CodeSigner[] getCodeSigners() { 80 return signers == null ? null : signers.clone(); 81 } 82 } 83 84 // Empty list to be used with JarCertVerifier constructor. 85 private static final List<JARDesc> emptyJARDescList = new Vector<JARDesc>(); 86 87 private static final String DNPARTIAL = ", OU=JarCertVerifier Unit Test, O=IcedTea, L=Toronto, ST=Ontario, C=CA"; 88 private static CodeSigner alphaSigner, betaSigner, charlieSigner, 89 expiredSigner, expiringSigner, notYetValidSigner, expiringAndNotYetValidSigner; 90 91 @BeforeClass 92 public static void setUp() throws Exception { 93 Date currentDate = new Date(); 94 Date pastDate = new Date(currentDate.getTime() - (1000L * 24L * 60L * 60L) - 1000L); // 1 day and 1 second in the past 95 Date futureDate = new Date(currentDate.getTime() + (1000L * 24L * 60L * 60L)); // 1 day in the future 96 alphaSigner = CodeSignerCreator.getOneCodeSigner("CN=Alpha Signer" + DNPARTIAL, currentDate, 365); 97 betaSigner = CodeSignerCreator.getOneCodeSigner("CN=Beta Signer" + DNPARTIAL, currentDate, 365); 98 charlieSigner = CodeSignerCreator.getOneCodeSigner("CN=Charlie Signer" + DNPARTIAL, currentDate, 365); 99 expiredSigner = CodeSignerCreator.getOneCodeSigner("CN=Expired Signer" + DNPARTIAL, pastDate, 1); 100 expiringSigner = CodeSignerCreator.getOneCodeSigner("CN=Expiring Signer" + DNPARTIAL, currentDate, 1); 101 notYetValidSigner = CodeSignerCreator.getOneCodeSigner("CN=Not Yet Valid Signer" + DNPARTIAL, futureDate, 365); 102 expiringAndNotYetValidSigner = CodeSignerCreator.getOneCodeSigner("CN=Expiring and Not Yet Valid Signer" + DNPARTIAL, futureDate, 3); 103 } 104 105 @Test 106 public void testNoManifest() throws Exception { 107 JarCertVerifier jcv = new JarCertVerifier(null); 108 VerifyResult result = jcv.verifyJarEntryCerts("", false, null); 109 110 Assert.assertEquals("No manifest should be considered unsigned.", 111 VerifyResult.UNSIGNED, result); 112 Assert.assertEquals("No manifest means no signers in the verifier.", 113 0, jcv.getCertsList().size()); 114 } 115 116 @Test 117 public void testNoSignableEntries() throws Exception { 118 JarCertVerifier jcv = new JarCertVerifier(null); 119 Vector<JarEntry> entries = new Vector<JarEntry>(); 120 entries.add(new JarCertVerifierEntry("OneDirEntry/")); 121 entries.add(new JarCertVerifierEntry("META-INF/MANIFEST.MF")); 122 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 123 124 Assert.assertEquals("No signable entry (only dirs/manifests) should be considered trivially signed.", 125 VerifyResult.SIGNED_OK, result); 126 Assert.assertEquals("No signable entry (only dirs/manifests) means no signers in the verifier.", 127 0, jcv.getCertsList().size()); 128 } 129 130 @Test 131 public void testSingleEntryNoSigners() throws Exception { 132 JarCertVerifier jcv = new JarCertVerifier(null); 133 Vector<JarEntry> entries = new Vector<JarEntry>(); 134 entries.add(new JarCertVerifierEntry("firstEntryWithoutSigner")); 135 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 136 137 Assert.assertEquals("One unsigned entry should be considered unsigned.", 138 VerifyResult.UNSIGNED, result); 139 Assert.assertEquals("One unsigned entry means no signers in the verifier.", 140 0, jcv.getCertsList().size()); 141 } 142 143 @Test 144 public void testManyEntriesNoSigners() throws Exception { 145 JarCertVerifier jcv = new JarCertVerifier(null); 146 Vector<JarEntry> entries = new Vector<JarEntry>(); 147 entries.add(new JarCertVerifierEntry("firstEntryWithoutSigner")); 148 entries.add(new JarCertVerifierEntry("secondEntryWithoutSigner")); 149 entries.add(new JarCertVerifierEntry("thirdEntryWithoutSigner")); 150 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 151 152 Assert.assertEquals("Many unsigned entries should be considered unsigned.", 153 VerifyResult.UNSIGNED, result); 154 Assert.assertEquals("Many unsigned entries means no signers in the verifier.", 0, 155 jcv.getCertsList().size()); 156 } 157 158 @Test 159 public void testSingleEntrySingleValidSigner() throws Exception { 160 JarCertVerifier jcv = new JarCertVerifier(null); 161 CodeSigner[] signers = { alphaSigner }; 162 Vector<JarEntry> entries = new Vector<JarEntry>(); 163 entries.add(new JarCertVerifierEntry("firstSignedByOne", signers)); 164 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 165 166 Assert.assertEquals("One signed entry should be considered signed and okay.", 167 VerifyResult.SIGNED_OK, result); 168 Assert.assertEquals("One signed entry means one signer in the verifier.", 169 1, jcv.getCertsList().size()); 170 Assert.assertTrue("One signed entry means one signer in the verifier.", 171 jcv.getCertsList().contains(alphaSigner.getSignerCertPath())); 172 } 173 174 @Test 175 public void testManyEntriesSingleValidSigner() throws Exception { 176 JarCertVerifier jcv = new JarCertVerifier(null); 177 CodeSigner[] signers = { alphaSigner }; 178 Vector<JarEntry> entries = new Vector<JarEntry>(); 179 entries.add(new JarCertVerifierEntry("firstSignedByOne", signers)); 180 entries.add(new JarCertVerifierEntry("secondSignedByOne", signers)); 181 entries.add(new JarCertVerifierEntry("thirdSignedByOne", signers)); 182 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 183 184 Assert.assertEquals("Three entries signed by one signer should be considered signed and okay.", 185 VerifyResult.SIGNED_OK, result); 186 Assert.assertEquals("Three entries signed by one signer means one signer in the verifier.", 187 1, jcv.getCertsList().size()); 188 Assert.assertTrue("Three entries signed by one signer means one signer in the verifier.", 189 jcv.getCertsList().contains(alphaSigner.getSignerCertPath())); 190 } 191 192 @Test 193 public void testSingleEntryMultipleValidSigners() throws Exception { 194 JarCertVerifier jcv = new JarCertVerifier(null); 195 CodeSigner[] signers = { alphaSigner, betaSigner, charlieSigner }; 196 Vector<JarEntry> entries = new Vector<JarEntry>(); 197 entries.add(new JarCertVerifierEntry("firstSignedByThree", signers)); 198 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 199 200 Assert.assertEquals("One entry signed by three signers should be considered signed and okay.", 201 VerifyResult.SIGNED_OK, result); 202 Assert.assertEquals("One entry signed by three means three signers in the verifier.", 203 3, jcv.getCertsList().size()); 204 Assert.assertTrue("One entry signed by three means three signers in the verifier.", 205 jcv.getCertsList().contains(alphaSigner.getSignerCertPath()) 206 && jcv.getCertsList().contains(betaSigner.getSignerCertPath()) 207 && jcv.getCertsList().contains(charlieSigner.getSignerCertPath())); 208 } 209 210 @Test 211 public void testManyEntriesMultipleValidSigners() throws Exception { 212 JarCertVerifier jcv = new JarCertVerifier(null); 213 CodeSigner[] signers = { alphaSigner, betaSigner, charlieSigner }; 214 Vector<JarEntry> entries = new Vector<JarEntry>(); 215 entries.add(new JarCertVerifierEntry("firstSignedByThree", signers)); 216 entries.add(new JarCertVerifierEntry("secondSignedByThree", signers)); 217 entries.add(new JarCertVerifierEntry("thirdSignedByThree", signers)); 218 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 219 220 Assert.assertEquals("Three entries signed by three signers should be considered signed and okay.", 221 VerifyResult.SIGNED_OK, result); 222 Assert.assertEquals("Three entries signed by three means three signers in the verifier.", 223 3, jcv.getCertsList().size()); 224 Assert.assertTrue("Three entries signed by three means three signers in the verifier.", 225 jcv.getCertsList().contains(alphaSigner.getSignerCertPath()) 226 && jcv.getCertsList().contains(betaSigner.getSignerCertPath()) 227 && jcv.getCertsList().contains(charlieSigner.getSignerCertPath())); 228 } 229 230 @Test 231 public void testOneCommonSigner() throws Exception { 232 JarCertVerifier jcv = new JarCertVerifier(null); 233 CodeSigner[] alphaSigners = { alphaSigner }; 234 CodeSigner[] betaSigners = { alphaSigner, betaSigner }; 235 CodeSigner[] charlieSigners = { alphaSigner, charlieSigner }; 236 Vector<JarEntry> entries = new Vector<JarEntry>(); 237 entries.add(new JarCertVerifierEntry("firstSignedByOne", alphaSigners)); 238 entries.add(new JarCertVerifierEntry("secondSignedByTwo", betaSigners)); 239 entries.add(new JarCertVerifierEntry("thirdSignedByTwo", charlieSigners)); 240 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 241 242 Assert.assertEquals("Three entries signed by at least one common signer should be considered signed and okay.", 243 VerifyResult.SIGNED_OK, result); 244 Assert.assertEquals("Three entries signed completely by only one signer means one signer in the verifier.", 245 1, jcv.getCertsList().size()); 246 Assert.assertTrue("Three entries signed completely by only one signer means one signer in the verifier.", 247 jcv.getCertsList().contains(alphaSigner.getSignerCertPath())); 248 } 249 250 @Test 251 public void testNoCommonSigner() throws Exception { 252 JarCertVerifier jcv = new JarCertVerifier(null); 253 CodeSigner[] alphaSigners = { alphaSigner }; 254 CodeSigner[] betaSigners = { betaSigner }; 255 CodeSigner[] charlieSigners = { charlieSigner }; 256 Vector<JarEntry> entries = new Vector<JarEntry>(); 257 entries.add(new JarCertVerifierEntry("firstSignedByAlpha", alphaSigners)); 258 entries.add(new JarCertVerifierEntry("secondSignedByBeta", betaSigners)); 259 entries.add(new JarCertVerifierEntry("thirdSignedByCharlie", charlieSigners)); 260 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 261 262 Assert.assertEquals("Three entries signed by no common signers should be considered unsigned.", 263 VerifyResult.UNSIGNED, result); 264 Assert.assertEquals("Three entries signed by no common signers means no signers in the verifier.", 265 0, jcv.getCertsList().size()); 266 } 267 268 @Test 269 public void testFewButNotAllCommonSigners() throws Exception { 270 JarCertVerifier jcv = new JarCertVerifier(null); 271 CodeSigner[] alphaSigners = { alphaSigner }; 272 CodeSigner[] betaSigners = { betaSigner }; 273 Vector<JarEntry> entries = new Vector<JarEntry>(); 274 entries.add(new JarCertVerifierEntry("firstSignedByAlpha", alphaSigners)); 275 entries.add(new JarCertVerifierEntry("secondSignedByAlpha", alphaSigners)); 276 entries.add(new JarCertVerifierEntry("thirdSignedByBeta", betaSigners)); 277 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 278 279 Assert.assertEquals("First two entries signed by alpha signer, third entry signed by beta signer should be considered unisgned.", 280 VerifyResult.UNSIGNED, result); 281 Assert.assertEquals("Three entries signed by some common signers but not all means no signers in the verifier.", 282 0, jcv.getCertsList().size()); 283 } 284 285 @Test 286 public void testNotAllEntriesSigned() throws Exception { 287 JarCertVerifier jcv = new JarCertVerifier(null); 288 CodeSigner[] alphaSigners = { alphaSigner }; 289 Vector<JarEntry> entries = new Vector<JarEntry>(); 290 entries.add(new JarCertVerifierEntry("firstSignedByAlpha", alphaSigners)); 291 entries.add(new JarCertVerifierEntry("secondSignedByAlpha", alphaSigners)); 292 entries.add(new JarCertVerifierEntry("thirdUnsigned")); 293 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 294 295 Assert.assertEquals("First two entries signed by alpha signer, third entry not signed, should be considered unisgned.", 296 VerifyResult.UNSIGNED, result); 297 Assert.assertEquals("First two entries signed by alpha signer, third entry not signed, means no signers in the verifier.", 298 0, jcv.getCertsList().size()); 299 } 300 301 @Test 302 public void testSingleEntryExpiredSigner() throws Exception { 303 JarCertVerifier jcv = new JarCertVerifier(null); 304 CodeSigner[] expiredSigners = { expiredSigner }; 305 Vector<JarEntry> entries = new Vector<JarEntry>(); 306 entries.add(new JarCertVerifierEntry("firstSignedByExpired", expiredSigners)); 307 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 308 309 Assert.assertEquals("One entry signed by expired cert, should be considered signed but not okay.", 310 VerifyResult.SIGNED_NOT_OK, result); 311 Assert.assertEquals("One entry signed by expired cert means one signer in the verifier.", 312 1, jcv.getCertsList().size()); 313 Assert.assertTrue("One entry signed by expired cert means one signer in the verifier.", 314 jcv.getCertsList().contains(expiredSigner.getSignerCertPath())); 315 } 316 317 @Test 318 public void testManyEntriesExpiredSigner() throws Exception { 319 JarCertVerifier jcv = new JarCertVerifier(null); 320 CodeSigner[] expiredSigners = { expiredSigner }; 321 Vector<JarEntry> entries = new Vector<JarEntry>(); 322 entries.add(new JarCertVerifierEntry("firstSignedByExpired", expiredSigners)); 323 entries.add(new JarCertVerifierEntry("secondSignedBExpired", expiredSigners)); 324 entries.add(new JarCertVerifierEntry("thirdSignedByExpired", expiredSigners)); 325 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 326 327 Assert.assertEquals("Three entries signed by expired cert, should be considered signed but not okay.", 328 VerifyResult.SIGNED_NOT_OK, result); 329 Assert.assertEquals("Three entries signed by expired cert means one signer in the verifier.", 330 1, jcv.getCertsList().size()); 331 Assert.assertTrue("Three entries signed by expired cert means one signer in the verifier.", 332 jcv.getCertsList().contains(expiredSigner.getSignerCertPath())); 333 } 334 335 @Test 336 public void testSingleEntryExpiringSigner() throws Exception { 337 JarCertVerifier jcv = new JarCertVerifier(null); 338 CodeSigner[] expiringSigners = { expiringSigner }; 339 Vector<JarEntry> entries = new Vector<JarEntry>(); 340 entries.add(new JarCertVerifierEntry("firstSignedByExpiring", expiringSigners)); 341 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 342 343 Assert.assertEquals("One entry signed by expiring cert, should be considered signed and okay.", 344 VerifyResult.SIGNED_OK, result); 345 Assert.assertEquals("One entry signed by expiring cert means one signer in the verifier.", 346 1, jcv.getCertsList().size()); 347 Assert.assertTrue("One entry signed by expiring cert means one signer in the verifier.", 348 jcv.getCertsList().contains(expiringSigner.getSignerCertPath())); 349 } 350 351 @Test 352 public void testManyEntriesExpiringSigner() throws Exception { 353 JarCertVerifier jcv = new JarCertVerifier(null); 354 CodeSigner[] expiringSigners = { expiringSigner }; 355 Vector<JarEntry> entries = new Vector<JarEntry>(); 356 entries.add(new JarCertVerifierEntry("firstSignedByExpiring", expiringSigners)); 357 entries.add(new JarCertVerifierEntry("secondSignedBExpiring", expiringSigners)); 358 entries.add(new JarCertVerifierEntry("thirdSignedByExpiring", expiringSigners)); 359 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 360 361 Assert.assertEquals("Three entries signed by expiring cert, should be considered signed and okay.", 362 VerifyResult.SIGNED_OK, result); 363 Assert.assertEquals("Three entries signed by expiring cert means one signer in the verifier.", 364 1, jcv.getCertsList().size()); 365 Assert.assertTrue("Three entries signed by expiring cert means one signer in the verifier.", 366 jcv.getCertsList().contains(expiringSigner.getSignerCertPath())); 367 } 368 369 @Test 370 public void testSingleEntryNotYetValidSigner() throws Exception { 371 JarCertVerifier jcv = new JarCertVerifier(null); 372 CodeSigner[] notYetValidSigners = { notYetValidSigner }; 373 Vector<JarEntry> entries = new Vector<JarEntry>(); 374 entries.add(new JarCertVerifierEntry("firstSignedByNotYetValid", notYetValidSigners)); 375 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 376 377 Assert.assertEquals("One entry signed by cert that is not yet valid, should be considered signed but not okay.", 378 VerifyResult.SIGNED_NOT_OK, result); 379 Assert.assertEquals("One entry signed by cert that is not yet valid means one signer in the verifier.", 380 1, jcv.getCertsList().size()); 381 Assert.assertTrue("One entry signed by cert that is not yet valid means one signer in the verifier.", 382 jcv.getCertsList().contains(notYetValidSigner.getSignerCertPath())); 383 } 384 385 @Test 386 public void testManyEntriesNotYetValidSigner() throws Exception { 387 JarCertVerifier jcv = new JarCertVerifier(null); 388 CodeSigner[] notYetValidSigners = { notYetValidSigner }; 389 Vector<JarEntry> entries = new Vector<JarEntry>(); 390 entries.add(new JarCertVerifierEntry("firstSignedByNotYetValid", notYetValidSigners)); 391 entries.add(new JarCertVerifierEntry("secondSignedByNotYetValid", notYetValidSigners)); 392 entries.add(new JarCertVerifierEntry("thirdSignedByNotYetValid", notYetValidSigners)); 393 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 394 395 Assert.assertEquals("Three entries signed by cert that is not yet valid, should be considered signed but not okay.", 396 VerifyResult.SIGNED_NOT_OK, result); 397 Assert.assertEquals("Three entries signed by cert that is not yet valid means one signer in the verifier.", 398 1, jcv.getCertsList().size()); 399 Assert.assertTrue("Three entries signed by cert that is not yet valid means one signer in the verifier.", 400 jcv.getCertsList().contains(notYetValidSigner.getSignerCertPath())); 401 } 402 403 @Test 404 public void testSingleEntryExpiringAndNotYetValidSigner() throws Exception { 405 JarCertVerifier jcv = new JarCertVerifier(null); 406 CodeSigner[] expiringAndNotYetValidSigners = { expiringAndNotYetValidSigner }; 407 Vector<JarEntry> entries = new Vector<JarEntry>(); 408 entries.add(new JarCertVerifierEntry("firstSignedByExpiringNotYetValid", expiringAndNotYetValidSigners)); 409 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 410 411 Assert.assertEquals("One entry signed by cert that is not yet valid but also expiring, should be considered signed but not okay.", 412 VerifyResult.SIGNED_NOT_OK, result); 413 Assert.assertEquals("One entry signed by cert that is not yet valid but also expiring means one signer in the verifier.", 414 1, jcv.getCertsList().size()); 415 Assert.assertTrue("One entry signed by cert that is not yet valid but also expiring means one signer in the verifier.", 416 jcv.getCertsList().contains(expiringAndNotYetValidSigner.getSignerCertPath())); 417 } 418 419 @Test 420 public void testManyEntryExpiringAndNotYetValidSigner() throws Exception { 421 JarCertVerifier jcv = new JarCertVerifier(null); 422 423 CodeSigner[] expiringAndNotYetValidSigners = { expiringAndNotYetValidSigner }; 424 Vector<JarEntry> entries = new Vector<JarEntry>(); 425 entries.add(new JarCertVerifierEntry("firstSignedByExpiringNotYetValid", expiringAndNotYetValidSigners)); 426 entries.add(new JarCertVerifierEntry("secondSignedByExpiringNotYetValid", expiringAndNotYetValidSigners)); 427 entries.add(new JarCertVerifierEntry("thirdSignedByExpiringNotYetValid", expiringAndNotYetValidSigners)); 428 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 429 430 Assert.assertEquals("Three entries signed by cert that is not yet valid but also expiring, should be considered signed but not okay.", 431 VerifyResult.SIGNED_NOT_OK, result); 432 Assert.assertEquals("Three entries signed by cert that is not yet valid but also expiring means one signer in the verifier.", 433 1, jcv.getCertsList().size()); 434 Assert.assertTrue("Three entries signed by cert that is not yet valid but also expiring means one signer in the verifier.", 435 jcv.getCertsList().contains(expiringAndNotYetValidSigner.getSignerCertPath())); 436 Assert.assertTrue("Three entries signed by cert that is not yet valid but also expiring means expiring issue should be in details list.", 437 jcv.getDetails(expiringAndNotYetValidSigner.getSignerCertPath()).contains(R("SHasExpiringCert"))); 438 } 439 440 @Test 441 public void testSingleEntryOneExpiredOneValidSigner() throws Exception { 442 JarCertVerifier jcv = new JarCertVerifier(null); 443 CodeSigner[] oneExpiredOneValidSigner = { expiredSigner, alphaSigner }; 444 Vector<JarEntry> entries = new Vector<JarEntry>(); 445 entries.add(new JarCertVerifierEntry("firstSignedByTwo", oneExpiredOneValidSigner)); 446 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 447 448 Assert.assertEquals("One entry signed by one expired cert and another valid cert, should be considered signed and okay.", 449 VerifyResult.SIGNED_OK, result); 450 Assert.assertEquals("One entry signed by one expired cert and another valid cert means two signers in the verifier.", 451 2, jcv.getCertsList().size()); 452 Assert.assertTrue("One entry signed by one expired cert and another valid cert means two signers in the verifier.", 453 jcv.getCertsList().contains(expiredSigner.getSignerCertPath()) 454 && jcv.getCertsList().contains(alphaSigner.getSignerCertPath())); 455 } 456 457 @Test 458 public void testManyEntriesOneExpiredOneValidSigner() throws Exception { 459 JarCertVerifier jcv = new JarCertVerifier(null); 460 CodeSigner[] oneExpiredOneValidSigner = { expiredSigner, alphaSigner }; 461 Vector<JarEntry> entries = new Vector<JarEntry>(); 462 entries.add(new JarCertVerifierEntry("firstSignedByTwo", oneExpiredOneValidSigner)); 463 entries.add(new JarCertVerifierEntry("secondSignedByTwo", oneExpiredOneValidSigner)); 464 entries.add(new JarCertVerifierEntry("thirdSignedByTwo", oneExpiredOneValidSigner)); 465 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 466 467 Assert.assertEquals("Three entries signed by one expired cert and another valid cert, should be considered signed and okay.", 468 VerifyResult.SIGNED_OK, result); 469 Assert.assertEquals("Three entries signed by one expired cert and another valid cert means two signers in the verifier.", 470 2, jcv.getCertsList().size()); 471 Assert.assertTrue("Three entries signed by one expired cert and another valid cert means two signers in the verifier.", 472 jcv.getCertsList().contains(expiredSigner.getSignerCertPath()) 473 && jcv.getCertsList().contains(alphaSigner.getSignerCertPath())); 474 } 475 476 @Test 477 public void testSomeExpiredEntries() throws Exception { 478 JarCertVerifier jcv = new JarCertVerifier(null); 479 CodeSigner[] oneExpiredOneValidSigners = { expiredSigner, alphaSigner }; 480 CodeSigner[] expiredSigners = { expiredSigner }; 481 482 Vector<JarEntry> entries = new Vector<JarEntry>(); 483 entries.add(new JarCertVerifierEntry("firstSignedByTwo", oneExpiredOneValidSigners)); 484 entries.add(new JarCertVerifierEntry("secondSignedByTwo", oneExpiredOneValidSigners)); 485 entries.add(new JarCertVerifierEntry("thirdSignedByExpired", expiredSigners)); 486 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 487 488 Assert.assertEquals("Two entries signed by one expired and one valid cert, third signed by just expired cert, should be considered signed but not okay.", 489 VerifyResult.SIGNED_NOT_OK, result); 490 Assert.assertEquals("Two entries signed by one expired and one valid cert, third signed by just expired cert means one signer in the verifier.", 491 1, jcv.getCertsList().size()); 492 Assert.assertTrue("Two entries signed by one expired and one valid cert, third signed by just expired cert means one signer in the verifier.", 493 jcv.getCertsList().contains(expiredSigner.getSignerCertPath())); 494 } 495 496 @Test 497 public void testManyInvalidOneValidStillSignedOkay() throws Exception { 498 JarCertVerifier jcv = new JarCertVerifier(null); 499 CodeSigner[] oneExpiredOneValidSigners = { alphaSigner, expiredSigner }; 500 CodeSigner[] oneNotYetValidOneValidSigners = { alphaSigner, notYetValidSigner }; 501 CodeSigner[] oneExpiringSigners = { alphaSigner, expiringSigner }; 502 503 Vector<JarEntry> entries = new Vector<JarEntry>(); 504 entries.add(new JarCertVerifierEntry("META-INF/MANIFEST.MF")); 505 entries.add(new JarCertVerifierEntry("firstSigned", oneExpiredOneValidSigners)); 506 entries.add(new JarCertVerifierEntry("secondSigned", oneNotYetValidOneValidSigners)); 507 entries.add(new JarCertVerifierEntry("thirdSigned", oneExpiringSigners)); 508 entries.add(new JarCertVerifierEntry("oneDir/")); 509 entries.add(new JarCertVerifierEntry("oneDir/fourthSigned", oneExpiredOneValidSigners)); 510 VerifyResult result = jcv.verifyJarEntryCerts("", true, entries); 511 512 Assert.assertEquals("Three entries sharing valid cert and others with issues, should be considered signed and okay.", 513 VerifyResult.SIGNED_OK, result); 514 Assert.assertEquals("Three entries sharing valid cert and others with issues means one signer in the verifier.", 515 1, jcv.getCertsList().size()); 516 Assert.assertTrue("Three entries sharing valid cert and others with issues means one signer in the verifier.", 517 jcv.getCertsList().contains(alphaSigner.getSignerCertPath())); 518 } 519 54 520 } -
trunk/icedtea-web/tests/netx/unit/net/sourceforge/jnlp/util/PropertiesFileTest.java
r418 r429 44 44 import java.nio.channels.FileLock; 45 45 import java.nio.channels.OverlappingFileLockException; 46 import net.sourceforge.jnlp.cache.CacheLRUWrapper; 46 47 47 48 import net.sourceforge.jnlp.config.DeploymentConfiguration; … … 62 63 63 64 // does no DeploymentConfiguration exist for this file name? 64 private final String cacheIndexFileName = "recently_used";65 private final String cacheIndexFileName = CacheLRUWrapper.CACHE_INDEX_FILE_NAME; 65 66 66 67 private final PropertiesFile cacheIndexFile = new PropertiesFile(new File(cacheDir + File.separatorChar + cacheIndexFileName)); -
trunk/icedtea-web/tests/netx/unit/net/sourceforge/jnlp/util/replacements/BASE64EncoderTest.java
r418 r429 49 49 public class BASE64EncoderTest { 50 50 51 privatestatic final String sSrc = "abcdefgHIJKLMNOPQrstuvwxyz1234567890\r\n"51 static final String sSrc = "abcdefgHIJKLMNOPQrstuvwxyz1234567890\r\n" 52 52 + "-=+_))(**&&&^^%%$$##@@!!~{}][\":'/\\.,><\n" 53 53 + "+ÄÅ¡ÄÄÅşÜáÃé=ů/úÄÅťšÄÅéÃáÄ"; 54 privatestatic final byte[] encoded = {89, 87, 74, 106, 90, 71, 86, 109, 90,54 static final byte[] encoded = {89, 87, 74, 106, 90, 71, 86, 109, 90, 55 55 48, 104, 74, 83, 107, 116, 77, 84, 85, 53, 80, 85, 70, 70, 121, 99, 51, 56 56 82, 49, 100, 110, 100, 52, 101, 88, 111, 120, 77, 106, 77, 48, 78, 84, … … 64 64 68, 113, 99, 79, 116, 119, 54, 72, 69, 106, 81, 61, 61, 10}; 65 65 66 public static final String sunClassE = "sun.misc.BASE64Encoder"; 67 public static final String sunClassD = "sun.misc.BASE64Decoder"; 66 private static final String sunClassD = "sun.misc.BASE64Decoder"; 68 67 69 68 @Test … … 98 97 byte[] encoded2 = out2.toByteArray(); 99 98 Object decoder = createInsatnce(sunClassD); 100 byte[] decoded = (byte[]) (getAndInvokeMethod(decoder, "decodeBuffer", new String(encoded , "utf-8")));99 byte[] decoded = (byte[]) (getAndInvokeMethod(decoder, "decodeBuffer", new String(encoded2, "utf-8"))); 101 100 Assert.assertArrayEquals(data, decoded); 102 101 Assert.assertEquals(sSrc, new String(decoded, "utf-8")); 103 104 105 106 102 } 103 104 @Test 105 public void testEmbededBase64EncoderAgainstEbededDecoder() throws Exception { 106 final byte[] data = sSrc.getBytes("utf-8"); 107 ByteArrayOutputStream out2 = new ByteArrayOutputStream(); 108 BASE64Encoder e2 = new BASE64Encoder(); 109 e2.encodeBuffer(data, out2); 110 byte[] encoded2 = out2.toByteArray(); 111 BASE64Decoder decoder = new BASE64Decoder(); 112 byte[] decoded = decoder.decodeBuffer(new String(encoded2, "utf-8")); 113 Assert.assertArrayEquals(data, decoded); 114 Assert.assertEquals(sSrc, new String(decoded, "utf-8")); 107 115 } 108 116 109 privatestatic Object createInsatnce(String ofCalss) throws ClassNotFoundException, InstantiationException, IllegalAccessException {117 static Object createInsatnce(String ofCalss) throws ClassNotFoundException, InstantiationException, IllegalAccessException { 110 118 111 Class classDefinition = Class.forName(ofCalss);119 Class<?> classDefinition = Class.forName(ofCalss); 112 120 return classDefinition.newInstance(); 113 121 114 122 } 115 123 116 privatestatic Object getAndInvokeMethod(Object instance, String methodName, Object... params) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {124 static Object getAndInvokeMethod(Object instance, String methodName, Object... params) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { 117 125 Class<?>[] cs = new Class<?>[params.length]; 118 126 for (int i = 0; i < params.length; i++) {
Note:
See TracChangeset
for help on using the changeset viewer.