Test the migration of signed jar files
diff --git a/pom.xml b/pom.xml
index b66f833..3ddfc68 100644
--- a/pom.xml
+++ b/pom.xml
@@ -136,6 +136,21 @@
<attribute name="Implementation-Version" value="1.2.3"/>
</manifest>
</jar>
+
+ <parallel>
+ <sequential>
+ <copy file="target/test-classes/hellocgi.jar" tofile="target/test-classes/hellocgi-signed-rsa.jar"/>
+ <signjar jar="target/test-classes/hellocgi-signed-rsa.jar" keystore="src/test/resources/keystore.p12" storepass="apache" alias="rsa"/>
+ </sequential>
+ <sequential>
+ <copy file="target/test-classes/hellocgi.jar" tofile="target/test-classes/hellocgi-signed-dsa.jar"/>
+ <signjar jar="target/test-classes/hellocgi-signed-dsa.jar" keystore="src/test/resources/keystore.p12" storepass="apache" alias="dsa"/>
+ </sequential>
+ <sequential>
+ <copy file="target/test-classes/hellocgi.jar" tofile="target/test-classes/hellocgi-signed-ec.jar"/>
+ <signjar jar="target/test-classes/hellocgi-signed-ec.jar" keystore="src/test/resources/keystore.p12" storepass="apache" alias="ec"/>
+ </sequential>
+ </parallel>
</target>
</configuration>
</execution>
diff --git a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
index 9ba59b0..418b57f 100644
--- a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
+++ b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
@@ -163,4 +163,33 @@
assertNotEquals("Implementation-Version manifest attribute not changed", "1.2.3", implementationVersion);
assertTrue("Implementation-Version manifest attribute doesn't match the expected pattern", implementationVersion.matches("1\\.2\\.3-migrated-[\\d\\.]+.*"));
}
+
+ @Test
+ public void testMigrateSignedJarFileRSA() throws Exception {
+ testMigrateSignedJarFile("rsa");
+ }
+
+ @Test
+ public void testMigrateSignedJarFileDSA() throws Exception {
+ testMigrateSignedJarFile("dsa");
+ }
+
+ @Test
+ public void testMigrateSignedJarFileEC() throws Exception {
+ testMigrateSignedJarFile("ec");
+ }
+
+ private void testMigrateSignedJarFile(String algorithm) throws Exception {
+ File jarFile = new File("target/test-classes/hellocgi-signed-" + algorithm + ".jar");
+
+ Migration migration = new Migration();
+ migration.setSource(jarFile);
+ migration.setDestination(jarFile);
+ migration.execute();
+
+ JarFile jar = new JarFile(jarFile);
+ assertNull("Digest not removed from the manifest", jar.getManifest().getAttributes("org/apache/tomcat/jakartaee/HelloCGI.class"));
+ assertNull("Signature key not removed", jar.getEntry("META-INF/" + algorithm.toUpperCase() + "." + algorithm.toUpperCase()));
+ assertNull("Signed manifest not removed", jar.getEntry("META-INF/" + algorithm.toUpperCase() + ".SF"));
+ }
}
diff --git a/src/test/resources/keystore.p12 b/src/test/resources/keystore.p12
new file mode 100644
index 0000000..6f1cf7a
--- /dev/null
+++ b/src/test/resources/keystore.p12
Binary files differ