Skip to content

Commit f83df76

Browse files
committed
Shared: Apply ShowProvenance in InlineFlowTest.qll
1 parent 0dfdee7 commit f83df76

File tree

9 files changed

+74
-5
lines changed

9 files changed

+74
-5
lines changed

csharp/ql/test/TestUtilities/InlineFlowTest.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import csharp
77
private import codeql.dataflow.test.InlineFlowTest
88
private import semmle.code.csharp.dataflow.internal.DataFlowImplSpecific
99
private import semmle.code.csharp.dataflow.internal.TaintTrackingImplSpecific
10+
private import semmle.code.csharp.dataflow.internal.ExternalFlow as ExternalFlow
1011
private import internal.InlineExpectationsTestImpl
1112

1213
private module FlowTestImpl implements InputSig<Location, CsharpDataFlow> {
@@ -33,6 +34,8 @@ private module FlowTestImpl implements InputSig<Location, CsharpDataFlow> {
3334
) and
3435
exists(sink)
3536
}
37+
38+
predicate interpretModelForTest = ExternalFlow::interpretModelForTest/2;
3639
}
3740

3841
import InlineFlowTestMake<Location, CsharpDataFlow, CsharpTaintTracking, Impl, FlowTestImpl>

go/ql/test/TestUtilities/InlineFlowTest.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import go
77
private import codeql.dataflow.test.InlineFlowTest
88
private import semmle.go.dataflow.internal.DataFlowImplSpecific
99
private import semmle.go.dataflow.internal.TaintTrackingImplSpecific
10+
private import semmle.go.dataflow.ExternalFlow as ExternalFlow
1011
private import internal.InlineExpectationsTestImpl
1112

1213
private module FlowTestImpl implements InputSig<Location, GoDataFlow> {
@@ -24,6 +25,8 @@ private module FlowTestImpl implements InputSig<Location, GoDataFlow> {
2425
exists(src) and
2526
result = "\"" + sink.toString() + "\""
2627
}
28+
29+
predicate interpretModelForTest = ExternalFlow::interpretModelForTest/2;
2730
}
2831

2932
import InlineFlowTestMake<Location, GoDataFlow, GoTaintTracking, Impl, FlowTestImpl>

java/ql/test-kotlin1/TestUtilities/InlineFlowTest.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import semmle.code.java.dataflow.DataFlow
88
private import codeql.dataflow.test.InlineFlowTest
99
private import semmle.code.java.dataflow.internal.DataFlowImplSpecific
1010
private import semmle.code.java.dataflow.internal.TaintTrackingImplSpecific
11+
private import semmle.code.java.dataflow.ExternalFlow as ExternalFlow
1112
private import internal.InlineExpectationsTestImpl
1213

1314
private module FlowTestImpl implements InputSig<Location, JavaDataFlow> {
@@ -28,6 +29,8 @@ private module FlowTestImpl implements InputSig<Location, JavaDataFlow> {
2829
(if exists(getSourceArgString(src)) then result = getSourceArgString(src) else result = "") and
2930
exists(sink)
3031
}
32+
33+
predicate interpretModelForTest = ExternalFlow::interpretModelForTest/2;
3134
}
3235

3336
import InlineFlowTestMake<Location, JavaDataFlow, JavaTaintTracking, Impl, FlowTestImpl>

java/ql/test-kotlin2/TestUtilities/InlineFlowTest.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import semmle.code.java.dataflow.DataFlow
88
private import codeql.dataflow.test.InlineFlowTest
99
private import semmle.code.java.dataflow.internal.DataFlowImplSpecific
1010
private import semmle.code.java.dataflow.internal.TaintTrackingImplSpecific
11+
private import semmle.code.java.dataflow.ExternalFlow as ExternalFlow
1112
private import internal.InlineExpectationsTestImpl
1213

1314
private module FlowTestImpl implements InputSig<Location, JavaDataFlow> {
@@ -28,6 +29,8 @@ private module FlowTestImpl implements InputSig<Location, JavaDataFlow> {
2829
(if exists(getSourceArgString(src)) then result = getSourceArgString(src) else result = "") and
2930
exists(sink)
3031
}
32+
33+
predicate interpretModelForTest = ExternalFlow::interpretModelForTest/2;
3134
}
3235

