Skip to content

Commit ee76d9b

Browse files
committed
Python: Clean up tests
1 parent e179df7 commit ee76d9b

File tree

4 files changed

+11
-44
lines changed

4 files changed

+11
-44
lines changed

python/ql/test/experimental/dataflow/global-flow/test.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
# Modification by reassignment
1919

2020
g_mod = []
21-
# The following assignment should not be a `ModuleVariableNode`, but currently our analysis thinks `g_mod` might be used in the `print` call
21+
# This assignment does not produce any flow, since `g_mod` is immediately reassigned.
22+
23+
# The following assignment should not be a `ModuleVariableNode`,
24+
# but currently our analysis thinks `g_mod` might be used in the `print` call
2225
g_mod = [10] # $f+:writes=g_mod
2326
print("foo")
2427
g_mod = [100] # $writes=g_mod
@@ -27,7 +30,7 @@
2730

2831
g_ins = [50] # $writes=g_ins
2932
print(g_ins)
30-
g_ins.insert(75)
33+
g_ins.append(75)
3134

3235
# A global with multiple potential definitions
3336

@@ -37,11 +40,11 @@
3740
else:
3841
g_mult = [300] # $writes=g_mult
3942

40-
# A global with multiple potential definitions
43+
# A global variable that may be redefined depending on some unknown value
4144

42-
g_mult2 = [400] # $writes=g_mult2
45+
g_redef = [400] # $writes=g_redef
4346
if unknown_module.attr:
44-
g_mult2 = [500] # $writes=g_mult2
47+
g_redef = [500] # $writes=g_redef
4548

4649
def global_access():
4750
l = 5
@@ -51,7 +54,7 @@ def global_access():
5154
print(g_mod) # $reads=g_mod
5255
print(g_ins) # $reads=g_ins
5356
print(g_mult) # $reads=g_mult
54-
print(g_mult2) # $reads=g_mult2
57+
print(g_redef) # $reads=g_redef
5558

5659
def print_g_mod(): # $writes=print_g_mod
5760
print(g_mod) # $reads=g_mod

python/ql/test/experimental/dataflow/tainttracking/TestTaintLib.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private string repr(Expr e) {
4343
result = repr(e.(Attribute).getObject()) + "." + e.(Attribute).getName()
4444
}
4545

46-
query predicate test_taint(string arg_location, string test_res, string function_name, string repr) {
46+
query predicate test_taint(string arg_location, string test_res, string scope_name, string repr) {
4747
exists(Call call, Expr arg, boolean expected_taint, boolean has_taint |
4848
// only consider files that are extracted as part of the test
4949
exists(call.getLocation().getFile().getRelativePath()) and
@@ -68,7 +68,7 @@ query predicate test_taint(string arg_location, string test_res, string function
6868
// select
6969
arg_location = arg.getLocation().toString() and
7070
test_res = test_res and
71-
function_name = call.getScope().(Function).getName() and
71+
scope_name = call.getScope().getName() and
7272
repr = repr(arg)
7373
)
7474
}
Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,7 @@
1-
| test.py:0:0:0:0 | GSSA Variable tainted3 | test.py:4:1:4:13 | GSSA Variable tainted3 |
21
| test.py:3:1:3:7 | GSSA Variable tainted | test.py:4:1:4:13 | GSSA Variable tainted |
32
| test.py:3:1:3:7 | GSSA Variable tainted | test.py:4:6:4:12 | ControlFlowNode for tainted |
43
| test.py:3:11:3:16 | ControlFlowNode for SOURCE | test.py:3:1:3:7 | GSSA Variable tainted |
5-
| test.py:3:11:3:16 | ControlFlowNode for SOURCE | test.py:20:12:20:17 | ControlFlowNode for SOURCE |
6-
| test.py:4:1:4:4 | ControlFlowNode for SINK | test.py:14:1:14:4 | ControlFlowNode for SINK |
74
| test.py:6:1:6:11 | ControlFlowNode for FunctionExpr | test.py:6:5:6:8 | GSSA Variable func |
8-
| test.py:6:1:6:11 | GSSA Variable tainted2 | test.py:8:5:8:22 | GSSA Variable tainted2 |
9-
| test.py:6:1:6:11 | GSSA Variable tainted3 | test.py:8:5:8:22 | GSSA Variable tainted3 |
105
| test.py:7:5:7:16 | SSA variable also_tainted | test.py:8:5:8:22 | SSA variable also_tainted |
116
| test.py:7:5:7:16 | SSA variable also_tainted | test.py:8:10:8:21 | ControlFlowNode for also_tainted |
127
| test.py:7:20:7:25 | ControlFlowNode for SOURCE | test.py:7:5:7:16 | SSA variable also_tainted |
13-
| test.py:13:1:13:8 | GSSA Variable tainted2 | test.py:14:1:14:14 | GSSA Variable tainted2 |
14-
| test.py:13:1:13:8 | GSSA Variable tainted2 | test.py:14:6:14:13 | ControlFlowNode for tainted2 |
15-
| test.py:13:12:13:21 | ControlFlowNode for NON_SOURCE | test.py:13:1:13:8 | GSSA Variable tainted2 |
16-
| test.py:13:12:13:21 | ControlFlowNode for NON_SOURCE | test.py:21:12:21:21 | ControlFlowNode for NON_SOURCE |
17-
| test.py:14:1:14:4 | ControlFlowNode for SINK | test.py:22:1:22:4 | ControlFlowNode for SINK |
18-
| test.py:14:1:14:14 | GSSA Variable tainted2 | test.py:22:1:22:14 | GSSA Variable tainted2 |
19-
| test.py:16:1:16:19 | ControlFlowNode for FunctionExpr | test.py:16:5:16:16 | GSSA Variable write_global |
20-
| test.py:18:16:18:21 | ControlFlowNode for SOURCE | test.py:18:5:18:12 | GSSA Variable tainted2 |
21-
| test.py:21:1:21:8 | GSSA Variable tainted3 | test.py:22:1:22:14 | GSSA Variable tainted3 |
22-
| test.py:21:1:21:8 | GSSA Variable tainted3 | test.py:22:6:22:13 | ControlFlowNode for tainted3 |
23-
| test.py:21:12:21:21 | ControlFlowNode for NON_SOURCE | test.py:21:1:21:8 | GSSA Variable tainted3 |
24-
| test.py:24:1:24:22 | ControlFlowNode for FunctionExpr | test.py:24:5:24:19 | GSSA Variable use_of_tainted3 |
25-
| test.py:26:16:26:25 | ControlFlowNode for NON_SOURCE | test.py:26:5:26:12 | GSSA Variable tainted3 |

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,3 @@
66
def func():
77
also_tainted = SOURCE
88
SINK(also_tainted)
9-
10-
11-
# Various instances where flow is undesirable
12-
13-
tainted2 = NON_SOURCE
14-
SINK(tainted2)
15-
16-
def write_global():
17-
global tainted2
18-
tainted2 = SOURCE
19-
20-
tainted3 = SOURCE
21-
tainted3 = NON_SOURCE
22-
SINK(tainted3)
23-
24-
def use_of_tainted3():
25-
global tainted3
26-
tainted3 = NON_SOURCE

0 commit comments

Comments
 (0)