mirror of
https://github.com/github/codeql.git
synced 2025-12-18 01:33:15 +01:00
python: dataflow tests names in exception handlers
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
missingAnnotationOnSink
|
||||
failures
|
||||
@@ -0,0 +1,2 @@
|
||||
import python
|
||||
import experimental.dataflow.TestUtil.NormalDataflowTest
|
||||
@@ -0,0 +1,19 @@
|
||||
uniqueEnclosingCallable
|
||||
uniqueType
|
||||
uniqueNodeLocation
|
||||
missingLocation
|
||||
uniqueNodeToString
|
||||
missingToString
|
||||
parameterCallable
|
||||
localFlowIsLocal
|
||||
compatibleTypesReflexive
|
||||
unreachableNodeCCtx
|
||||
localCallNodes
|
||||
postIsNotPre
|
||||
postHasUniquePre
|
||||
uniquePostUpdate
|
||||
postIsInSameCallable
|
||||
reverseRead
|
||||
argHasPostUpdate
|
||||
postWithInFlow
|
||||
viableImplInCallContextTooLarge
|
||||
@@ -0,0 +1 @@
|
||||
import semmle.python.dataflow.new.internal.DataFlowImplConsistency::Consistency
|
||||
46
python/ql/test/experimental/dataflow/exceptions/test.py
Normal file
46
python/ql/test/experimental/dataflow/exceptions/test.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# This should cover all the syntactical constructs that we hope to support.
|
||||
# Headings refer to https://docs.python.org/3/reference/expressions.html,
|
||||
# and are selected whenever they incur dataflow.
|
||||
# Intended sources should be the variable `SOURCE` and intended sinks should be
|
||||
# arguments to the function `SINK` (see python/ql/test/experimental/dataflow/testConfig.qll).
|
||||
#
|
||||
# Functions whose name ends with "_with_local_flow" will also be tested for local flow.
|
||||
#
|
||||
# All functions starting with "test_" should run and execute `print("OK")` exactly once.
|
||||
# This can be checked by running validTest.py.
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.dirname((__file__))))
|
||||
from testlib import expects
|
||||
|
||||
# These are defined so that we can evaluate the test code.
|
||||
NONSOURCE = "not a source"
|
||||
SOURCE = "source"
|
||||
|
||||
|
||||
def is_source(x):
|
||||
return x == "source" or x == b"source" or x == 42 or x == 42.0 or x == 42j
|
||||
|
||||
|
||||
def SINK(x):
|
||||
if is_source(x):
|
||||
print("OK")
|
||||
else:
|
||||
print("Unexpected flow", x)
|
||||
|
||||
|
||||
def SINK_F(x):
|
||||
if is_source(x):
|
||||
print("Unexpected flow", x)
|
||||
else:
|
||||
print("OK")
|
||||
|
||||
def test_as_binding():
|
||||
try:
|
||||
e_with_source = Exception()
|
||||
e_with_source.a = SOURCE
|
||||
raise e_with_source
|
||||
except Exception as e:
|
||||
SINK(e.a) # $ MISSING: flow
|
||||
@@ -0,0 +1,46 @@
|
||||
# This should cover all the syntactical constructs that we hope to support.
|
||||
# Headings refer to https://docs.python.org/3/reference/expressions.html,
|
||||
# and are selected whenever they incur dataflow.
|
||||
# Intended sources should be the variable `SOURCE` and intended sinks should be
|
||||
# arguments to the function `SINK` (see python/ql/test/experimental/dataflow/testConfig.qll).
|
||||
#
|
||||
# Functions whose name ends with "_with_local_flow" will also be tested for local flow.
|
||||
#
|
||||
# All functions starting with "test_" should run and execute `print("OK")` exactly once.
|
||||
# This can be checked by running validTest.py.
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.dirname((__file__))))
|
||||
from testlib import expects
|
||||
|
||||
# These are defined so that we can evaluate the test code.
|
||||
NONSOURCE = "not a source"
|
||||
SOURCE = "source"
|
||||
|
||||
|
||||
def is_source(x):
|
||||
return x == "source" or x == b"source" or x == 42 or x == 42.0 or x == 42j
|
||||
|
||||
|
||||
def SINK(x):
|
||||
if is_source(x):
|
||||
print("OK")
|
||||
else:
|
||||
print("Unexpected flow", x)
|
||||
|
||||
|
||||
def SINK_F(x):
|
||||
if is_source(x):
|
||||
print("Unexpected flow", x)
|
||||
else:
|
||||
print("OK")
|
||||
|
||||
def test_as_binding():
|
||||
try:
|
||||
e_with_source = Exception()
|
||||
e_with_source.a = SOURCE
|
||||
raise e_with_source
|
||||
except* Exception as e:
|
||||
SINK(e.a) # $ MISSING: flow
|
||||
@@ -51,6 +51,14 @@ def check_tests_valid(testFile):
|
||||
check_async_test_function(item)
|
||||
|
||||
|
||||
def check_tests_valid_after_version(testFile, version):
|
||||
|
||||
if sys.version_info[:2] >= version:
|
||||
print("INFO: Will run tests in", testFile, "since we're running Python", version, "or newer")
|
||||
check_tests_valid(testFile)
|
||||
else:
|
||||
print("WARN: Will not run tests in", testFile, "since we're running Python", sys.version_info[:2], "and need", version, "or newer")
|
||||
|
||||
if __name__ == "__main__":
|
||||
check_tests_valid("coverage.classes")
|
||||
check_tests_valid("coverage.test")
|
||||
@@ -60,12 +68,9 @@ if __name__ == "__main__":
|
||||
check_tests_valid("variable-capture.dict")
|
||||
check_tests_valid("module-initialization.multiphase")
|
||||
check_tests_valid("fieldflow.test")
|
||||
|
||||
if sys.version_info[:2] >= (3, 10):
|
||||
print("INFO: Will run `match` tests since we're running Python 3.10 or newer")
|
||||
check_tests_valid("match.test")
|
||||
else:
|
||||
print("WARN: Skipping `match` tests since we're not running 3.10 or newer")
|
||||
check_tests_valid_after_version("match.test", (3, 10))
|
||||
check_tests_valid("exceptions.test")
|
||||
check_tests_valid_after_version("exceptions.test_group", (3, 11))
|
||||
|
||||
# The below fails when trying to import modules
|
||||
# check_tests_valid("module-initialization.test")
|
||||
|
||||
Reference in New Issue
Block a user