77import static org .junit .jupiter .api .Assertions .*;
88
99public class PathTraversalDetectorTest {
10- private final PathTraversalDetector pathTraversalDetector = new PathTraversalDetector ();
1110 private void assertNotAttack (Detector .DetectorResult detectorResult ) {
1211 assertFalse (detectorResult .isDetectedAttack ());
1312 }
@@ -16,199 +15,199 @@ private void assertAttack(Detector.DetectorResult detectorResult) {
1615 }
1716 @ Test
1817 public void testEmptyUserInput () {
19- assertNotAttack (pathTraversalDetector .run ("" , new String []{"test.txt" }));
18+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("" , new String []{"test.txt" }));
2019 }
2120
2221 @ Test
2322 public void testEmptyFileInput () {
24- assertNotAttack (pathTraversalDetector .run ("test" , new String []{"" }));
23+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("test" , new String []{"" }));
2524 }
2625
2726 @ Test
2827 public void testEmptyUserInputAndFileInput () {
29- assertNotAttack (pathTraversalDetector .run ("" , new String []{"" }));
28+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("" , new String []{"" }));
3029 }
3130
3231 @ Test
3332 public void testUserInputIsASingleCharacter () {
34- assertNotAttack (pathTraversalDetector .run ("t" , new String []{"test.txt" }));
33+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("t" , new String []{"test.txt" }));
3534 }
3635
3736 @ Test
3837 public void testFileInputIsASingleCharacter () {
39- assertNotAttack (pathTraversalDetector .run ("test" , new String []{"t" }));
38+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("test" , new String []{"t" }));
4039 }
4140
4241 @ Test
4342 public void testSameAsUserInput () {
44- assertNotAttack (pathTraversalDetector .run ("text.txt" , new String []{"text.txt" }));
43+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("text.txt" , new String []{"text.txt" }));
4544 }
4645
4746 @ Test
4847 public void testWithDirectoryBefore () {
49- assertNotAttack (pathTraversalDetector .run ("text.txt" , new String []{"directory/text.txt" }));
48+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("text.txt" , new String []{"directory/text.txt" }));
5049 }
5150
5251 @ Test
5352 public void testWithBothDirectoryBefore () {
54- assertNotAttack (pathTraversalDetector .run ("directory/text.txt" , new String []{"directory/text.txt" }));
53+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("directory/text.txt" , new String []{"directory/text.txt" }));
5554 }
5655
5756 @ Test
5857 public void testUserInputAndFileInputAreSingleCharacters () {
59- assertNotAttack (pathTraversalDetector .run ("t" , new String []{"t" }));
58+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("t" , new String []{"t" }));
6059 }
6160
6261 @ Test
6362 public void testItFlagsDotDotSlash () {
64- assertAttack (pathTraversalDetector .run ("../" , new String []{"../test.txt" }));
63+ assertAttack (PathTraversalDetector . INSTANCE .run ("../" , new String []{"../test.txt" }));
6564 }
6665
6766 @ Test
6867 public void testItFlagsDotDotSlashSlash () {
69- assertAttack (pathTraversalDetector .run ("..//" , new String []{"..//test.txt" }));
68+ assertAttack (PathTraversalDetector . INSTANCE .run ("..//" , new String []{"..//test.txt" }));
7069 }
7170
7271 @ Test
7372 public void testItFlagsMoreComplexPaths () {
74- assertAttack (pathTraversalDetector .run ("..//secrets/key.txt" , new String []{"resources/blog/..//secrets/key.txt" }));
75- assertAttack (pathTraversalDetector .run (".././/secrets/key.txt" , new String []{"resources/blog/.././/secrets/key.txt" }));
76- assertAttack (pathTraversalDetector .run ("////../secrets/key.txt" , new String []{"resources/blog/////../secrets/key.txt" }));
73+ assertAttack (PathTraversalDetector . INSTANCE .run ("..//secrets/key.txt" , new String []{"resources/blog/..//secrets/key.txt" }));
74+ assertAttack (PathTraversalDetector . INSTANCE .run (".././/secrets/key.txt" , new String []{"resources/blog/.././/secrets/key.txt" }));
75+ assertAttack (PathTraversalDetector . INSTANCE .run ("////../secrets/key.txt" , new String []{"resources/blog/////../secrets/key.txt" }));
7776 }
7877
7978 @ Test
8079 public void testItFlagsBackslashDotDot () {
81- assertAttack (pathTraversalDetector .run ("..\\ " , new String []{"..\\ test.txt" ,}));
80+ assertAttack (PathTraversalDetector . INSTANCE .run ("..\\ " , new String []{"..\\ test.txt" ,}));
8281 }
8382
8483 @ Test
8584 public void testItFlagsDoubleDotSlash () {
86- assertAttack (pathTraversalDetector .run ("../../" , new String []{"../../test.txt" }));
85+ assertAttack (PathTraversalDetector . INSTANCE .run ("../../" , new String []{"../../test.txt" }));
8786 }
8887
8988 @ Test
9089 public void testItFlagsDoubleDotBackslash () {
91- assertAttack (pathTraversalDetector .run ("..\\ ..\\ " , new String []{"..\\ ..\\ test.txt" ,}));
90+ assertAttack (PathTraversalDetector . INSTANCE .run ("..\\ ..\\ " , new String []{"..\\ ..\\ test.txt" ,}));
9291 }
9392
9493 @ Test
9594 public void testItFlagsFourDotSlash () {
96- assertAttack (pathTraversalDetector .run ("../../../../" , new String []{"../../../../test.txt" }));
95+ assertAttack (PathTraversalDetector . INSTANCE .run ("../../../../" , new String []{"../../../../test.txt" }));
9796 }
9897
9998 @ Test
10099 public void testItFlagsThreeDotBackslash () {
101- assertAttack (pathTraversalDetector .run ("..\\ ..\\ ..\\ " , new String []{"..\\ ..\\ ..\\ test.txt" ,}));
100+ assertAttack (PathTraversalDetector . INSTANCE .run ("..\\ ..\\ ..\\ " , new String []{"..\\ ..\\ ..\\ test.txt" ,}));
102101 }
103102
104103 @ Test
105104 public void testUserInputIsLongerThanFilePath () {
106- assertNotAttack (pathTraversalDetector .run ("../../file.txt" , new String []{"../file.txt" }));
105+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("../../file.txt" , new String []{"../file.txt" }));
107106 }
108107
109108 @ Test
110109 public void testAbsoluteLinuxPath () {
111- assertAttack (pathTraversalDetector .run ("/etc/passwd" , new String []{"/etc/passwd" }));
110+ assertAttack (PathTraversalDetector . INSTANCE .run ("/etc/passwd" , new String []{"/etc/passwd" }));
112111 }
113112
114113 @ Test
115114 public void testLinuxUserDirectory () {
116- assertAttack (pathTraversalDetector .run ("/home/user/" , new String []{"/home/user/file.txt" }));
115+ assertAttack (PathTraversalDetector . INSTANCE .run ("/home/user/" , new String []{"/home/user/file.txt" }));
117116 }
118117
119118 @ Test
120119 public void testWindowsDriveLetter () {
121- assertAttack (pathTraversalDetector .run ("C:\\ " , new String []{"C:\\ file.txt" }));
120+ assertAttack (PathTraversalDetector . INSTANCE .run ("C:\\ " , new String []{"C:\\ file.txt" }));
122121 }
123122
124123 @ Test
125124 public void testNoPathTraversal () {
126- assertNotAttack (pathTraversalDetector .run ("/storage/file.txt" , new String []{"/appdata/storage/file.txt" }));
125+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("/storage/file.txt" , new String []{"/appdata/storage/file.txt" }));
127126 }
128127
129128 @ Test
130129 public void testDoesNotFlagTest () {
131- assertNotAttack (pathTraversalDetector .run ("test" , new String []{"/app/test.txt" }));
130+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("test" , new String []{"/app/test.txt" }));
132131 }
133132
134133 @ Test
135134 public void testDoesNotFlagExampleTestTxt () {
136- assertNotAttack (pathTraversalDetector .run ("example/test.txt" , new String []{"/app/data/example/test.txt" }));
135+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("example/test.txt" , new String []{"/app/data/example/test.txt" }));
137136 }
138137
139138 @ Test
140139 public void testDoesNotAbsolutePathWithDifferentFolder () {
141- assertNotAttack (pathTraversalDetector .run ("/etc/hack/config" , new String []{"/etc/app/config" }));
140+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("/etc/hack/config" , new String []{"/etc/app/config" }));
142141 }
143142
144143 @ Test
145144 public void testDoesNotAbsolutePathInsideAnotherFolder () {
146- assertNotAttack (pathTraversalDetector .run ("/etc/config" , new String []{"/etc/app/data/etc/config" }));
145+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("/etc/config" , new String []{"/etc/app/data/etc/config" }));
147146 }
148147
149148 @ Test
150149 public void testUserInputContainsMultipleUnsafePathParts () {
151- assertNotAttack (pathTraversalDetector .run ("../../../" , new String []{"directory/../../file.txt" }));
150+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("../../../" , new String []{"directory/../../file.txt" }));
152151 }
153152
154153 @ Test
155154 public void testUserInputWithMixedPathSeparators () {
156- assertNotAttack (pathTraversalDetector .run ("..\\ ..\\ " , new String []{"directory/../file.txt" }));
155+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("..\\ ..\\ " , new String []{"directory/../file.txt" }));
157156 }
158157
159158 @ Test
160159 public void testUserInputWithEncodedCharacters () {
161- assertAttack (pathTraversalDetector .run ("%2E%2E/../" , new String []{"directory/%2E%2E/../file.txt" }));
160+ assertAttack (PathTraversalDetector . INSTANCE .run ("%2E%2E/../" , new String []{"directory/%2E%2E/../file.txt" }));
162161 }
163162
164163 @ Test
165164 public void testUserInputWithEncodedBackslash () {
166- assertNotAttack (pathTraversalDetector .run ("%5C%5C" , new String []{"directory/%5C%5Cfile.txt" }));
165+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("%5C%5C" , new String []{"directory/%5C%5Cfile.txt" }));
167166 }
168167
169168 @ Test
170169 public void testUserInputWithSpaces () {
171- assertNotAttack (pathTraversalDetector .run ("test file" , new String []{"directory/test file.txt" }));
170+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("test file" , new String []{"directory/test file.txt" }));
172171 }
173172
174173 @ Test
175174 public void testUserInputWithLeadingSpaces () {
176- assertNotAttack (pathTraversalDetector .run (" test.txt" , new String []{"directory/test.txt" }));
175+ assertNotAttack (PathTraversalDetector . INSTANCE .run (" test.txt" , new String []{"directory/test.txt" }));
177176 }
178177
179178 @ Test
180179 public void testUserInputWithTrailingSpaces () {
181- assertNotAttack (pathTraversalDetector .run ("test.txt " , new String []{"directory/test.txt" }));
180+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("test.txt " , new String []{"directory/test.txt" }));
182181 }
183182
184183 @ Test
185184 public void testUserInputWithSpecialCharacters () {
186- assertNotAttack (
pathTraversalDetector .
run (
"[email protected] " ,
new String []{
"directory/[email protected] " }));
185+ assertNotAttack (
PathTraversalDetector . INSTANCE .
run (
"[email protected] " ,
new String []{
"directory/[email protected] " }));
187186 }
188187
189188 @ Test
190189 public void testUserInputWithAbsolutePath () {
191- assertAttack (pathTraversalDetector .run ("/etc/passwd" , new String []{"/etc/passwd" }));
190+ assertAttack (PathTraversalDetector . INSTANCE .run ("/etc/passwd" , new String []{"/etc/passwd" }));
192191 }
193192
194193 @ Test
195194 public void testUserInputWithMixedCase () {
196- assertNotAttack (pathTraversalDetector .run ("Test.txt" , new String []{"directory/test.txt" }));
195+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("Test.txt" , new String []{"directory/test.txt" }));
197196 }
198197
199198 @ Test
200199 public void testUserInputWithLongPath () {
201200 String longUserInput = "a" .repeat (260 ); // Assuming a long input
202- assertNotAttack (pathTraversalDetector .run (longUserInput , new String []{"directory/test.txt" }));
201+ assertNotAttack (PathTraversalDetector . INSTANCE .run (longUserInput , new String []{"directory/test.txt" }));
203202 }
204203
205204 @ Test
206205 public void testUserInputWithEmptyFilePath () {
207- assertNotAttack (pathTraversalDetector .run ("test" , new String []{"" }));
206+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("test" , new String []{"" }));
208207 }
209208
210209 @ Test
211210 public void testUserInputWithFilePathContainingSpaces () {
212- assertNotAttack (pathTraversalDetector .run ("test file" , new String []{"directory/test file.txt" }));
211+ assertNotAttack (PathTraversalDetector . INSTANCE .run ("test file" , new String []{"directory/test file.txt" }));
213212 }
214213}
0 commit comments