|
3 | 3 | import org.junit.jupiter.api.Test;
|
4 | 4 | import org.junit.jupiter.params.ParameterizedTest;
|
5 | 5 | import org.junit.jupiter.params.provider.ValueSource;
|
| 6 | +import org.objectweb.asm.ClassReader; |
| 7 | +import org.objectweb.asm.ClassWriter; |
6 | 8 | import software.coley.lljzip.format.compression.ZipCompressions;
|
7 | 9 | import software.coley.lljzip.format.model.LocalFileHeader;
|
8 | 10 | import software.coley.lljzip.format.model.ZipArchive;
|
|
14 | 16 | import java.io.IOException;
|
15 | 17 | import java.nio.file.Path;
|
16 | 18 | import java.nio.file.Paths;
|
| 19 | +import java.util.List; |
17 | 20 |
|
18 | 21 | import static org.junit.jupiter.api.Assertions.*;
|
19 | 22 |
|
@@ -105,6 +108,35 @@ public void testConcatAndMerged(String name) {
|
105 | 108 | }
|
106 | 109 | }
|
107 | 110 |
|
| 111 | + @ParameterizedTest |
| 112 | + @ValueSource(strings = { |
| 113 | + "hello-concat.jar", |
| 114 | + "hello-concat-junkheader.jar", |
| 115 | + "hello-merged.jar", |
| 116 | + "hello-merged-fake-empty.jar", |
| 117 | + "hello-merged-junkheader.jar", |
| 118 | + "hello-secret-0-length-locals.jar", |
| 119 | + "hello-secret-junkheader.jar", |
| 120 | + "hello-secret-trailing-slash.jar", |
| 121 | + "hello-secret-trailing-slash-0-length-locals.jar", |
| 122 | + }) |
| 123 | + public void testJvmCanRecoverData(String name) { |
| 124 | + try { |
| 125 | + Path path = Paths.get("src/test/resources/" + name); |
| 126 | + ZipArchive zip = ZipIO.readJvm(path); |
| 127 | + List<LocalFileHeader> localFiles = zip.getNameFilteredLocalFiles(n -> n.contains(".class")); |
| 128 | + assertEquals(1, localFiles.size(), "More than 1 class"); |
| 129 | + byte[] decompressed = ByteDataUtil.toByteArray(ZipCompressions.decompress(localFiles.get(0))); |
| 130 | + assertDoesNotThrow(() -> { |
| 131 | + ClassWriter cw = new ClassWriter(0); |
| 132 | + ClassReader cr = new ClassReader(decompressed); |
| 133 | + cr.accept(cw, 0); |
| 134 | + }, "Failed to read class, must have failed to decompress"); |
| 135 | + } catch (IOException ex) { |
| 136 | + fail(ex); |
| 137 | + } |
| 138 | + } |
| 139 | + |
108 | 140 | @Test
|
109 | 141 | public void testLocalHeaderDetectMismatch() {
|
110 | 142 | Path path = Paths.get("src/test/resources/hello-secret-0-length-locals.jar");
|
|
0 commit comments