3336
import InlineFlowTestMake<Location, JavaDataFlow, JavaTaintTracking, Impl, FlowTestImpl>

java/ql/test/TestUtilities/InlineFlowTest.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import semmle.code.java.dataflow.DataFlow
88
private import codeql.dataflow.test.InlineFlowTest
99
private import semmle.code.java.dataflow.internal.DataFlowImplSpecific
1010
private import semmle.code.java.dataflow.internal.TaintTrackingImplSpecific
11+
private import semmle.code.java.dataflow.ExternalFlow as ExternalFlow
1112
private import internal.InlineExpectationsTestImpl
1213

1314
private module FlowTestImpl implements InputSig<Location, JavaDataFlow> {
@@ -28,6 +29,8 @@ private module FlowTestImpl implements InputSig<Location, JavaDataFlow> {
2829
(if exists(getSourceArgString(src)) then result = getSourceArgString(src) else result = "") and
2930
exists(sink)
3031
}
32+
33+
predicate interpretModelForTest = ExternalFlow::interpretModelForTest/2;
3134
}
3235

3336
import InlineFlowTestMake<Location, JavaDataFlow, JavaTaintTracking, Impl, FlowTestImpl>

ruby/ql/lib/codeql/ruby/frameworks/data/internal/ApiGraphModelsExtensions.qll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,25 @@ extensible predicate typeModel(string type1, string type2, string path);
4545
* Holds if `path` can be substituted for a token `TypeVar[name]`.
4646
*/
4747
extensible predicate typeVariableModel(string name, string path);
48+
49+
/**
50+
* Holds if the given extension tuple `madId` should pretty-print as `model`.
51+
*
52+
* This predicate should only be used in tests.
53+
*/
54+
predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) {
55+
exists(string type, string path, string kind |
56+
sourceModel(type, path, kind, madId) and
57+
model = "Source: " + type + "; " + path + "; " + kind
58+
)
59+
or
60+
exists(string type, string path, string kind |
61+
sinkModel(type, path, kind, madId) and
62+
model = "Sink: " + type + "; " + path + "; " + kind
63+
)
64+
or
65+
exists(string type, string path, string input, string output, string kind |
66+
summaryModel(type, path, input, output, kind, madId) and
67+
model = "Summary: " + type + "; " + path + "; " + input + "; " + output + "; " + kind
68+
)
69+
}

ruby/ql/test/TestUtilities/InlineFlowTest.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ private import codeql.Locations
88
private import codeql.dataflow.test.InlineFlowTest
99
private import codeql.ruby.dataflow.internal.DataFlowImplSpecific
1010
private import codeql.ruby.dataflow.internal.TaintTrackingImplSpecific
11+
private import codeql.ruby.frameworks.data.internal.ApiGraphModelsExtensions as ApiGraphModelsExtensions
1112
private import internal.InlineExpectationsTestImpl
1213

1314
private module FlowTestImpl implements InputSig<Location, RubyDataFlow> {
@@ -18,6 +19,8 @@ private module FlowTestImpl implements InputSig<Location, RubyDataFlow> {
1819
(if exists(getSourceArgString(src)) then result = getSourceArgString(src) else result = "") and
1920
exists(sink)
2021
}
22+
23+
predicate interpretModelForTest = ApiGraphModelsExtensions::interpretModelForTest/2;
2124
}
2225

2326
import InlineFlowTestMake<Location, RubyDataFlow, RubyTaintTracking, Impl, FlowTestImpl>

shared/dataflow/codeql/dataflow/test/InlineFlowTest.qll

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ signature module InputSig<LocationSig Location, DF::InputSig<Location> DataFlowL
3838

3939
bindingset[src, sink]
4040
string getArgString(DataFlowLang::Node src, DataFlowLang::Node sink);
41+
42+
/** Holds if the given extension tuple `madId` should pretty-print as `model`. */
43+
predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model);
4144
}
4245

