Skip to content

Commit 6601b36

Browse files
committed
Add unit test for deeply nested path file parsing
Using example for reproducing issue #172
1 parent 99d6b96 commit 6601b36

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/test_nsjail.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,29 @@ def test_file_parsing_timeout(self):
227227
)
228228
self.assertEqual(result.stderr, None)
229229

230+
def test_file_parsing_depth_limit(self):
231+
code = dedent(
232+
"""
233+
import os
234+
235+
x = ""
236+
for _ in range(1000):
237+
x += "a/"
238+
os.mkdir(x)
239+
240+
open(f"{x}test.txt", "w").write("test")
241+
"""
242+
).strip()
243+
244+
nsjail = NsJail(memfs_instance_size=32 * Size.MiB, files_timeout=5)
245+
result = nsjail.python3(["-c", code])
246+
self.assertEqual(result.returncode, None)
247+
self.assertEqual(
248+
result.stdout,
249+
"FileParsingError: Exceeded directory depth limit while parsing attachments",
250+
)
251+
self.assertEqual(result.stderr, None)
252+
230253
def test_file_write_error(self):
231254
"""Test errors during file write."""
232255
result = self.nsjail.python3(

0 commit comments

Comments
 (0)