harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghar...@apache.org
Subject svn commit: r391368 - in /incubator/harmony/enhanced/classlib/trunk/modules/archive/src: main/java/java/util/jar/ test/java/tests/api/java/util/jar/ test/java/tests/archive/
Date Tue, 04 Apr 2006 17:17:06 GMT
Author: gharley
Date: Tue Apr  4 10:17:04 2006
New Revision: 391368

URL: http://svn.apache.org/viewcvs?rev=391368&view=rev
Log:
HARMONY-295 : New implementation and test code. Test cases complete successfully against both
5.0 RI and Harmony.
InitManifest.java contains small mod to fix boundary condition failure that was noticed after
the changes to 
related issue HARMONY-204 were committed.   

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarInputStream.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/JarInputStreamTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/archive/AllTests.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java?rev=391368&r1=391367&r2=391368&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
Tue Apr  4 10:17:04 2006
@@ -143,7 +143,12 @@
 					if (blankline)
 						addLine(pos, lines);
 					return out.toByteArray();
-				}
+                } else {
+                    if (inbufCount == inbuf.length && in.available() == 0) {
+                        /* KA000 = "line too long" */
+                        throw new IOException(Msg.getString("KA000"));
+                    }
+                } 
 				inbufPos = 0;
 			}
 			next = inbuf[inbufPos++];

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarInputStream.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarInputStream.java?rev=391368&r1=391367&r2=391368&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarInputStream.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarInputStream.java
Tue Apr  4 10:17:04 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -45,8 +45,9 @@
 	public JarInputStream(InputStream stream, boolean verify)
 			throws IOException {
 		super(stream);
-		if (verify)
-			verifier = new JarVerifier("JarInputStream");
+		if (verify) {
+			verifier = new JarVerifier("JarInputStream");			
+		}
 		if ((mEntry = getNextJarEntry()) == null)
 			return;
 		String name = mEntry.getName().toUpperCase();
@@ -60,12 +61,20 @@
 			mEntry = null;
 			manifest = new Manifest(this, verify);
 			closeEntry();
-			if (verify)
+			if (verify) {
 				verifier.setManifest(manifest);
+				if (manifest != null)
+					verifier.mainAttributesChunk = manifest
+							.getMainAttributesChunk();
+			}
+
 		} else {
 			Attributes temp = new Attributes(3);
 			temp.map.put("hidden", null);
 			mEntry.setAttributes(temp);
+			/* if not from the first entry, we will not get
+			 enough information,so no verify will be taken out.*/
+			verifier = null;
 		}
 	}
 
@@ -101,16 +110,28 @@
 		int r = super.read(buffer, offset, length);
 		if (verStream != null && !eos) {
 			if (r == -1) {
-				eos = true;
-				if (isMeta) {
-					verifier.addMetaEntry(jarEntry.getName(),
-							((ByteArrayOutputStream) verStream).toByteArray());
-					verifier.readCertificates();
-				} else
-					verifier.verifySignatures(
-							(JarVerifier.VerifierEntry) verStream, jarEntry);
-			} else
+				eos = true;				
+				if (verifier != null) {
+					if (isMeta) {
+						verifier.addMetaEntry(jarEntry.getName(),
+								((ByteArrayOutputStream) verStream)
+					    					.toByteArray());
+						try {
+							verifier.readCertificates();
+						} catch (SecurityException e) {
+							verifier = null;
+							throw e;
+						}
+					}
+					else {
+                        verifier.verifySignatures(
+                                (JarVerifier.VerifierEntry) this.verStream,
+                                jarEntry);
+                    }
+				}
+			} else {
 				verStream.write(buffer, offset, r);
+            }
 		}
 		return r;
 	}
@@ -124,25 +145,26 @@
 	 *                If an error occurs while reading the entry
 	 */
 	public ZipEntry getNextEntry() throws IOException {
-		eos = false;
 		if (mEntry != null) {
 			jarEntry = mEntry;
 			mEntry = null;
-			jarEntry.setAttributes(null);
-			return jarEntry;
-		}
-		jarEntry = (JarEntry) super.getNextEntry();
-		if (jarEntry == null)
-			return null;
-		if (verifier != null) {
-			isMeta = jarEntry.getName().toUpperCase().startsWith(
-					JarFile.META_DIR);
-			if (isMeta) {
-				verStream = new ByteArrayOutputStream();
-			} else {
-				verStream = verifier.initEntry(jarEntry.getName());
-			}
+			jarEntry.setAttributes(null);			
 		}
+		else {
+            jarEntry = (JarEntry) super.getNextEntry();
+            if (jarEntry == null)
+                return null;
+            if (verifier != null) {
+                isMeta = jarEntry.getName().toUpperCase().startsWith(
+                        JarFile.META_DIR);
+                if (isMeta) {
+                    verStream = new ByteArrayOutputStream();
+                } else {
+                    verStream = verifier.initEntry(jarEntry.getName());
+                }
+            }
+        }
+		eos = false;			
 		return jarEntry;
 	}
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/JarInputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/JarInputStreamTest.java?rev=391368&r1=391367&r2=391368&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/JarInputStreamTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/JarInputStreamTest.java
Tue Apr  4 10:17:04 2006
@@ -15,7 +15,7 @@
 package tests.api.java.util.jar;
 
 
