Added JarFileTests to test signed jars. development
authorJan Vrany <jan.vrany@fit.cvut.cz>
Fri, 06 Sep 2013 10:36:57 +0100
branchdevelopment
changeset 2712 69af63cd04a3
parent 2711 a00302fe5083
child 2713 d87e89dd5276
Added JarFileTests to test signed jars. As of 2013-09-06, reading and verifying signed jar works in interpreted mode but fails when JIT is on.
tests/libjava/src/stx/libjava/tests/lib/java/util/jar/JarFileTests.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/src/stx/libjava/tests/lib/java/util/jar/JarFileTests.java	Fri Sep 06 10:36:57 2013 +0100
@@ -0,0 +1,68 @@
+package stx.libjava.tests.lib.java.util.jar;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.cert.Certificate;
+import java.util.Enumeration;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.junit.Test;
+
+/**
+ * Regression tests for JarFile 
+ * 
+ * @author Jan Vrany <jan.vrany [at] fit.cvut.cz>
+ *
+ */
+public class JarFileTests {
+    
+    /**
+     * This test tests signed JAR files. As of 2013-09-06, it works
+     * in interpeted mode but fails when JIT is on. 
+     */     
+    @Test    
+    public void signed_jar_01() {
+        String jarfile = System.getProperty("libjava.tests.dir", "..") + "/libjava-mauve/src/gnu/testlet/java/util/jar/JarFile/jfaceSmall.jar";
+        try {
+            JarFile jar = new JarFile(jarfile);
+            for (Enumeration<JarEntry> entries = jar.entries(); entries.hasMoreElements();) {
+                JarEntry entry = entries.nextElement();
+                if (entry.isDirectory()) {
+                    continue;
+                }
+                InputStream stream = null;
+                try {
+                    stream = jar.getInputStream(entry);
+                    byte[] ba = new byte[8192];
+                    int n;
+                    while ((n = stream.read(ba)) >= 0)
+                  /* keep reading */;
+                } finally {
+                    if (stream != null) {
+                        try {
+                            stream.close();
+                        } catch (IOException ignored) {
+                        }
+                    }
+                }
+                Certificate[] certs = entry.getCertificates();
+                if (certs == null || certs.length == 0) // No certificate
+                {
+                    if (!entry.getName().startsWith("META-INF")) {
+                        assertTrue("Entry " + entry.getName() + " in jar file "
+                              + jarfile + " does not have a certificate", false);                        
+                    }
+                }
+            }
+            
+        } catch (IOException e) {            
+            e.printStackTrace();
+            assertTrue(e.getMessage(), false);
+        }
+
+    }
+
+}