View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.shared.jarsigner;
20  
21  import javax.inject.Inject;
22  
23  import java.io.File;
24  
25  import org.apache.maven.shared.utils.cli.javatool.JavaToolResult;
26  import org.junit.jupiter.api.Test;
27  
28  import static org.junit.jupiter.api.Assertions.assertEquals;
29  
30  /**
31   * @author Olivier Lamy
32   */
33  class SimpleJarSignTest extends AbstractJarSignerTest {
34      @Inject
35      private JarSigner jarSigner;
36  
37      @Test
38      void checkSimpleSign() throws Exception {
39          File target = prepareTestJar("simple.jar");
40  
41          JarSignerSignRequest jarSignerRequest = new JarSignerSignRequest();
42          jarSignerRequest.setArchive(target);
43          jarSignerRequest.setKeystore("src/test/keystore");
44          jarSignerRequest.setVerbose(true);
45          jarSignerRequest.setAlias("foo_alias");
46          jarSignerRequest.setKeypass("key-passwd");
47          jarSignerRequest.setStorepass("changeit");
48          jarSignerRequest.setSignedjar(new File("target/ssimple.jar"));
49  
50          JavaToolResult jarSignerResult = jarSigner.execute(jarSignerRequest);
51  
52          assertEquals(0, jarSignerResult.getExitCode(), "not exit code 0 " + jarSignerResult.getExecutionException());
53      }
54  
55      @Test
56      void simpleSignAndVerify() throws Exception {
57          checkSimpleSign();
58  
59          JarSignerVerifyRequest request = new JarSignerVerifyRequest();
60          request.setCerts(true);
61          request.setVerbose(true);
62          request.setArchive(new File("target/ssimple.jar"));
63          request.setKeystore("src/test/keystore");
64          request.setAlias("foo_alias");
65          request.setStorepass("changeit");
66  
67          JavaToolResult jarSignerResult = jarSigner.execute(request);
68  
69          assertEquals(0, jarSignerResult.getExitCode(), "not exit code 0 " + jarSignerResult.getExecutionException());
70      }
71  }