mirror of
https://github.com/github/codeql.git
synced 2025-12-22 03:36:30 +01:00
Merge pull request #13346 from jketema/inline-2
Update inline expectation tests to use parameterized module
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
failures
|
||||
testFailures
|
||||
|
||||
@@ -4,16 +4,14 @@ import semmle.python.dataflow.new.internal.DataFlowDispatch as DataFlowDispatch
|
||||
import TestUtilities.InlineExpectationsTest
|
||||
private import semmle.python.dataflow.new.internal.PrintNode
|
||||
|
||||
class DataFlowCallTest extends InlineExpectationsTest {
|
||||
DataFlowCallTest() { this = "DataFlowCallTest" }
|
||||
|
||||
override string getARelevantTag() {
|
||||
module DataFlowCallTest implements TestSig {
|
||||
string getARelevantTag() {
|
||||
result in ["call", "callType"]
|
||||
or
|
||||
result = "arg[" + any(DataFlowDispatch::ArgumentPosition pos).toString() + "]"
|
||||
}
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(location.getFile().getRelativePath()) and
|
||||
exists(DataFlowDispatch::DataFlowCall call |
|
||||
location = call.getLocation() and
|
||||
@@ -35,3 +33,5 @@ class DataFlowCallTest extends InlineExpectationsTest {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<DataFlowCallTest>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
failures
|
||||
testFailures
|
||||
|
||||
@@ -2,12 +2,10 @@ import python
|
||||
import semmle.python.dataflow.new.DataFlow
|
||||
import TestUtilities.InlineExpectationsTest
|
||||
|
||||
class GlobalReadTest extends InlineExpectationsTest {
|
||||
GlobalReadTest() { this = "GlobalReadTest" }
|
||||
module GlobalReadTest implements TestSig {
|
||||
string getARelevantTag() { result = "reads" }
|
||||
|
||||
override string getARelevantTag() { result = "reads" }
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(DataFlow::ModuleVariableNode n, DataFlow::Node read |
|
||||
read = n.getARead() and
|
||||
value = n.getVariable().getId() and
|
||||
@@ -19,12 +17,10 @@ class GlobalReadTest extends InlineExpectationsTest {
|
||||
}
|
||||
}
|
||||
|
||||
class GlobalWriteTest extends InlineExpectationsTest {
|
||||
GlobalWriteTest() { this = "GlobalWriteTest" }
|
||||
module GlobalWriteTest implements TestSig {
|
||||
string getARelevantTag() { result = "writes" }
|
||||
|
||||
override string getARelevantTag() { result = "writes" }
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(DataFlow::ModuleVariableNode n, DataFlow::Node read |
|
||||
read = n.getAWrite() and
|
||||
value = n.getVariable().getId() and
|
||||
@@ -34,3 +30,5 @@ class GlobalWriteTest extends InlineExpectationsTest {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<MergeTests<GlobalReadTest, GlobalWriteTest>>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
failures
|
||||
testFailures
|
||||
|
||||
@@ -8,12 +8,10 @@ import TestUtilities.InlineExpectationsTest
|
||||
import semmle.python.dataflow.new.SensitiveDataSources
|
||||
private import semmle.python.ApiGraphs
|
||||
|
||||
class SensitiveDataSourcesTest extends InlineExpectationsTest {
|
||||
SensitiveDataSourcesTest() { this = "SensitiveDataSourcesTest" }
|
||||
module SensitiveDataSourcesTest implements TestSig {
|
||||
string getARelevantTag() { result in ["SensitiveDataSource", "SensitiveUse"] }
|
||||
|
||||
override string getARelevantTag() { result in ["SensitiveDataSource", "SensitiveUse"] }
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(location.getFile().getRelativePath()) and
|
||||
exists(SensitiveDataSource source |
|
||||
location = source.getLocation() and
|
||||
@@ -32,6 +30,8 @@ class SensitiveDataSourcesTest extends InlineExpectationsTest {
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<SensitiveDataSourcesTest>
|
||||
|
||||
class SensitiveUseConfiguration extends TaintTracking::Configuration {
|
||||
SensitiveUseConfiguration() { this = "SensitiveUseConfiguration" }
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
failures
|
||||
testFailures
|
||||
|
||||
@@ -3,12 +3,10 @@ import semmle.python.dataflow.new.DataFlow
|
||||
import TestUtilities.InlineExpectationsTest
|
||||
import experimental.dataflow.testConfig
|
||||
|
||||
class CaptureTest extends InlineExpectationsTest {
|
||||
CaptureTest() { this = "CaptureTest" }
|
||||
module CaptureTest implements TestSig {
|
||||
string getARelevantTag() { result = "captured" }
|
||||
|
||||
override string getARelevantTag() { result = "captured" }
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(DataFlow::Node sink | exists(TestConfiguration cfg | cfg.hasFlowTo(sink)) |
|
||||
location = sink.getLocation() and
|
||||
tag = "captured" and
|
||||
@@ -17,3 +15,5 @@ class CaptureTest extends InlineExpectationsTest {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<CaptureTest>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
failures
|
||||
testFailures
|
||||
|
||||
@@ -72,12 +72,10 @@ private class ImportConfiguration extends DataFlow::Configuration {
|
||||
}
|
||||
}
|
||||
|
||||
class ResolutionTest extends InlineExpectationsTest {
|
||||
ResolutionTest() { this = "ResolutionTest" }
|
||||
module ResolutionTest implements TestSig {
|
||||
string getARelevantTag() { result = "prints" }
|
||||
|
||||
override string getARelevantTag() { result = "prints" }
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
(
|
||||
exists(DataFlow::PathNode source, DataFlow::PathNode sink, ImportConfiguration config |
|
||||
config.hasFlowPath(source, sink) and
|
||||
@@ -105,12 +103,10 @@ private string getTagForVersion(int version) {
|
||||
version = major_version()
|
||||
}
|
||||
|
||||
class VersionSpecificResolutionTest extends InlineExpectationsTest {
|
||||
VersionSpecificResolutionTest() { this = "VersionSpecificResolutionTest" }
|
||||
module VersionSpecificResolutionTest implements TestSig {
|
||||
string getARelevantTag() { result = getTagForVersion(_) }
|
||||
|
||||
override string getARelevantTag() { result = getTagForVersion(_) }
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
(
|
||||
exists(DataFlow::PathNode source, DataFlow::PathNode sink, ImportConfiguration config |
|
||||
config.hasFlowPath(source, sink) and
|
||||
@@ -130,3 +126,5 @@ class VersionSpecificResolutionTest extends InlineExpectationsTest {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<MergeTests<ResolutionTest, VersionSpecificResolutionTest>>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
failures
|
||||
testFailures
|
||||
|
||||
@@ -18,12 +18,10 @@ private class ImmediateModuleRef extends DataFlow::Node {
|
||||
string getAsname() { result = alias }
|
||||
}
|
||||
|
||||
class ImportTest extends InlineExpectationsTest {
|
||||
ImportTest() { this = "ImportTest" }
|
||||
module ImportTest implements TestSig {
|
||||
string getARelevantTag() { result = "imports" }
|
||||
|
||||
override string getARelevantTag() { result = "imports" }
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(ImmediateModuleRef ref |
|
||||
tag = "imports" and
|
||||
location = ref.getLocation() and
|
||||
@@ -33,12 +31,10 @@ class ImportTest extends InlineExpectationsTest {
|
||||
}
|
||||
}
|
||||
|
||||
class AliasTest extends InlineExpectationsTest {
|
||||
AliasTest() { this = "AliasTest" }
|
||||
module AliasTest implements TestSig {
|
||||
string getARelevantTag() { result = "as" }
|
||||
|
||||
override string getARelevantTag() { result = "as" }
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(ImmediateModuleRef ref |
|
||||
tag = "as" and
|
||||
location = ref.getLocation() and
|
||||
@@ -47,3 +43,5 @@ class AliasTest extends InlineExpectationsTest {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<MergeTests<ImportTest, AliasTest>>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
failures
|
||||
testFailures
|
||||
debug_callableNotUnique
|
||||
pointsTo_found_typeTracker_notFound
|
||||
typeTracker_found_pointsTo_notFound
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
failures
|
||||
testFailures
|
||||
debug_callableNotUnique
|
||||
pointsTo_found_typeTracker_notFound
|
||||
typeTracker_found_pointsTo_notFound
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
failures
|
||||
testFailures
|
||||
debug_callableNotUnique
|
||||
pointsTo_found_typeTracker_notFound
|
||||
| code/class_attr_assign.py:10:9:10:27 | ControlFlowNode for Attribute() | my_func |
|
||||
|
||||
@@ -37,12 +37,10 @@ predicate typeTrackerClassCall(CallNode call, Function callable) {
|
||||
)
|
||||
}
|
||||
|
||||
class CallGraphTest extends InlineExpectationsTest {
|
||||
CallGraphTest() { this = "CallGraphTest" }
|
||||
module CallGraphTest implements TestSig {
|
||||
string getARelevantTag() { result in ["pt", "tt"] }
|
||||
|
||||
override string getARelevantTag() { result in ["pt", "tt"] }
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(location.getFile().getRelativePath()) and
|
||||
exists(CallNode call, Function target |
|
||||
tag = "tt" and
|
||||
@@ -58,6 +56,8 @@ class CallGraphTest extends InlineExpectationsTest {
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<CallGraphTest>
|
||||
|
||||
bindingset[call, target]
|
||||
string getCallEdgeValue(CallNode call, Function target) {
|
||||
if call.getLocation().getFile() = target.getLocation().getFile()
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
failures
|
||||
testFailures
|
||||
|
||||
@@ -3,22 +3,20 @@ import semmle.python.dataflow.new.DataFlow
|
||||
import TestUtilities.InlineExpectationsTest
|
||||
import semmle.python.ApiGraphs
|
||||
|
||||
class ApiUseTest extends InlineExpectationsTest {
|
||||
ApiUseTest() { this = "ApiUseTest" }
|
||||
|
||||
override string getARelevantTag() { result = "use" }
|
||||
module ApiUseTest implements TestSig {
|
||||
string getARelevantTag() { result = "use" }
|
||||
|
||||
private predicate relevant_node(API::Node a, DataFlow::Node n, Location l) {
|
||||
n = a.getAValueReachableFromSource() and l = n.getLocation()
|
||||
}
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(DataFlow::Node n | this.relevant_node(_, n, location) |
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(DataFlow::Node n | relevant_node(_, n, location) |
|
||||
tag = "use" and
|
||||
// Only report the longest path on this line:
|
||||
value =
|
||||
max(API::Node a2, Location l2 |
|
||||
this.relevant_node(a2, _, l2) and
|
||||
relevant_node(a2, _, l2) and
|
||||
l2.getFile() = location.getFile() and
|
||||
l2.getStartLine() = location.getStartLine()
|
||||
|
|
||||
@@ -28,3 +26,5 @@ class ApiUseTest extends InlineExpectationsTest {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<ApiUseTest>
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
failures
|
||||
testFailures
|
||||
| test.py:1:1:1:3 | foo | Tag mismatch: Actual result with tag 'foo' that is not part of getARelevantTag() |
|
||||
| test.py:4:1:4:3 | foo | Tag mismatch: Actual result with tag 'foo' that is not part of getARelevantTag() |
|
||||
|
||||
@@ -4,12 +4,10 @@
|
||||
import python
|
||||
import TestUtilities.InlineExpectationsTest
|
||||
|
||||
class MissingRelevantTag extends InlineExpectationsTest {
|
||||
MissingRelevantTag() { this = "MissingRelevantTag" }
|
||||
module MissingRelevantTag implements TestSig {
|
||||
string getARelevantTag() { none() }
|
||||
|
||||
override string getARelevantTag() { none() }
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(Name name | name.getId() = "foo" |
|
||||
location = name.getLocation() and
|
||||
element = name.toString() and
|
||||
@@ -18,3 +16,5 @@ class MissingRelevantTag extends InlineExpectationsTest {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<MissingRelevantTag>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
failures
|
||||
testFailures
|
||||
|
||||
@@ -2,12 +2,10 @@ import python
|
||||
import semmle.python.essa.SsaCompute
|
||||
import TestUtilities.InlineExpectationsTest
|
||||
|
||||
class UseTest extends InlineExpectationsTest {
|
||||
UseTest() { this = "UseTest" }
|
||||
module UseTest implements TestSig {
|
||||
string getARelevantTag() { result in ["use-use", "def-use", "def"] }
|
||||
|
||||
override string getARelevantTag() { result in ["use-use", "def-use", "def"] }
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(location.getFile().getRelativePath()) and
|
||||
exists(string name | name in ["x", "y"] |
|
||||
exists(NameNode nodeTo, Location prevLoc |
|
||||
@@ -39,3 +37,5 @@ class UseTest extends InlineExpectationsTest {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<UseTest>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
failures
|
||||
testFailures
|
||||
|
||||
@@ -3,12 +3,10 @@ private import semmle.python.dataflow.new.DataFlow
|
||||
private import semmle.python.frameworks.internal.PoorMansFunctionResolution
|
||||
import TestUtilities.InlineExpectationsTest
|
||||
|
||||
class InlinePoorMansFunctionResolutionTest extends InlineExpectationsTest {
|
||||
InlinePoorMansFunctionResolutionTest() { this = "InlinePoorMansFunctionResolutionTest" }
|
||||
module InlinePoorMansFunctionResolutionTest implements TestSig {
|
||||
string getARelevantTag() { result = "resolved" }
|
||||
|
||||
override string getARelevantTag() { result = "resolved" }
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(location.getFile().getRelativePath()) and
|
||||
exists(Function func, DataFlow::Node ref |
|
||||
ref = poorMansFunctionTracker(func) and
|
||||
@@ -26,3 +24,5 @@ class InlinePoorMansFunctionResolutionTest extends InlineExpectationsTest {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<InlinePoorMansFunctionResolutionTest>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
failures
|
||||
testFailures
|
||||
|
||||
@@ -4,17 +4,15 @@ import TestUtilities.InlineExpectationsTest
|
||||
import semmle.python.functions.ModificationOfParameterWithDefault
|
||||
private import semmle.python.dataflow.new.internal.PrintNode
|
||||
|
||||
class ModificationOfParameterWithDefaultTest extends InlineExpectationsTest {
|
||||
ModificationOfParameterWithDefaultTest() { this = "ModificationOfParameterWithDefaultTest" }
|
||||
module ModificationOfParameterWithDefaultTest implements TestSig {
|
||||
string getARelevantTag() { result = "modification" }
|
||||
|
||||
override string getARelevantTag() { result = "modification" }
|
||||
|
||||
predicate relevant_node(DataFlow::Node sink) {
|
||||
private predicate relevant_node(DataFlow::Node sink) {
|
||||
exists(ModificationOfParameterWithDefault::Configuration cfg | cfg.hasFlowTo(sink))
|
||||
}
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(DataFlow::Node n | this.relevant_node(n) |
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(DataFlow::Node n | relevant_node(n) |
|
||||
n.getLocation() = location and
|
||||
tag = "modification" and
|
||||
value = prettyNode(n) and
|
||||
@@ -22,3 +20,5 @@ class ModificationOfParameterWithDefaultTest extends InlineExpectationsTest {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<ModificationOfParameterWithDefaultTest>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
failures
|
||||
testFailures
|
||||
|
||||
@@ -3,12 +3,10 @@ import semmle.python.dataflow.new.DataFlow
|
||||
import TestUtilities.InlineExpectationsTest
|
||||
import semmle.python.security.dataflow.ExceptionInfo
|
||||
|
||||
class ExceptionInfoTest extends InlineExpectationsTest {
|
||||
ExceptionInfoTest() { this = "ExceptionInfoTest" }
|
||||
module ExceptionInfoTest implements TestSig {
|
||||
string getARelevantTag() { result = "exceptionInfo" }
|
||||
|
||||
override string getARelevantTag() { result = "exceptionInfo" }
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(location.getFile().getRelativePath()) and
|
||||
exists(ExceptionInfo e |
|
||||
location = e.getLocation() and
|
||||
@@ -18,3 +16,5 @@ class ExceptionInfoTest extends InlineExpectationsTest {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<ExceptionInfoTest>
|
||||
|
||||
Reference in New Issue
Block a user