mirror of
https://github.com/github/codeql.git
synced 2026-04-26 09:15:12 +02:00
C#: Migrate unit tests to data extensions.
This commit is contained in:
@@ -7,40 +7,6 @@ import DataFlow::PathGraph
|
||||
import semmle.code.csharp.dataflow.ExternalFlow
|
||||
import CsvValidation
|
||||
|
||||
class SummaryModelTest extends SummaryModelCsv {
|
||||
override predicate row(string row) {
|
||||
row =
|
||||
[
|
||||
//"namespace;type;overrides;name;signature;ext;inputspec;outputspec;kind;provenance",
|
||||
"My.Qltest;D;false;StepArgRes;(System.Object);;Argument[0];ReturnValue;taint;manual",
|
||||
"My.Qltest;D;false;StepArgArg;(System.Object,System.Object);;Argument[0];Argument[1];taint;manual",
|
||||
"My.Qltest;D;false;StepArgQual;(System.Object);;Argument[0];Argument[this];taint;manual",
|
||||
"My.Qltest;D;false;StepFieldGetter;();;Argument[this].Field[My.Qltest.D.Field];ReturnValue;value;manual",
|
||||
"My.Qltest;D;false;StepFieldSetter;(System.Object);;Argument[0];Argument[this].Field[My.Qltest.D.Field];value;manual",
|
||||
"My.Qltest;D;false;StepFieldSetter;(System.Object);;Argument[this];ReturnValue.Field[My.Qltest.D.Field2];value;manual",
|
||||
"My.Qltest;D;false;StepPropertyGetter;();;Argument[this].Property[My.Qltest.D.Property];ReturnValue;value;manual",
|
||||
"My.Qltest;D;false;StepPropertySetter;(System.Object);;Argument[0];Argument[this].Property[My.Qltest.D.Property];value;manual",
|
||||
"My.Qltest;D;false;StepElementGetter;();;Argument[this].Element;ReturnValue;value;manual",
|
||||
"My.Qltest;D;false;StepElementSetter;(System.Object);;Argument[0];Argument[this].Element;value;manual",
|
||||
"My.Qltest;D;false;Apply<,>;(System.Func<S,T>,S);;Argument[1];Argument[0].Parameter[0];value;manual",
|
||||
"My.Qltest;D;false;Apply<,>;(System.Func<S,T>,S);;Argument[0].ReturnValue;ReturnValue;value;manual",
|
||||
"My.Qltest;D;false;Apply2<>;(System.Action<S>,S,S);;Argument[1].Field[My.Qltest.D.Field];Argument[0].Parameter[0];value;manual",
|
||||
"My.Qltest;D;false;Apply2<>;(System.Action<S>,S,S);;Argument[2].Field[My.Qltest.D.Field2];Argument[0].Parameter[0];value;manual",
|
||||
"My.Qltest;D;false;Map<,>;(S[],System.Func<S,T>);;Argument[0].Element;Argument[1].Parameter[0];value;manual",
|
||||
"My.Qltest;D;false;Map<,>;(S[],System.Func<S,T>);;Argument[1].ReturnValue;ReturnValue.Element;value;manual",
|
||||
"My.Qltest;D;false;Parse;(System.String,System.Int32);;Argument[0];Argument[1];taint;manual",
|
||||
"My.Qltest;D;false;Reverse;(System.Object[]);;Argument[0].WithElement;ReturnValue;value;manual",
|
||||
"My.Qltest;E;true;get_MyProp;();;Argument[this].Field[My.Qltest.E.MyField];ReturnValue;value;manual",
|
||||
"My.Qltest;E;true;set_MyProp;(System.Object);;Argument[0];Argument[this].Field[My.Qltest.E.MyField];value;manual",
|
||||
"My.Qltest;G;false;GeneratedFlow;(System.Object);;Argument[0];ReturnValue;value;generated",
|
||||
"My.Qltest;G;false;GeneratedFlowArgs;(System.Object,System.Object);;Argument[0];ReturnValue;value;generated",
|
||||
"My.Qltest;G;false;GeneratedFlowArgs;(System.Object,System.Object);;Argument[1];ReturnValue;value;generated",
|
||||
"My.Qltest;G;false;MixedFlowArgs;(System.Object,System.Object);;Argument[0];ReturnValue;value;generated",
|
||||
"My.Qltest;G;false;MixedFlowArgs;(System.Object,System.Object);;Argument[1];ReturnValue;value;manual",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
class Conf extends TaintTracking::Configuration {
|
||||
Conf() { this = "ExternalFlow" }
|
||||
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
extensions:
|
||||
|
||||
- addsTo:
|
||||
pack: codeql/csharp-all
|
||||
extensible: extSourceModel
|
||||
data:
|
||||
# "namespace", "type", "overrides", "name", "signature", "ext", "spec", "kind", "provenance",
|
||||
- ["My.Qltest", "A", false, "Src1", "()", "", "ReturnValue", "local", "manual"]
|
||||
- ["My.Qltest", "A", false, "Src1", "(System.String)", "", "ReturnValue", "local", "manual"]
|
||||
- ["My.Qltest", "A", false, "Src1", "", "", "ReturnValue", "local", "manual"]
|
||||
- ["My.Qltest", "A", false, "Src2", "()", "", "ReturnValue", "local", "manual"]
|
||||
- ["My.Qltest", "A", false, "Src3", "()", "", "ReturnValue", "local", "manual"]
|
||||
- ["My.Qltest", "A", true, "Src2", "()", "", "ReturnValue", "local", "manual"]
|
||||
- ["My.Qltest", "A", true, "Src3", "()", "", "ReturnValue", "local", "manual"]
|
||||
- ["My.Qltest", "A", false, "SrcArg", "(System.Object)", "", "Argument[0]", "local", "manual"]
|
||||
- ["My.Qltest", "A", false, "SrcArg", "(System.Object)", "", "Argument", "local", "manual"]
|
||||
- ["My.Qltest", "A", true, "SrcParam", "(System.Object)", "", "Parameter[0]", "local", "manual"]
|
||||
- ["My.Qltest", "SourceAttribute", false, "", "", "Attribute", "ReturnValue", "local", "manual"]
|
||||
- ["My.Qltest", "SourceAttribute", false, "", "", "Attribute", "Parameter", "local", "manual"]
|
||||
- ["My.Qltest", "SourceAttribute", false, "", "", "Attribute", "", "local", "manual"]
|
||||
- ["My.Qltest", "A", false, "SrcTwoArg", "(System.String,System.String)", "", "ReturnValue", "local", "manual"]
|
||||
|
||||
- addsTo:
|
||||
pack: codeql/csharp-all
|
||||
extensible: extSinkModel
|
||||
data:
|
||||
# "namespace", "type", "overrides", "name", "signature", "ext", "spec", "kind", "provenance"
|
||||
- ["My.Qltest", "B", false, "Sink1", "(System.Object)", "", "Argument[0]", "code", "manual"]
|
||||
- ["My.Qltest", "B", false, "SinkMethod", "()", "", "ReturnValue", "xss", "manual"]
|
||||
- ["My.Qltest", "SinkAttribute", false, "", "", "Attribute", "ReturnValue", "html", "manual"]
|
||||
- ["My.Qltest", "SinkAttribute", false, "", "", "Attribute", "Argument", "remote", "manual"]
|
||||
- ["My.Qltest", "SinkAttribute", false, "", "", "Attribute", "", "sql", "manual"]
|
||||
|
||||
# Summaries relevant for the ExternalFlow testcase.
|
||||
- addsTo:
|
||||
pack: codeql/csharp-all
|
||||
extensible: extSummaryModel
|
||||
data:
|
||||
# "namespace", "type", "overrides", "name", "signature", "ext", "inputspec", "outputspec", "kind", "provenance"
|
||||
- ["My.Qltest", "D", false, "StepArgRes", "(System.Object)","", "Argument[0]", "ReturnValue", "taint", "manual"]
|
||||
- ["My.Qltest", "D", false, "StepArgArg", "(System.Object,System.Object)", "", "Argument[0]", "Argument[1]", "taint", "manual"]
|
||||
- ["My.Qltest", "D", false, "StepArgQual", "(System.Object)", "", "Argument[0]", "Argument[this]", "taint", "manual"]
|
||||
- ["My.Qltest", "D", false, "StepFieldGetter", "()", "", "Argument[this].Field[My.Qltest.D.Field]", "ReturnValue", "value", "manual"]
|
||||
- ["My.Qltest", "D", false, "StepFieldSetter", "(System.Object)", "", "Argument[0]", "Argument[this].Field[My.Qltest.D.Field]", "value", "manual"]
|
||||
- ["My.Qltest", "D", false, "StepFieldSetter", "(System.Object)", "", "Argument[this]", "ReturnValue.Field[My.Qltest.D.Field2]", "value", "manual"]
|
||||
- ["My.Qltest", "D", false, "StepPropertyGetter", "()", "", "Argument[this].Property[My.Qltest.D.Property]", "ReturnValue", "value", "manual"]
|
||||
- ["My.Qltest", "D", false, "StepPropertySetter", "(System.Object)", "", "Argument[0]", "Argument[this].Property[My.Qltest.D.Property]", "value", "manual"]
|
||||
- ["My.Qltest", "D", false, "StepElementGetter", "()", "", "Argument[this].Element", "ReturnValue", "value", "manual"]
|
||||
- ["My.Qltest", "D", false, "StepElementSetter", "(System.Object)", "", "Argument[0]", "Argument[this].Element", "value", "manual"]
|
||||
- ["My.Qltest", "D", false, "Apply<,>", "(System.Func<S,T>,S)", "", "Argument[1]", "Argument[0].Parameter[0]", "value", "manual"]
|
||||
- ["My.Qltest", "D", false, "Apply<,>", "(System.Func<S,T>,S)", "", "Argument[0].ReturnValue", "ReturnValue", "value", "manual"]
|
||||
- ["My.Qltest", "D", false, "Apply2<>", "(System.Action<S>,S,S)", "", "Argument[1].Field[My.Qltest.D.Field]", "Argument[0].Parameter[0]", "value", "manual"]
|
||||
- ["My.Qltest", "D", false, "Apply2<>", "(System.Action<S>,S,S)", "", "Argument[2].Field[My.Qltest.D.Field2]", "Argument[0].Parameter[0]", "value", "manual"]
|
||||
- ["My.Qltest", "D", false, "Map<,>", "(S[],System.Func<S,T>)", "", "Argument[0].Element", "Argument[1].Parameter[0]", "value", "manual"]
|
||||
- ["My.Qltest", "D", false, "Map<,>", "(S[],System.Func<S,T>)", "", "Argument[1].ReturnValue", "ReturnValue.Element", "value", "manual"]
|
||||
- ["My.Qltest", "D", false, "Parse", "(System.String,System.Int32)", "", "Argument[0]", "Argument[1]", "taint", "manual"]
|
||||
- ["My.Qltest", "D", false, "Reverse", "(System.Object[])", "", "Argument[0].WithElement", "ReturnValue", "value", "manual"]
|
||||
- ["My.Qltest", "E", true, "get_MyProp", "()", "", "Argument[this].Field[My.Qltest.E.MyField]", "ReturnValue", "value", "manual"]
|
||||
- ["My.Qltest", "E", true, "set_MyProp", "(System.Object)", "", "Argument[0]", "Argument[this].Field[My.Qltest.E.MyField]", "value", "manual"]
|
||||
- ["My.Qltest", "G", false, "GeneratedFlow", "(System.Object)", "", "Argument[0]", "ReturnValue", "value", "generated"]
|
||||
- ["My.Qltest", "G", false, "GeneratedFlowArgs", "(System.Object,System.Object)", "", "Argument[0]", "ReturnValue", "value", "generated"]
|
||||
- ["My.Qltest", "G", false, "GeneratedFlowArgs", "(System.Object,System.Object)", "", "Argument[1]", "ReturnValue", "value", "generated"]
|
||||
- ["My.Qltest", "G", false, "MixedFlowArgs", "(System.Object,System.Object)", "", "Argument[0]", "ReturnValue", "value", "generated"]
|
||||
- ["My.Qltest", "G", false, "MixedFlowArgs", "(System.Object,System.Object)", "", "Argument[1]", "ReturnValue", "value", "manual"]
|
||||
|
||||
# Summaries relevant for the Steps testcase.
|
||||
- addsTo:
|
||||
pack: codeql/csharp-all
|
||||
extensible: extSummaryModel
|
||||
# "namespace", "type", "overrides", "name", "signature", "ext", "inputspec", "outputspec", "kind", "provenance"
|
||||
data:
|
||||
- ["My.Qltest", "C", false, "StepArgRes", "(System.Object)", "", "Argument[0]", "ReturnValue", "taint", "manual"]
|
||||
- ["My.Qltest", "C", false, "StepArgArg", "(System.Object,System.Object)", "", "Argument[0]", "Argument[1]", "taint", "manual"]
|
||||
- ["My.Qltest", "C", false, "StepArgQual", "(System.Object)", "", "Argument[0]", "Argument[this]", "taint", "manual"]
|
||||
- ["My.Qltest", "C", false, "StepQualRes", "()", "", "Argument[this]", "ReturnValue", "taint", "manual"]
|
||||
- ["My.Qltest", "C", false, "StepQualArg", "(System.Object)", "", "Argument[this]", "Argument[0]", "taint", "manual"]
|
||||
- ["My.Qltest", "C", false, "StepFieldGetter", "()", "", "Argument[this].Field[My.Qltest.C.Field]", "ReturnValue", "value", "manual"]
|
||||
- ["My.Qltest", "C", false, "StepFieldSetter", "(System.Int32)", "", "Argument[0]", "Argument[this].Field[My.Qltest.C.Field]", "value", "manual"]
|
||||
- ["My.Qltest", "C", false, "StepPropertyGetter", "()", "", "Argument[this].Property[My.Qltest.C.Property]", "ReturnValue", "value", "manual"]
|
||||
- ["My.Qltest", "C", false, "StepPropertySetter", "(System.Int32)", "", "Argument[0]", "Argument[this].Property[My.Qltest.C.Property]", "value", "manual"]
|
||||
- ["My.Qltest", "C", false, "StepElementGetter", "()", "", "Argument[this].Element", "ReturnValue", "value", "manual"]
|
||||
- ["My.Qltest", "C", false, "StepElementSetter", "(System.Int32)", "", "Argument[0]", "Argument[this].Element", "value", "manual"]
|
||||
- ["My.Qltest", "C+Generic<,>", false, "StepGeneric", "(T)", "", "Argument[0]", "ReturnValue", "value", "manual"]
|
||||
- ["My.Qltest", "C+Generic<,>", false, "StepGeneric2<>", "(S)", "", "Argument[0]", "ReturnValue", "value", "manual"]
|
||||
- ["My.Qltest", "C+Base<>", true, "StepOverride", "(T)", "", "Argument[0]", "ReturnValue", "value", "manual"]
|
||||
@@ -2,21 +2,6 @@ import csharp
|
||||
import DataFlow
|
||||
import semmle.code.csharp.dataflow.ExternalFlow
|
||||
import CsvValidation
|
||||
import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
|
||||
|
||||
class SinkModelTest extends SinkModelCsv {
|
||||
override predicate row(string row) {
|
||||
row =
|
||||
[
|
||||
//"namespace;type;overrides;name;signature;ext;spec;kind;provenance",
|
||||
"My.Qltest;B;false;Sink1;(System.Object);;Argument[0];code;manual",
|
||||
"My.Qltest;B;false;SinkMethod;();;ReturnValue;xss;manual",
|
||||
"My.Qltest;SinkAttribute;false;;;Attribute;ReturnValue;html;manual",
|
||||
"My.Qltest;SinkAttribute;false;;;Attribute;Argument;remote;manual",
|
||||
"My.Qltest;SinkAttribute;false;;;Attribute;;sql;manual"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
from DataFlow::Node node, string kind
|
||||
where sinkNode(node, kind)
|
||||
|
||||
@@ -2,30 +2,6 @@ import csharp
|
||||
import DataFlow
|
||||
import semmle.code.csharp.dataflow.ExternalFlow
|
||||
import CsvValidation
|
||||
import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
|
||||
|
||||
class SourceModelTest extends SourceModelCsv {
|
||||
override predicate row(string row) {
|
||||
row =
|
||||
[
|
||||
//"namespace;type;overrides;name;signature;ext;spec;kind;provenance",
|
||||
"My.Qltest;A;false;Src1;();;ReturnValue;local;manual",
|
||||
"My.Qltest;A;false;Src1;(System.String);;ReturnValue;local;manual",
|
||||
"My.Qltest;A;false;Src1;;;ReturnValue;local;manual",
|
||||
"My.Qltest;A;false;Src2;();;ReturnValue;local;manual",
|
||||
"My.Qltest;A;false;Src3;();;ReturnValue;local;manual",
|
||||
"My.Qltest;A;true;Src2;();;ReturnValue;local;manual",
|
||||
"My.Qltest;A;true;Src3;();;ReturnValue;local;manual",
|
||||
"My.Qltest;A;false;SrcArg;(System.Object);;Argument[0];local;manual",
|
||||
"My.Qltest;A;false;SrcArg;(System.Object);;Argument;local;manual",
|
||||
"My.Qltest;A;true;SrcParam;(System.Object);;Parameter[0];local;manual",
|
||||
"My.Qltest;SourceAttribute;false;;;Attribute;ReturnValue;local;manual",
|
||||
"My.Qltest;SourceAttribute;false;;;Attribute;Parameter;local;manual",
|
||||
"My.Qltest;SourceAttribute;false;;;Attribute;;local;manual",
|
||||
"My.Qltest;A;false;SrcTwoArg;(System.String,System.String);;ReturnValue;local;manual"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
from DataFlow::Node node, string kind
|
||||
where sourceNode(node, kind)
|
||||
|
||||
@@ -6,47 +6,30 @@ import semmle.code.csharp.dataflow.FlowSummary
|
||||
import semmle.code.csharp.dataflow.internal.DataFlowDispatch as DataFlowDispatch
|
||||
import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
|
||||
|
||||
private class SummaryModelTest extends SummaryModelCsv {
|
||||
override predicate row(string row) {
|
||||
row =
|
||||
[
|
||||
//"namespace;type;overrides;name;signature;ext;inputspec;outputspec;kind;provenance",
|
||||
"My.Qltest;C;false;StepArgRes;(System.Object);;Argument[0];ReturnValue;taint;manual",
|
||||
"My.Qltest;C;false;StepArgArg;(System.Object,System.Object);;Argument[0];Argument[1];taint;manual",
|
||||
"My.Qltest;C;false;StepArgQual;(System.Object);;Argument[0];Argument[this];taint;manual",
|
||||
"My.Qltest;C;false;StepQualRes;();;Argument[this];ReturnValue;taint;manual",
|
||||
"My.Qltest;C;false;StepQualArg;(System.Object);;Argument[this];Argument[0];taint;manual",
|
||||
"My.Qltest;C;false;StepFieldGetter;();;Argument[this].Field[My.Qltest.C.Field];ReturnValue;value;manual",
|
||||
"My.Qltest;C;false;StepFieldSetter;(System.Int32);;Argument[0];Argument[this].Field[My.Qltest.C.Field];value;manual",
|
||||
"My.Qltest;C;false;StepPropertyGetter;();;Argument[this].Property[My.Qltest.C.Property];ReturnValue;value;manual",
|
||||
"My.Qltest;C;false;StepPropertySetter;(System.Int32);;Argument[0];Argument[this].Property[My.Qltest.C.Property];value;manual",
|
||||
"My.Qltest;C;false;StepElementGetter;();;Argument[this].Element;ReturnValue;value;manual",
|
||||
"My.Qltest;C;false;StepElementSetter;(System.Int32);;Argument[0];Argument[this].Element;value;manual",
|
||||
"My.Qltest;C+Generic<,>;false;StepGeneric;(T);;Argument[0];ReturnValue;value;manual",
|
||||
"My.Qltest;C+Generic<,>;false;StepGeneric2<>;(S);;Argument[0];ReturnValue;value;manual",
|
||||
"My.Qltest;C+Base<>;true;StepOverride;(T);;Argument[0];ReturnValue;value;manual"
|
||||
]
|
||||
}
|
||||
private SummarizedCallable getRelevantSummarizedCallable() {
|
||||
exists(SummarizedCallable sc |
|
||||
sc.getDeclaringType*().getName() = "C" and
|
||||
sc instanceof DataFlowDispatch::DataFlowSummarizedCallable and
|
||||
result = sc
|
||||
)
|
||||
}
|
||||
|
||||
query predicate summaryThroughStep(
|
||||
DataFlow::Node node1, DataFlow::Node node2, boolean preservesValue
|
||||
) {
|
||||
FlowSummaryImpl::Private::Steps::summaryThroughStepValue(node1, node2,
|
||||
any(DataFlowDispatch::DataFlowSummarizedCallable sc)) and
|
||||
getRelevantSummarizedCallable()) and
|
||||
preservesValue = true
|
||||
or
|
||||
FlowSummaryImpl::Private::Steps::summaryThroughStepTaint(node1, node2,
|
||||
any(DataFlowDispatch::DataFlowSummarizedCallable sc)) and
|
||||
getRelevantSummarizedCallable()) and
|
||||
preservesValue = false
|
||||
}
|
||||
|
||||
query predicate summaryGetterStep(DataFlow::Node arg, DataFlow::Node out, Content c) {
|
||||
FlowSummaryImpl::Private::Steps::summaryGetterStep(arg, c, out,
|
||||
any(DataFlowDispatch::DataFlowSummarizedCallable sc))
|
||||
FlowSummaryImpl::Private::Steps::summaryGetterStep(arg, c, out, getRelevantSummarizedCallable())
|
||||
}
|
||||
|
||||
query predicate summarySetterStep(DataFlow::Node arg, DataFlow::Node out, Content c) {
|
||||
FlowSummaryImpl::Private::Steps::summarySetterStep(arg, c, out,
|
||||
any(DataFlowDispatch::DataFlowSummarizedCallable sc))
|
||||
FlowSummaryImpl::Private::Steps::summarySetterStep(arg, c, out, getRelevantSummarizedCallable())
|
||||
}
|
||||
|
||||
@@ -4,4 +4,6 @@ dependencies:
|
||||
codeql/csharp-all: ${workspace}
|
||||
codeql/csharp-queries: ${workspace}
|
||||
extractor: csharp
|
||||
dataExtensions:
|
||||
- library-tests/dataflow/external-models/ext/*.model.yml
|
||||
tests: .
|
||||
|
||||
Reference in New Issue
Block a user