Skip to content

Commit 2dbf83b

Browse files
committed
Python: TaintTracking: Move tests of py3 string methods
1 parent cf121cc commit 2dbf83b

File tree

4 files changed

+73
-64
lines changed

4 files changed

+73
-64
lines changed
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
| test.py:28 | fail | binary_decode_encode | base64.a85encode(..) |
2-
| test.py:29 | fail | binary_decode_encode | base64.a85decode(..) |
3-
| test.py:32 | fail | binary_decode_encode | base64.b85encode(..) |
4-
| test.py:33 | fail | binary_decode_encode | base64.b85decode(..) |
5-
| test.py:36 | fail | binary_decode_encode | base64.encodebytes(..) |
6-
| test.py:37 | fail | binary_decode_encode | base64.decodebytes(..) |
7-
| test.py:45 | ok | f_strings | Fstring |
1+
| test.py:26 | ok | str_methods | ts.casefold() |
2+
| test.py:28 | ok | str_methods | ts.format_map(..) |
3+
| test.py:29 | fail | str_methods | "{unsafe}".format_map(..) |
4+
| test.py:40 | fail | binary_decode_encode | base64.a85encode(..) |
5+
| test.py:41 | fail | binary_decode_encode | base64.a85decode(..) |
6+
| test.py:44 | fail | binary_decode_encode | base64.b85encode(..) |
7+
| test.py:45 | fail | binary_decode_encode | base64.b85decode(..) |
8+
| test.py:48 | fail | binary_decode_encode | base64.encodebytes(..) |
9+
| test.py:49 | fail | binary_decode_encode | base64.decodebytes(..) |
10+
| test.py:57 | ok | f_strings | Fstring |

python/ql/test/experimental/dataflow/tainttracking/string-py3/test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ def ensure_not_tainted(*args):
1818

1919
# Actual tests
2020

21+
def str_methods():
22+
print("\n# str_methods")
23+
ts = TAINTED_STRING
24+
tb = TAINTED_BYTES
25+
ensure_tainted(
26+
ts.casefold(),
27+
28+
ts.format_map({}),
29+
"{unsafe}".format_map({"unsafe": ts}),
30+
)
31+
32+
2133
def binary_decode_encode():
2234
print("\n#percent_fmt")
2335
tb = TAINTED_BYTES
@@ -47,5 +59,6 @@ def f_strings():
4759

4860
# Make tests runable
4961

62+
str_methods()
5063
binary_decode_encode()
5164
f_strings()

python/ql/test/experimental/dataflow/tainttracking/string/TestTaint.expected

