Skip to content

Commit b95225f

Browse files
committed
test(FileSystem) new create_symlink tests
1 parent 8838f29 commit b95225f

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

tests/test_file_utils.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
round_down,
2626
round_up,
2727
)
28-
from unblob.report import PathTraversalProblem
28+
from unblob.report import LinkExtractionProblem, PathTraversalProblem
2929

3030

3131
@pytest.mark.parametrize(
@@ -503,6 +503,30 @@ def test_create_symlink(self, sandbox: FileSystem):
503503
assert os.readlink(output_path) == "target file"
504504
assert sandbox.problems == []
505505

506+
def test_create_symlink_target_inside_sandbox(self, sandbox: FileSystem):
507+
# ./sbin/shell -> ../bin/sh
508+
sandbox.mkdir(Path("bin"))
509+
sandbox.write_bytes(Path("bin/sh"), b"posix shell")
510+
sandbox.mkdir(Path("sbin"))
511+
sandbox.create_symlink(Path("../bin/sh"), Path("sbin/shell"))
512+
513+
output_path = sandbox.root / "sbin/shell"
514+
assert output_path.read_bytes() == b"posix shell"
515+
assert output_path.exists()
516+
assert os.readlink(output_path) == "../bin/sh"
517+
assert sandbox.problems == []
518+
519+
def test_create_symlink_target_outside_sandbox(self, sandbox: FileSystem):
520+
# /shell -> ../bin/sh
521+
sandbox.mkdir(Path("bin"))
522+
sandbox.write_bytes(Path("bin/sh"), b"posix shell")
523+
sandbox.create_symlink(Path("../bin/sh"), Path("/shell"))
524+
525+
assert any(p for p in sandbox.problems if isinstance(p, LinkExtractionProblem))
526+
output_path = sandbox.root / "shell"
527+
assert not output_path.exists()
528+
assert not output_path.is_symlink()
529+
506530
def test_create_symlink_absolute_paths(self, sandbox: FileSystem):
507531
sandbox.write_bytes(Path("target file"), b"test content")
508532
sandbox.create_symlink(Path("/target file"), Path("/symlink"))

0 commit comments

Comments
 (0)