1 package org.apache.maven.shared.jarsigner;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import org.codehaus.plexus.PlexusTestCase;
22 import org.codehaus.plexus.util.FileUtils;
23
24 import java.io.File;
25
26
27
28
29 public class SimpleJarSignTest
30 extends PlexusTestCase
31 {
32
33 public void testSimpleSign()
34 throws Exception
35 {
36 File file = new File( "src/test/simple.jar" );
37 File target = new File( "target/simple.jar" );
38
39 if ( target.exists() )
40 {
41 FileUtils.forceDelete( target );
42 }
43
44 FileUtils.copyFile( file, target );
45
46 JarSignerSignRequest jarSignerRequest = buildJarSignerRequest( target );
47
48 JarSigner jarSigner = (JarSigner) lookup( JarSigner.class.getName() );
49
50 JarSignerResult jarSignerResult = jarSigner.execute( jarSignerRequest );
51 assertEquals( "not exit code 0 " + jarSignerResult.getExecutionException(), 0, jarSignerResult.getExitCode() );
52
53
54 }
55
56 public void testSimpleSignAdVerify()
57 throws Exception
58 {
59 File file = new File( "src/test/simple.jar" );
60 File target = new File( "target/simple.jar" );
61
62 if ( target.exists() )
63 {
64 FileUtils.forceDelete( target );
65 }
66
67 FileUtils.copyFile( file, target );
68
69 JarSignerSignRequest jarSignerRequest = buildJarSignerRequest( target );
70
71 JarSigner jarSigner = (JarSigner) lookup( JarSigner.class.getName() );
72
73 JarSignerResult jarSignerResult = jarSigner.execute( jarSignerRequest );
74
75 assertEquals( "not exit code 0 " + jarSignerResult.getExecutionException(), 0, jarSignerResult.getExitCode() );
76
77 JarSignerVerifyRequest request = new JarSignerVerifyRequest();
78 request.setCerts( true );
79 request.setVerbose( true );
80 request.setArchive( new File( "target/ssimple.jar" ) );
81
82 jarSignerResult = jarSigner.execute( request );
83 assertEquals( "not exit code 0 " + jarSignerResult.getExecutionException(), 0, jarSignerResult.getExitCode() );
84
85 }
86
87 protected JarSignerSignRequest buildJarSignerRequest( File target )
88 {
89 JarSignerSignRequest jarSignerRequest = new JarSignerSignRequest();
90 jarSignerRequest.setArchive( target );
91 jarSignerRequest.setKeystore( "src/test/keystore" );
92 jarSignerRequest.setVerbose( true );
93 jarSignerRequest.setAlias( "foo_alias" );
94 jarSignerRequest.setKeypass( "key-passwd" );
95 jarSignerRequest.setStorepass( "changeit" );
96 jarSignerRequest.setSignedjar( new File( "target/ssimple.jar" ) );
97 return jarSignerRequest;
98 }
99 }