Skip to content

Commit bea0acb

Browse files
committed
Python: Add barrier test to import resolution
Just like the one added for `py/insecure-protocol` in fb425b7, but instead added in the import-resolution tests, such that we don't have to remember it's in a completely different directory.
1 parent 321a4b4 commit bea0acb

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

python/ql/test/experimental/import-resolution/ModuleExport.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
| baz | __file__ | baz.py:2:7:2:14 | ControlFlowNode for __file__ |
1212
| baz | __file__ | baz.py:6:6:6:13 | ControlFlowNode for __file__ |
1313
| baz | baz_attr | baz.py:4:12:4:21 | ControlFlowNode for Str |
14+
| block_flow_check | SOURCE | block_flow_check.py:4:1:4:21 | ControlFlowNode for ClassExpr |
15+
| block_flow_check | __file__ | block_flow_check.py:2:7:2:14 | ControlFlowNode for __file__ |
16+
| block_flow_check | __file__ | block_flow_check.py:14:6:14:13 | ControlFlowNode for __file__ |
1417
| foo | __file__ | foo.py:2:7:2:14 | ControlFlowNode for __file__ |
1518
| foo | __file__ | foo.py:14:6:14:13 | ControlFlowNode for __file__ |
1619
| foo | __private_foo_attr | foo.py:8:22:8:41 | ControlFlowNode for Str |
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from trace import *
2+
enter(__file__)
3+
4+
class SOURCE(object):
5+
@staticmethod
6+
def block_flow(): pass
7+
8+
check("SOURCE", SOURCE, SOURCE, globals()) #$ prints=SOURCE
9+
10+
SOURCE.block_flow()
11+
12+
check("SOURCE", SOURCE, SOURCE, globals())
13+
14+
exit(__file__)

python/ql/test/experimental/import-resolution/importflow.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ private class ImportConfiguration extends DataFlow::Configuration {
6666
override predicate isSink(DataFlow::Node sink) {
6767
sink = API::moduleImport("trace").getMember("check").getACall().getArg(1)
6868
}
69+
70+
override predicate isBarrier(DataFlow::Node node) {
71+
exists(DataFlow::MethodCallNode call | call.calls(node, "block_flow"))
72+
}
6973
}
7074

7175
class ResolutionTest extends InlineExpectationsTest {

python/ql/test/experimental/import-resolution/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ def local_import():
146146
check("simplistic_reexport.bar_attr", simplistic_reexport.bar_attr, "overwritten", globals()) #$ prints=overwritten SPURIOUS: prints=bar_attr
147147
check("simplistic_reexport.baz_attr", simplistic_reexport.baz_attr, "overwritten", globals()) #$ prints=overwritten SPURIOUS: prints=baz_attr
148148

149+
# check that we don't treat all assignments as being exports
150+
import block_flow_check #$ imports=block_flow_check as=block_flow_check
151+
check("block_flow_check.SOURCE", block_flow_check.SOURCE, block_flow_check.SOURCE, globals()) #$ SPURIOUS: prints=SOURCE
152+
149153
exit(__file__)
150154

151155
print()

0 commit comments

Comments
 (0)