4346
module InlineFlowTestMake<
@@ -51,6 +54,8 @@ module InlineFlowTestMake<
5154

5255
private module InlineExpectationsTest = IET::Make<Test>;
5356

57+
private import ProvenancePathGraph
58+
5459
module DefaultFlowConfig implements DataFlow::ConfigSig {
5560
predicate isSource(DataFlowLang::Node source) { Impl::defaultSource(source) }
5661

@@ -66,13 +71,33 @@ module InlineFlowTestMake<
6671
bindingset[src, sink]
6772
signature string getArgStringSig(DataFlowLang::Node src, DataFlowLang::Node sink);
6873

74+
private module DataFlowGlobal<DataFlow::ConfigSig Config> {
75+
private import DataFlow::Global<Config> as G
76+
import G
77+
78+
module PathGraphNoInterpretModel = G::PathGraph;
79+
80+
module PathGraph =
81+
ShowProvenance<Impl::interpretModelForTest/2, PathNode, PathGraphNoInterpretModel>;
82+
}
83+
84+
private module TaintTrackingGlobal<DataFlow::ConfigSig Config> {
85+
private import TaintTracking::Global<Config> as G
86+
import G
87+
88+
module PathGraphNoInterpretModel = G::PathGraph;
89+
90+
module PathGraph =
91+
ShowProvenance<Impl::interpretModelForTest/2, PathNode, PathGraphNoInterpretModel>;
92+
}
93+
6994
module FlowTestArgString<
7095
DataFlow::ConfigSig ValueFlowConfig, DataFlow::ConfigSig TaintFlowConfig,
7196
getArgStringSig/2 getArgString>
7297
{
73-
module ValueFlow = DataFlow::Global<ValueFlowConfig>;
98+
module ValueFlow = DataFlowGlobal<ValueFlowConfig>;
7499

75-
module TaintFlow = TaintTracking::Global<TaintFlowConfig>;
100+
module TaintFlow = TaintTrackingGlobal<TaintFlowConfig>;
76101

77102
private predicate hasLocationInfo(DataFlowLang::Node node, Test::Location location) {
78103
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
@@ -104,7 +129,11 @@ module InlineFlowTestMake<
104129
}
105130

106131
import InlineExpectationsTest::MakeTest<InlineTest>
107-
import DataFlow::MergePathGraph<ValueFlow::PathNode, TaintFlow::PathNode, ValueFlow::PathGraph, TaintFlow::PathGraph>
132+
private import DataFlow::MergePathGraph<ValueFlow::PathNode, TaintFlow::PathNode, ValueFlow::PathGraphNoInterpretModel, TaintFlow::PathGraphNoInterpretModel> as Merged
133+
import Merged
134+
135+
module PathGraph =
136+
ShowProvenance<Impl::interpretModelForTest/2, Merged::PathNode, Merged::PathGraph>;
108137

109138
predicate flowPath(PathNode source, PathNode sink) {
110139
ValueFlow::flowPath(source.asPathNode1(), sink.asPathNode1()) or

shared/dataflow/codeql/dataflow/test/ProvenancePathGraph.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ private module TranslateModels<
6565
/** Transforms a `PathGraph` by printing the provenance information. */
6666
module ShowProvenance<
6767
interpretModelForTestSig/2 interpretModelForTest, PathNodeSig PathNode,
68-
DF::PathGraphSig<PathNode> PathGraph>
68+
DF::PathGraphSig<PathNode> PathGraph> implements DF::PathGraphSig<PathNode>
6969
{
7070
private predicate provenance(string model) { PathGraph::edges(_, _, _, model) }
7171

7272
private module Models = TranslateModels<interpretModelForTest/2, provenance/1>;
7373

74-
query predicate models(int r, string model) { Models::models(r, model) }
74+
additional query predicate models(int r, string model) { Models::models(r, model) }
7575

7676
query predicate edges(PathNode a, PathNode b, string key, string val) {
7777
exists(string model |

0 commit comments

Comments
 (0)