-
+import java.io.IOException;
 import java.net.URL;
 import java.util.Arrays;
 import java.util.HashSet;
@@ -23,6 +23,7 @@
 import java.util.jar.JarEntry;
 import java.util.jar.JarInputStream;
 import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
 
 import tests.support.resource.Support_Resources;
 
@@ -37,6 +38,12 @@
 
 	final String entryName2 = "Blah.txt";
 
+    private static int indexofDSA = 2;
+
+    private static int indexofTESTCLASS = 4;
+
+    private static int totalEntries = 4;
+
 	/**
 	 * @tests java.util.jar.JarInputStream#JarInputStream(java.io.InputStream)
 	 */
@@ -114,6 +121,229 @@
 		assertTrue("Set of entries is not correct", actual.equals(desired));
 	}
 
+    public void test_JarInputStream_Integrate_Jar_getNextEntry()
+            throws IOException {
+        String intJarName = Support_Resources.getURL("Integrate.jar");
+        java.io.InputStream is = new URL(intJarName).openConnection()
+                .getInputStream();
+        JarInputStream jin = new JarInputStream(is, true);
+        ZipEntry entry = null;
+        int count = 0;
+        while (count == 0 || entry != null) {
+            count++;
+            entry = jin.getNextEntry();
+        }
+        assertEquals(totalEntries + 1, count);
+        jin.close();
+    }
+
+    public void test_JarInputStream_Modified_Class_getNextEntry()
+            throws IOException {
+        String modJarName = Support_Resources.getURL("Modified_Class.jar");
+        java.io.InputStream is = new URL(modJarName).openConnection()
+                .getInputStream();
+        JarInputStream jin = new JarInputStream(is, true);
+        ZipEntry zipEntry = null;
+
+        int count = 0;
+        while (count == 0 || zipEntry != null) {
+            count++;
+            try {
+                zipEntry = jin.getNextEntry();
+                if (count == indexofTESTCLASS + 1)
+                    fail("Should throw Security Exception");
+            } catch (SecurityException e) {
+                if (count != indexofTESTCLASS + 1)
+                    throw e;
+
+            }
+        }
+        assertEquals(totalEntries + 2, count);
+        jin.close();
+    }
+
+    public void test_JarInputStream_Modified_Manifest_MainAttributes_getNextEntry()
+            throws IOException {
+        String modJarName = Support_Resources.getURL("Modified_Manifest_MainAttributes.jar");
+        java.io.InputStream is = new URL(modJarName).openConnection()
+                .getInputStream();
+        JarInputStream jin = new JarInputStream(is, true);
+        ZipEntry zipEntry = null;
+
+        final int indexofDSA = 2;
+        final int totalEntries = 4;
+        int count = 0;
+        while (count == 0 || zipEntry != null) {
+            count++;
+            try {
+                zipEntry = jin.getNextEntry();
+                if (count == indexofDSA + 1)
+                    fail("Should throw Security Exception");
+            } catch (SecurityException e) {
+                if (count != indexofDSA + 1)
+                    throw e;
+            }
+        }
+        assertEquals(totalEntries + 2, count);
+        jin.close();
+    }
+
+    public void test_JarInputStream_Modified_Manifest_EntryAttributes_getNextEntry()
+            throws IOException {
+        String modJarName = Support_Resources
+                .getURL("Modified_Manifest_EntryAttributes.jar");
+        java.io.InputStream is = new URL(modJarName).openConnection()
+                .getInputStream();
+        JarInputStream jin = new JarInputStream(is, true);
+        ZipEntry zipEntry = null;
+
+        int count = 0;
+        while (count == 0 || zipEntry != null) {
+            count++;
+            try {
+                zipEntry = jin.getNextEntry();
+                if (count == indexofDSA + 1)
+                    fail("Should throw Security Exception");
+            } catch (SecurityException e) {
+                if (count != indexofDSA + 1)
+                    throw e;
+            }
+        }
+        assertEquals(totalEntries + 2, count);
+        jin.close();
+    }
+
+    public void test_JarInputStream_Modified_SF_EntryAttributes_getNextEntry()
+            throws IOException {
+        String modJarName = Support_Resources
+                .getURL("Modified_SF_EntryAttributes.jar");
+        java.io.InputStream is = new URL(modJarName).openConnection()
+                .getInputStream();
+        JarInputStream jin = new JarInputStream(is, true);
+        ZipEntry zipEntry = null;
+
+        int count = 0;
+        while (count == 0 || zipEntry != null) {
+            count++;
+            try {
+                zipEntry = jin.getNextEntry();
+                if (count == indexofDSA + 1)
+                    fail("Should throw Security Exception");
+            } catch (SecurityException e) {
+                if (count != indexofDSA + 1)
+                    throw e;
+            }
+        }
+        assertEquals(totalEntries + 2, count);
+        jin.close();
+    }
+
+    public void test_JarInputStream_Modified_Class_read() throws IOException {
+        String modJarName = Support_Resources.getURL("Modified_Class.jar");
+        java.io.InputStream is = new URL(modJarName).openConnection()
+                .getInputStream();
+        JarInputStream jin = new JarInputStream(is, true);
+        int count = 0;
+        ZipEntry zipEntry = null;
+        while (count == 0 || zipEntry != null) {
+            count++;
+            zipEntry = jin.getNextEntry();
+            byte[] buffer = new byte[1024];
+            try {
+                int length = 0;
+                while (length >= 0) {
+                    length = jin.read(buffer);
+                }
+                if (count == indexofTESTCLASS)
+                    fail("Should throw Security Exception");
+            } catch (SecurityException e) {
+                if (count < indexofTESTCLASS)
+                    throw e;
+            }
+        }
+        assertEquals(totalEntries + 1, count);
+        jin.close();
+    }
+
+    public void test_Integrate_Jar_read() throws IOException {
+        String intJarName = Support_Resources.getURL("Integrate.jar");
+        java.io.InputStream is = new URL(intJarName).openConnection()
+                .getInputStream();
+        JarInputStream jin = new JarInputStream(is, true);
+        int count = 0;
+        ZipEntry zipEntry = null;
+        while (count == 0 || zipEntry != null) {
+            count++;
+            zipEntry = jin.getNextEntry();
+            byte[] buffer = new byte[1024];
+            int length = 0;
+            while (length >= 0) {
+                length = jin.read(buffer);
+            }
+
+        }
+        assertEquals(totalEntries + 1, count);
+        jin.close();
+    }
+
+    public void test_JarInputStream_Modified_Manifest_MainAttributes_read()
+            throws IOException {
+        String modJarName = Support_Resources
+                .getURL("Modified_Manifest_MainAttributes.jar");
+        java.io.InputStream is = new URL(modJarName).openConnection()
+                .getInputStream();
+        JarInputStream jin = new JarInputStream(is, true);
+        int count = 0;
+        ZipEntry zipEntry = null;
+        while (count == 0 || zipEntry != null) {
+            count++;
+            zipEntry = jin.getNextEntry();
+            byte[] buffer = new byte[1024];
+            try {
+                int length = 0;
+                while (length >= 0) {
+                    length = jin.read(buffer);
+                }
+                if (count == indexofDSA)
+                    fail("Should throw Security Exception");
+            } catch (SecurityException e) {
+                if (count != indexofDSA)
+                    throw e;
+            }
+        }
+        assertEquals(totalEntries + 1, count);
+        jin.close();
+    }
+
+    public void test_JarInputStream_Modified_SF_EntryAttributes_read()
+            throws IOException {
+        String modJarName = Support_Resources
+                .getURL("Modified_SF_EntryAttributes.jar");
+        java.io.InputStream is = new URL(modJarName).openConnection()
+                .getInputStream();
+        JarInputStream jin = new JarInputStream(is, true);
+        int count = 0;
+        ZipEntry zipEntry = null;
+        while (count == 0 || zipEntry != null) {
+            count++;
+            zipEntry = jin.getNextEntry();
+            byte[] buffer = new byte[1024];
+            try {
+                int length = 0;
+                while (length >= 0) {
+                    length = jin.read(buffer);
+                }
+                if (count == indexofDSA)
+                    fail("Should throw Security Exception");
+            } catch (SecurityException e) {
+                if (count != indexofDSA)
+                    throw e;
+            }
+        }
+        assertEquals(totalEntries + 1, count);
+        jin.close();
+    }    
+    
 	/**
 	 * Sets up the fixture, for example, open a network connection. This method
 	 * is called before a test is executed.

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/archive/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/archive/AllTests.java?rev=391368&r1=391367&r2=391368&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/archive/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/archive/AllTests.java
Tue Apr  4 10:17:04 2006
@@ -32,6 +32,8 @@
 		// $JUnit-BEGIN$
 		suite.addTest(tests.api.java.util.jar.AllTests.suite());
 		suite.addTest(tests.api.java.util.zip.AllTests.suite());
+        suite.addTest(org.apache.harmony.tests.java.util.jar.AllTests.suite());
+        suite.addTest(org.apache.harmony.tests.java.util.zip.AllTests.suite());
 		// $JUnit-END$
 		return suite;
 	}



Mime
View raw message