Skip to content

Commit

Permalink
Add test for JarResultBuildStep#filterJarFile
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Apr 11, 2024
1 parent 1001256 commit 406ab77
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ private void handleParent(FileSystem runnerZipFs, String fileName, Map<String, S
}
}

private void filterJarFile(Path resolvedDep, Path targetPath, Set<String> transformedFromThisArchive) {
static void filterJarFile(Path resolvedDep, Path targetPath, Set<String> transformedFromThisArchive) {
try {
byte[] buffer = new byte[10000];
try (JarFile in = new JarFile(resolvedDep.toFile(), false)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.quarkus.deployment.pkg.steps;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.nio.file.Path;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;

import static org.assertj.core.api.Assertions.assertThat;

class JarResultBuildStepTest {

@Test
void should_unsign_jar_when_filtered(@TempDir Path tempDir) throws Exception {
Path signedJarFilePath = Path.of(getClass().getClassLoader().getResource("signed.jar").toURI());
Path jarFilePath = tempDir.resolve("unsigned.jar");
JarResultBuildStep.filterJarFile(signedJarFilePath, jarFilePath, Set.of("org/eclipse/jgit/transport/sshd/SshdSessionFactory.class"));
try (JarFile jarFile = new JarFile(jarFilePath.toFile())) {
assertThat(jarFile.stream().map(JarEntry::getName)).doesNotContain("META-INF/ECLIPSE_.RSA", "META-INF/ECLIPSE_.SF");
// Check that the manifest is still present
Manifest manifest = jarFile.getManifest();
assertThat(manifest.getMainAttributes()).isNotEmpty();
assertThat(manifest.getEntries()).isEmpty();
}
}
}
Binary file added core/deployment/src/test/resources/signed.jar
Binary file not shown.

0 comments on commit 406ab77

Please sign in to comment.