| 1 |
from beaker.util import encoded_path |
| 2 |
import os |
| 3 |
import pathlib |
| 4 |
|
| 5 |
def test_strips_leading_periods(tmp_path): |
| 6 |
""" |
| 7 |
Ensure that leading periods in the identifier are stripped when |
| 8 |
digest_filenames=False to prevent limited traversal |
| 9 |
""" |
| 10 |
|
| 11 |
out = encoded_path( |
| 12 |
root=tmp_path, |
| 13 |
identifiers=["..poc"], |
| 14 |
digest_filenames=False |
| 15 |
) |
| 16 |
|
| 17 |
p = pathlib.Path(out) |
| 18 |
|
| 19 |
|
| 20 |
assert not p.name.startswith("."), "Leading periods should be stripped" |
| 21 |
|
| 22 |
|
| 23 |
assert p.stem == "poc", "Filename should preserve content minus leading dots" |
| 24 |
|
| 25 |
|
| 26 |
assert p.suffix == ".enc" |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
relpath = os.path.relpath(p, tmp_path) |
| 31 |
assert not relpath.startswith('..'), f"Path {p} is not relative to {tmp_path}" |
| 32 |
|
| 33 |
|
| 34 |
assert str(p.parent) != str(tmp_path.absolute()) |
| 35 |
|