forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pathlib.py
More file actions
60 lines (43 loc) · 1.5 KB
/
test_pathlib.py
File metadata and controls
60 lines (43 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Add taintlib to PATH so it can be imported during runtime without any hassle
import sys; import os; sys.path.append(os.path.dirname(os.path.dirname((__file__))))
from taintlib import *
# This has no runtime impact, but allows autocomplete to work
from typing import Iterable, TYPE_CHECKING
if TYPE_CHECKING:
from ..taintlib import *
# Actual tests
import pathlib
# pathlib was added in 3.4
def test_basic():
print("\n# test_basic")
ts = TAINTED_STRING
tainted_path = pathlib.Path(ts)
tainted_pure_path = pathlib.PurePath(ts)
tainted_pure_posix_path = pathlib.PurePosixPath(ts)
tainted_pure_windows_path = pathlib.PureWindowsPath(ts)
ensure_tainted(
tainted_path,
tainted_pure_path,
tainted_pure_posix_path,
tainted_pure_windows_path,
pathlib.Path("foo") / ts,
ts / pathlib.Path("foo"),
tainted_path.joinpath("foo", "bar"),
pathlib.Path("foo").joinpath(tainted_path, "bar"),
pathlib.Path("foo").joinpath("bar", tainted_path),
str(tainted_path),
# TODO: Tainted methods and attributes
# https://docs.python.org/3.8/library/pathlib.html#methods-and-properties
)
if os.name == "posix":
tainted_posix_path = pathlib.PosixPath(ts)
ensure_tainted(
tainted_posix_path,
)
if os.name == "nt":
tainted_windows_path = pathlib.WindowsPath(ts)
ensure_tainted(
tainted_windows_path,
)
# Make tests runable
test_basic()