View Javadoc

1   package org.apache.maven.shared.jarsigner;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  import org.codehaus.plexus.PlexusTestCase;
22  import org.codehaus.plexus.util.FileUtils;
23  
24  import java.io.File;
25  
26  /**
27   * @author Olivier Lamy
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  }