Skip to content

Commit

Permalink
test(FileSystem) new create_symlink tests
Browse files Browse the repository at this point in the history
  • Loading branch information
e3krisztian committed Feb 15, 2024
1 parent 50c5e1a commit ca32156
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tests/test_file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
round_down,
round_up,
)
from unblob.report import PathTraversalProblem
from unblob.report import LinkExtractionProblem, PathTraversalProblem


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

def test_create_symlink_target_inside_sandbox(self, sandbox: FileSystem):
# ./sbin/shell -> ../bin/sh
sandbox.mkdir(Path("bin"))
sandbox.write_bytes(Path("bin/sh"), b"posix shell")
sandbox.mkdir(Path("sbin"))
sandbox.create_symlink(Path("../bin/sh"), Path("sbin/shell"))

output_path = sandbox.root / "sbin/shell"
assert output_path.read_bytes() == b"posix shell"
assert output_path.exists()
assert os.readlink(output_path) == "../bin/sh"
assert sandbox.problems == []

def test_create_symlink_target_outside_sandbox(self, sandbox: FileSystem):
# /shell -> ../bin/sh
sandbox.mkdir(Path("bin"))
sandbox.write_bytes(Path("bin/sh"), b"posix shell")
sandbox.create_symlink(Path("../bin/sh"), Path("/shell"))

assert any(p for p in sandbox.problems if isinstance(p, LinkExtractionProblem))
output_path = sandbox.root / "shell"
assert not output_path.exists()
assert not output_path.is_symlink()

def test_create_symlink_absolute_paths(self, sandbox: FileSystem):
sandbox.write_bytes(Path("target file"), b"test content")
sandbox.create_symlink(Path("/target file"), Path("/symlink"))
Expand Down

0 comments on commit ca32156

Please sign in to comment.