This is the mail archive of the mauve-patches@sourceware.org mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: URLClassLoader test fixed and addition


Hi,
  the retrieval of resource isn't very well defined in the API so I
added some more tests in the related testlet, based on a patch
proposition by Robin Green
(http://sourceware.org/ml/mauve-patches/2004/msg00118.html) and extended
with ".." tests and invalid directories. It has just been checked in.
  Now this testlet works fine with the SUN jre and jamvm with a
classpath patch which is on its way to the classpath ML (which deals
with ".."). Cacao still behaves a bit differently but it should be fixed
quickly.

  Cheers

+Olivier

	2006-03-07  Olivier Jolly  <olivier.jolly@pcedev.com>
	
	* gnu/testlet/java/net/URLClassLoader/getResourceBase.java (check): Added
	canonalization of tested filenames.
	* gnu/testlet/java/net/URLCLassLoader/getResource.java (test, setup): Added
	more special situations checks with ".." and invalid directories. Fixed
	and documented existing checks dealing with directories.
	Based on Robin Green's patch.


Index: gnu/testlet/java/net/URLClassLoader/getResource.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/net/URLClassLoader/getResource.java,v
retrieving revision 1.6
diff -u -r1.6 getResource.java
--- gnu/testlet/java/net/URLClassLoader/getResource.java	3 Jun 2004 14:31:12 -0000	1.6
+++ gnu/testlet/java/net/URLClassLoader/getResource.java	7 Mar 2006 20:27:26 -0000
@@ -1,7 +1,7 @@
 // Tags: JDK1.2
 // Uses: getResourceBase
 
-// Copyright (C) 2002 Free Software Foundation, Inc.
+// Copyright (C) 2002, 2006 Free Software Foundation, Inc.
 // Written by Mark Wielaard (mark@klomp.org)
 
 // This file is part of Mauve.
@@ -70,6 +70,8 @@
     jos.putNextEntry(je);
     jos.write(new byte[256]);
 
+    je = new JarEntry("path/in/jar/");
+    jos.putNextEntry(je);
     je = new JarEntry("path/in/jar/file");
     jos.putNextEntry(je);
     jos.write(new byte[256]);
@@ -110,18 +112,67 @@
 	urls[1] = new URL("file://" + jarPath);
 	ucl = URLClassLoader.newInstance(urls);
 
+        // Check that the root resource can be found
+        // It is valid as a directory
 	URL u = ucl.getResource(".");
 	harness.debug(u != null ? u.toString() : null);
-	harness.check(u == null, "no .");
+	harness.check(u != null, "Checking .");
 
+        // Check that the parent directory can not be found
+        // It is invalid as one shouldn't be able to escape the "url root"
 	u = ucl.getResource("..");
 	harness.debug(u != null ? u.toString() : null);
-	harness.check(u == null, "no ..");
+	harness.check(u == null, "Checking ..");
 
+        // Check that the current directory can not be found
+        // It is invalid because at one point, we're escaping the "url root"
+        u = ucl.getResource("../mauve-testdir");
+        harness.debug(u != null ? u.toString() : null);
+        harness.check(u == null, "Checking ../mauve-testdir");
+        
+        // Check that the current directory can not be found
+        // It is invalid because at one point, we're walking into an invalid directory
+        u = ucl.getResource("mauve-testdir/..");
+        harness.debug(u != null ? u.toString() : null);
+        harness.check(u == null, "Checking mauve-testdir/..");
+
+        // Check that the current directory can not be found
+        // It is invalid because at one point, we're walking into an invalid directory
+        u = ucl.getResource("mauve-testdir/../");
+        harness.debug(u != null ? u.toString() : null);
+        harness.check(u == null, "Checking mauve-testdir/../");
+
+        // Check that the current directory can be found
+        // It is valid because we're walking into an valid directory and back
+        u = ucl.getResource("testdir/..");
+        harness.debug(u != null ? u.toString() : null);
+        harness.check(u != null, "Checking testdir/..");
+
+        // Check that the current directory can be found
+        // It is valid because we're walking into an valid directory and back
+        u = ucl.getResource("testdir/../");
+        harness.debug(u != null ? u.toString() : null);
+        harness.check(u != null, "Checking testdir/../");        
+        
+        // Check that the testdir subdirectory can not be found
+        // It is invalid because at one point, we're walking into an invalid directory
+        u = ucl.getResource("mauve-testdir/../testdir");
+        harness.debug(u != null ? u.toString() : null);
+        harness.check(u == null, "Checking mauve-testdir/../testdir");        
+        
+        // Check that the testdir subdirectory can be found
+        // It is valid because we're walking into an valid directory and back
+        // and into a valid directory again
+        u = ucl.getResource("testdir/../testdir");
+        harness.debug(u != null ? u.toString() : null);
+        harness.check(u != null, "Checking testdir/../testdir");        
+        
 	check("testfile", "mauve-testdir", true);
+	check("testdir", "mauve-testdir", true);
 	check("testdir/test", "mauve-testdir", true);
 	check("jresource", "m.jar", false);
 	check("path/in/jar/file", "m.jar", false);
+	check("path/in/jar", "m.jar", false);
       }
     catch(IOException ioe)
       {
Index: gnu/testlet/java/net/URLClassLoader/getResourceBase.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/net/URLClassLoader/getResourceBase.java,v
retrieving revision 1.4
diff -u -r1.4 getResourceBase.java
--- gnu/testlet/java/net/URLClassLoader/getResourceBase.java	3 Jun 2004 14:31:12 -0000	1.4
+++ gnu/testlet/java/net/URLClassLoader/getResourceBase.java	7 Mar 2006 20:27:26 -0000
@@ -1,6 +1,6 @@
 // Tags: not-a-test
 
-// Copyright (C) 2002 Free Software Foundation, Inc.
+// Copyright (C) 2002, 2006 Free Software Foundation, Inc.
 // Written by Mark Wielaard (mark@klomp.org)
 
 // This file is part of Mauve.
@@ -22,12 +22,13 @@
 
 package gnu.testlet.java.net.URLClassLoader;
 
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.io.File;
 import java.net.URL;
 import java.net.URLClassLoader;
 
-import gnu.testlet.Testlet;
-import gnu.testlet.TestHarness;
-
 /**
  * Helper class for getResource classes that checks resources when
  * URLClassLoader is set.
@@ -54,7 +55,25 @@
     if (u != null)
       {
 	String f = u.getFile();
-	int i = f.indexOf(fullpath);
+        File file = new File(u.getFile());
+
+        // Canonize filenames. If the file is a directory, makes sure both filenames
+        // end with a slash
+        if (file.isDirectory()
+            && fullpath.length() > 1
+            && (fullpath.charAt(fullpath.length() - 1) != File.separator.charAt(0)))
+          {
+            fullpath = fullpath + File.separator;
+          }
+        
+        if (file.isDirectory()
+            && f.length() > 1
+            && f.charAt(f.length() - 1) != File.separator.charAt(0))
+          {
+            f = f + File.separator;
+          }
+        
+	int i = f.indexOf(fullpath);         
 	if (i != -1)
 	  r = f.substring(f.length() - fullpath.length());
 	else

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]