1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.bcel.util;
21
22 import static org.junit.jupiter.api.Assertions.assertThrows;
23 import static org.junit.jupiter.api.Assertions.assertTrue;
24
25 import java.io.File;
26 import java.io.IOException;
27
28 import org.apache.bcel.Const;
29 import org.apache.bcel.classfile.JavaClass;
30 import org.apache.bcel.generic.ClassGen;
31 import org.junit.jupiter.api.Test;
32
33
34
35
36
37
38 class Class2HTMLTraversalTest {
39
40 private static File outputDir() {
41 final File outputDir = new File("target/test-output/html-traversal");
42 if (!outputDir.mkdirs()) {
43 assertTrue(outputDir.isDirectory());
44 }
45 return outputDir;
46 }
47
48 @Test
49 void testRejectsClassNameWithDriveDesignator() {
50 final JavaClass jc = new ClassGen("C:pwn", "java.lang.Object", "pwn.java", Const.ACC_PUBLIC, null).getJavaClass();
51 assertThrows(IOException.class, () -> new Class2HTML(jc, outputDir().getAbsolutePath() + File.separator));
52 }
53
54 @Test
55 void testRejectsClassNameWithWindowsTraversal() {
56 final JavaClass jc = new ClassGen("..\\..\\pwn", "java.lang.Object", "pwn.java", Const.ACC_PUBLIC, null).getJavaClass();
57 assertThrows(IOException.class, () -> new Class2HTML(jc, outputDir().getAbsolutePath() + File.separator));
58 }
59 }