Skip to content

Commit 9dbb364

Browse files
committed
Python: Move json tests to be part of stdlib
This is better, since the modeling is also part of Stdlib.qll
1 parent 51a25e4 commit 9dbb364

File tree

2 files changed

+40
-53
lines changed
  • python/ql/test

2 files changed

+40
-53
lines changed

python/ql/test/experimental/dataflow/tainttracking/defaultAdditionalTaintStep/test_json.py

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from io import StringIO
2+
import json
3+
4+
def test():
5+
print("\n# test")
6+
ts = TAINTED_STRING
7+
8+
encoded = json.dumps(ts) # $ encodeOutput=json.dumps(..) encodeFormat=JSON encodeInput=ts
9+
10+
ensure_tainted(
11+
encoded, # $ tainted
12+
json.dumps(ts), # $ tainted encodeOutput=json.dumps(..) encodeFormat=JSON encodeInput=ts
13+
json.dumps(obj=ts), # $ tainted encodeOutput=json.dumps(..) encodeFormat=JSON encodeInput=ts
14+
json.loads(encoded), # $ tainted decodeOutput=json.loads(..) decodeFormat=JSON decodeInput=encoded
15+
json.loads(s=encoded), # $ tainted decodeOutput=json.loads(..) decodeFormat=JSON decodeInput=encoded
16+
)
17+
18+
# load/dump with file-like
19+
tainted_filelike = StringIO()
20+
json.dump(ts, tainted_filelike) # $ encodeFormat=JSON encodeInput=ts
21+
22+
tainted_filelike.seek(0)
23+
ensure_tainted(
24+
tainted_filelike, # $ tainted
25+
json.load(tainted_filelike), # $ tainted decodeOutput=json.load(..) decodeFormat=JSON decodeInput=tainted_filelike
26+
)
27+
28+
# load/dump with file-like using keyword-args
29+
tainted_filelike = StringIO()
30+
json.dump(obj=ts, fp=tainted_filelike) # $ encodeFormat=JSON encodeInput=ts
31+
32+
tainted_filelike.seek(0)
33+
ensure_tainted(
34+
tainted_filelike, # $ tainted
35+
json.load(fp=tainted_filelike), # $ tainted decodeOutput=json.load(..) decodeFormat=JSON decodeInput=tainted_filelike
36+
)
37+
38+
39+
# Make tests runable
40+
test()

0 commit comments

Comments
 (0)