Lines changed: 50 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,53 @@
1010
| test.py:41 | ok | str_operations | bytes(..) |
1111
| test.py:42 | ok | str_operations | unicode(..) |
1212
| test.py:51 | ok | str_methods | ts.capitalize() |
13-
| test.py:52 | ok | str_methods | ts.casefold() |
14-
| test.py:53 | ok | str_methods | ts.center(..) |
15-
| test.py:54 | ok | str_methods | ts.expandtabs() |
16-
| test.py:56 | ok | str_methods | ts.format() |
17-
| test.py:57 | ok | str_methods | "{}".format(..) |
18-
| test.py:58 | ok | str_methods | "{unsafe}".format(..) |
19-
| test.py:60 | ok | str_methods | ts.format_map(..) |
20-
| test.py:61 | fail | str_methods | "{unsafe}".format_map(..) |
21-
| test.py:63 | ok | str_methods | ts.join(..) |
22-
| test.py:64 | fail | str_methods | "".join(..) |
23-
| test.py:66 | ok | str_methods | ts.ljust(..) |
24-
| test.py:67 | ok | str_methods | ts.lstrip() |
25-
| test.py:68 | ok | str_methods | ts.lower() |
26-
| test.py:70 | ok | str_methods | ts.replace(..) |
27-
| test.py:71 | ok | str_methods | "safe".replace(..) |
28-
| test.py:73 | ok | str_methods | ts.rjust(..) |
29-
| test.py:74 | ok | str_methods | ts.rstrip() |
30-
| test.py:75 | ok | str_methods | ts.strip() |
31-
| test.py:76 | ok | str_methods | ts.swapcase() |
32-
| test.py:77 | ok | str_methods | ts.title() |
33-
| test.py:78 | ok | str_methods | ts.upper() |
34-
| test.py:79 | ok | str_methods | ts.zfill(..) |
35-
| test.py:81 | ok | str_methods | ts.encode(..) |
36-
| test.py:82 | ok | str_methods | ts.encode(..).decode(..) |
37-
| test.py:84 | ok | str_methods | tb.decode(..) |
38-
| test.py:85 | ok | str_methods | tb.decode(..).encode(..) |
39-
| test.py:88 | ok | str_methods | ts.partition(..) |
40-
| test.py:89 | ok | str_methods | ts.rpartition(..) |
41-
| test.py:90 | ok | str_methods | ts.rsplit(..) |
42-
| test.py:91 | ok | str_methods | ts.split(..) |
43-
| test.py:92 | ok | str_methods | ts.splitlines() |
44-
| test.py:97 | ok | str_methods | "safe".replace(..) |
45-
| test.py:99 | fail | str_methods | ts.join(..) |
46-
| test.py:100 | fail | str_methods | ts.join(..) |
47-
| test.py:110 | fail | non_syntactic | meth() |
48-
| test.py:111 | fail | non_syntactic | _str(..) |
49-
| test.py:120 | ok | percent_fmt | BinaryExpr |
50-
| test.py:121 | ok | percent_fmt | BinaryExpr |
51-
| test.py:122 | fail | percent_fmt | BinaryExpr |
52-
| test.py:132 | fail | binary_decode_encode | base64.b64encode(..) |
53-
| test.py:133 | fail | binary_decode_encode | base64.b64decode(..) |
54-
| test.py:135 | fail | binary_decode_encode | base64.standard_b64encode(..) |
55-
| test.py:136 | fail | binary_decode_encode | base64.standard_b64decode(..) |
56-
| test.py:138 | fail | binary_decode_encode | base64.urlsafe_b64encode(..) |
57-
| test.py:139 | fail | binary_decode_encode | base64.urlsafe_b64decode(..) |
58-
| test.py:141 | fail | binary_decode_encode | base64.b32encode(..) |
59-
| test.py:142 | fail | binary_decode_encode | base64.b32decode(..) |
60-
| test.py:144 | fail | binary_decode_encode | base64.b16encode(..) |
61-
| test.py:145 | fail | binary_decode_encode | base64.b16decode(..) |
62-
| test.py:160 | fail | binary_decode_encode | base64.encodestring(..) |
63-
| test.py:161 | fail | binary_decode_encode | base64.decodestring(..) |
64-
| test.py:166 | fail | binary_decode_encode | quopri.encodestring(..) |
65-
| test.py:167 | fail | binary_decode_encode | quopri.decodestring(..) |
13+
| test.py:52 | ok | str_methods | ts.center(..) |
14+
| test.py:53 | ok | str_methods | ts.expandtabs() |
15+
| test.py:55 | ok | str_methods | ts.format() |
16+
| test.py:56 | ok | str_methods | "{}".format(..) |
17+
| test.py:57 | ok | str_methods | "{unsafe}".format(..) |
18+
| test.py:59 | ok | str_methods | ts.join(..) |
19+
| test.py:60 | fail | str_methods | "".join(..) |
20+
| test.py:62 | ok | str_methods | ts.ljust(..) |
21+
| test.py:63 | ok | str_methods | ts.lstrip() |
22+
| test.py:64 | ok | str_methods | ts.lower() |
23+
| test.py:66 | ok | str_methods | ts.replace(..) |
24+
| test.py:67 | ok | str_methods | "safe".replace(..) |
25+
| test.py:69 | ok | str_methods | ts.rjust(..) |
26+
| test.py:70 | ok | str_methods | ts.rstrip() |
27+
| test.py:71 | ok | str_methods | ts.strip() |
28+
| test.py:72 | ok | str_methods | ts.swapcase() |
29+
| test.py:73 | ok | str_methods | ts.title() |
30+
| test.py:74 | ok | str_methods | ts.upper() |
31+
| test.py:75 | ok | str_methods | ts.zfill(..) |
32+
| test.py:77 | ok | str_methods | ts.encode(..) |
33+
| test.py:78 | ok | str_methods | ts.encode(..).decode(..) |
34+
| test.py:80 | ok | str_methods | tb.decode(..) |
35+
| test.py:81 | ok | str_methods | tb.decode(..).encode(..) |
36+
| test.py:84 | ok | str_methods | ts.partition(..) |
37+
| test.py:85 | ok | str_methods | ts.rpartition(..) |
38+
| test.py:86 | ok | str_methods | ts.rsplit(..) |
39+
| test.py:87 | ok | str_methods | ts.split(..) |
40+
| test.py:88 | ok | str_methods | ts.splitlines() |
41+
| test.py:93 | ok | str_methods | "safe".replace(..) |
42+
| test.py:95 | fail | str_methods | ts.join(..) |
43+
| test.py:96 | fail | str_methods | ts.join(..) |
44+
| test.py:106 | fail | non_syntactic | meth() |
45+
| test.py:107 | fail | non_syntactic | _str(..) |
46+
| test.py:116 | ok | percent_fmt | BinaryExpr |
47+
| test.py:117 | ok | percent_fmt | BinaryExpr |
48+
| test.py:118 | fail | percent_fmt | BinaryExpr |
49+
| test.py:128 | fail | binary_decode_encode | base64.b64encode(..) |
50+
| test.py:129 | fail | binary_decode_encode | base64.b64decode(..) |
51+
| test.py:131 | fail | binary_decode_encode | base64.standard_b64encode(..) |
52+
| test.py:132 | fail | binary_decode_encode | base64.standard_b64decode(..) |
53+
| test.py:134 | fail | binary_decode_encode | base64.urlsafe_b64encode(..) |
54+
| test.py:135 | fail | binary_decode_encode | base64.urlsafe_b64decode(..) |
55+
| test.py:137 | fail | binary_decode_encode | base64.b32encode(..) |
56+
| test.py:138 | fail | binary_decode_encode | base64.b32decode(..) |
57+
| test.py:140 | fail | binary_decode_encode | base64.b16encode(..) |
58+
| test.py:141 | fail | binary_decode_encode | base64.b16decode(..) |
59+
| test.py:156 | fail | binary_decode_encode | base64.encodestring(..) |
60+
| test.py:157 | fail | binary_decode_encode | base64.decodestring(..) |
61+
| test.py:162 | fail | binary_decode_encode | quopri.encodestring(..) |
62+
| test.py:163 | fail | binary_decode_encode | quopri.decodestring(..) |

python/ql/test/experimental/dataflow/tainttracking/string/test.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,13 @@ def str_methods():
4949
tb = TAINTED_BYTES
5050
ensure_tainted(
5151
ts.capitalize(),
52-
ts.casefold(),
5352
ts.center(100),
5453
ts.expandtabs(),
5554

5655
ts.format(),
5756
"{}".format(ts),
5857
"{unsafe}".format(unsafe=ts),
5958

60-
ts.format_map({}),
61-
"{unsafe}".format_map({"unsafe": ts}),
62-
6359
ts.join(["", ""]),
6460
"".join([ts]),
6561

0 commit comments

Comments
 (0)