Skip to content

Commit 39f134c

Browse files
committed
Python: reorganized and added to tests
1 parent 71830ab commit 39f134c

File tree

4 files changed

+94
-66
lines changed

4 files changed

+94
-66
lines changed

python/ql/test/experimental/dataflow/validTest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ def check_tests_valid(testFile):
5353
check_tests_valid("coverage.classes")
5454
check_tests_valid("coverage.test")
5555
check_tests_valid("coverage.argumentPassing")
56+
check_tests_valid("variable-capture.in")
5657
check_tests_valid("variable-capture.nonlocal")
5758
check_tests_valid("variable-capture.dict")

python/ql/test/experimental/dataflow/variable-capture/dict.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,6 @@ def SINK_F(x):
2929
print("OK")
3030

3131

32-
def In(tainted):
33-
def captureIn1():
34-
sinkI1 = tainted
35-
SINK(sinkI1) #$ MISSING:captured
36-
captureIn1()
37-
38-
def captureIn2():
39-
def m():
40-
sinkI2 = tainted
41-
SINK(sinkI2) #$ MISSING:captured
42-
m()
43-
captureIn2()
44-
45-
# captureIn3 = lambda arg:(
46-
# sinkI3 = tainted;
47-
# check(sinkI3);
48-
# return arg)
49-
# [ captureIn3(x) for x in " " ]
50-
51-
def captureIn1NotCalled():
52-
nonSink0 = tainted
53-
SINK_F(nonSink0)
54-
55-
def captureIn2NotCalled():
56-
def m():
57-
nonSink0 = tainted
58-
SINK_F(nonSink0)
59-
captureIn2NotCalled()
60-
61-
@expects(2)
62-
def test_In():
63-
In(SOURCE)
64-
6532
def Out():
6633
sinkO1 = { "x": "" }
6734
def captureOut1():
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# All functions starting with "test_" should run and execute `print("OK")` exactly once.
2+
# This can be checked by running validTest.py.
3+
4+
import sys
5+
import os
6+
7+
sys.path.append(os.path.dirname(os.path.dirname((__file__))))
8+
from testlib import *
9+
10+
# These are defined so that we can evaluate the test code.
11+
NONSOURCE = "not a source"
12+
SOURCE = "source"
13+
14+
def is_source(x):
15+
return x == "source" or x == b"source" or x == 42 or x == 42.0 or x == 42j
16+
17+
18+
def SINK(x):
19+
if is_source(x):
20+
print("OK")
21+
else:
22+
print("Unexpected flow", x)
23+
24+
25+
def SINK_F(x):
26+
if is_source(x):
27+
print("Unexpected flow", x)
28+
else:
29+
print("OK")
30+
31+
32+
def inParam(tainted):
33+
def captureIn1():
34+
sinkI1 = tainted
35+
SINK(sinkI1) #$ MISSING:captured
36+
captureIn1()
37+
38+
def captureIn2():
39+
def m():
40+
sinkI2 = tainted
41+
SINK(sinkI2) #$ MISSING:captured
42+
m()
43+
captureIn2()
44+
45+
captureIn3 = lambda arg: SINK(tainted)
46+
captureIn3("")
47+
48+
def captureIn1NotCalled():
49+
nonSink0 = tainted
50+
SINK_F(nonSink0)
51+
52+
def captureIn2NotCalled():
53+
def m():
54+
nonSink0 = tainted
55+
SINK_F(nonSink0)
56+
captureIn2NotCalled()
57+
58+
@expects(3)
59+
def test_inParam():
60+
inParam(SOURCE)
61+
62+
def inLocal():
63+
tainted = SOURCE
64+
65+
def captureIn1():
66+
sinkI1 = tainted
67+
SINK(sinkI1) #$ MISSING:captured
68+
captureIn1()
69+
70+
def captureIn2():
71+
def m():
72+
sinkI2 = tainted
73+
SINK(sinkI2) #$ MISSING:captured
74+
m()
75+
captureIn2()
76+
77+
captureIn3 = lambda arg: SINK(tainted)
78+
captureIn3("")
79+
80+
def captureIn1NotCalled():
81+
nonSink0 = tainted
82+
SINK_F(nonSink0)
83+
84+
def captureIn2NotCalled():
85+
def m():
86+
nonSink0 = tainted
87+
SINK_F(nonSink0)
88+
captureIn2NotCalled()
89+
90+
@expects(3)
91+
def test_inLocal():
92+
inLocal()
93+

python/ql/test/experimental/dataflow/variable-capture/nonlocal.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,6 @@ def SINK_F(x):
2929
print("OK")
3030

3131

32-
def In(tainted):
33-
def captureIn1():
34-
sinkI1 = tainted
35-
SINK(sinkI1) #$ MISSING:captured
36-
captureIn1()
37-
38-
def captureIn2():
39-
def m():
40-
sinkI2 = tainted
41-
SINK(sinkI2) #$ MISSING:captured
42-
m()
43-
captureIn2()
44-
45-
# captureIn3 = lambda arg:(
46-
# sinkI3 = tainted;
47-
# check(sinkI3);
48-
# return arg)
49-
# [ captureIn3(x) for x in " " ]
50-
51-
def captureIn1NotCalled():
52-
nonSink0 = tainted
53-
SINK_F(nonSink0)
54-
55-
def captureIn2NotCalled():
56-
def m():
57-
nonSink0 = tainted
58-
SINK_F(nonSink0)
59-
captureIn2NotCalled()
60-
61-
@expects(2)
62-
def test_In():
63-
In(SOURCE)
64-
6532
def Out():
6633
sinkO1 = ""
6734
def captureOut1():

0 commit comments

Comments
 (0)