File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\test\java\jenkins\RemotingJarSignatureTest.java.html

1 package jenkins;
2
3 import hudson.remoting.Channel;
4 import hudson.remoting.Which;
5 import hudson.util.IOUtils;
6 import org.apache.commons.io.output.NullOutputStream;
7 import org.junit.Assert;
8 import org.junit.Test;
9
10 import java.io.File;
11 import java.util.Enumeration;
12 import java.util.jar.JarEntry;
13 import java.util.jar.JarFile;
14
15 /**
16 * @author Kohsuke Kawaguchi
17 */
18 public class RemotingJarSignatureTest {
19 /**
20 * Makes sure that the remoting jar is properly signed.
21 */
22 @Test
23 public void testSignature() throws Exception {
24 File jar = Which.jarFile(Channel.class);
25 // File jar = new File("/home/kohsuke/.m2/repository/org/jenkins-ci/main/remoting/1.421/remoting-1.421.jar");
26 // File jar = new File("/home/kohsuke/.m2/repository/org/jenkins-ci/main/remoting/2.0/remoting-2.0.jar");
27 System.out.println("Verifying "+jar);
28
29 JarFile myJar = new JarFile(jar,true);
30
31 Enumeration<JarEntry> entries = myJar.entries();
32 while (entries.hasMoreElements()) {
33 JarEntry entry = entries.nextElement();
34 if (entry.isDirectory()) continue;
35
36 // unsigned files that are related to signatures
37 String name = entry.getName();
38 if (name.equals("META-INF/MANIFEST.MF")) continue;
39 if (name.startsWith("META-INF/") && name.endsWith(".SF")) continue;
40 if (name.startsWith("META-INF/") && name.endsWith(".RSA")) continue;
41 if (name.startsWith("META-INF/") && name.endsWith(".DSA")) continue;
42
43 // make sure bits are signed
44 IOUtils.copy(myJar.getInputStream(entry), new NullOutputStream());
45 if (entry.getCodeSigners()==null) {
46 Assert.fail("No signature for " + name);
47 }
48 }
49 }
50 }
51