Skip to content

Commit 5c586c3

Browse files
committed
C#: Re-factor the InlineFlowTest framework.
1 parent 61b8f97 commit 5c586c3

File tree

5 files changed

+24
-35
lines changed

5 files changed

+24
-35
lines changed

csharp/ql/test/TestUtilities/InlineFlowTest.qll

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
* Example for a test.ql:
55
* ```ql
66
* import csharp
7-
* import DataFlow::PathGraph
7+
* import DefaultValueFlow::PathGraph
88
* import TestUtilities.InlineFlowTest
99
*
10-
* from DataFlow::PathNode source, DataFlow::PathNode sink, DefaultValueFlowConf conf
11-
* where conf.hasFlowPath(source, sink)
10+
* from DefaultValueFlow::PathNode source, DefaultValueFlow::PathNode sink
11+
* where DefaultValueFlow::flowPath(source, sink)
1212
* select sink, source, sink, "$@", source, source.toString()
13+
*
1314
* ```
1415
*
1516
* To declare expecations, you can use the $hasTaintFlow or $hasValueFlow comments within the test source files.
@@ -56,25 +57,17 @@ private predicate defaultSink(DataFlow::Node sink) {
5657
)
5758
}
5859

59-
class DefaultValueFlowConf extends DataFlow::Configuration {
60-
DefaultValueFlowConf() { this = "qltest:defaultValueFlowConf" }
61-
62-
override predicate isSource(DataFlow::Node n) { defaultSource(n) }
60+
module DefaultFlowConfig implements DataFlow::ConfigSig {
61+
predicate isSource(DataFlow::Node n) { defaultSource(n) }
6362

64-
override predicate isSink(DataFlow::Node n) { defaultSink(n) }
63+
predicate isSink(DataFlow::Node n) { defaultSink(n) }
6564

66-
override int fieldFlowBranchLimit() { result = 1000 }
65+
int fieldFlowBranchLimit() { result = 1000 }
6766
}
6867

69-
class DefaultTaintFlowConf extends TaintTracking::Configuration {
70-
DefaultTaintFlowConf() { this = "qltest:defaultTaintFlowConf" }
68+
module DefaultValueFlow = DataFlow::Global<DefaultFlowConfig>;
7169

72-
override predicate isSource(DataFlow::Node n) { defaultSource(n) }
73-
74-
override predicate isSink(DataFlow::Node n) { defaultSink(n) }
75-
76-
override int fieldFlowBranchLimit() { result = 1000 }
77-
}
70+
module DefaultTaintFlow = TaintTracking::Global<DefaultFlowConfig>;
7871

7972
private string getSourceArgString(DataFlow::Node src) {
8073
defaultSource(src) and
@@ -88,23 +81,19 @@ class InlineFlowTest extends InlineExpectationsTest {
8881

8982
override predicate hasActualResult(Location location, string element, string tag, string value) {
9083
tag = "hasValueFlow" and
91-
exists(DataFlow::Node src, DataFlow::Node sink | getValueFlowConfig().hasFlow(src, sink) |
84+
exists(DataFlow::Node src, DataFlow::Node sink | DefaultValueFlow::flow(src, sink) |
9285
sink.getLocation() = location and
9386
element = sink.toString() and
9487
if exists(getSourceArgString(src)) then value = getSourceArgString(src) else value = ""
9588
)
9689
or
9790
tag = "hasTaintFlow" and
9891
exists(DataFlow::Node src, DataFlow::Node sink |
99-
getTaintFlowConfig().hasFlow(src, sink) and not getValueFlowConfig().hasFlow(src, sink)
92+
DefaultTaintFlow::flow(src, sink) and not DefaultValueFlow::flow(src, sink)
10093
|
10194
sink.getLocation() = location and
10295
element = sink.toString() and
10396
if exists(getSourceArgString(src)) then value = getSourceArgString(src) else value = ""
10497
)
10598
}
106-
107-
DataFlow::Configuration getValueFlowConfig() { result = any(DefaultValueFlowConf config) }
108-
109-
DataFlow::Configuration getTaintFlowConfig() { result = any(DefaultTaintFlowConf config) }
11099
}

csharp/ql/test/library-tests/dataflow/fields/FieldFlow.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
*/
44

55
import csharp
6-
import DataFlow::PathGraph
6+
import DefaultValueFlow::PathGraph
77
import TestUtilities.InlineFlowTest
88

9-
from DataFlow::PathNode source, DataFlow::PathNode sink, DefaultValueFlowConf conf
10-
where conf.hasFlowPath(source, sink)
9+
from DefaultValueFlow::PathNode source, DefaultValueFlow::PathNode sink
10+
where DefaultValueFlow::flowPath(source, sink)
1111
select sink, source, sink, "$@", source, source.toString()

csharp/ql/test/library-tests/dataflow/operators/operatorFlow.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
*/
44

55
import csharp
6-
import DataFlow::PathGraph
6+
import DefaultValueFlow::PathGraph
77
import TestUtilities.InlineFlowTest
88

9-
from DataFlow::PathNode source, DataFlow::PathNode sink, DefaultValueFlowConf conf
10-
where conf.hasFlowPath(source, sink)
9+
from DefaultValueFlow::PathNode source, DefaultValueFlow::PathNode sink
10+
where DefaultValueFlow::flowPath(source, sink)
1111
select sink, source, sink, "$@", source, source.toString()

csharp/ql/test/library-tests/dataflow/patterns/PatternFlow.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
*/
44

55
import csharp
6-
import DataFlow::PathGraph
6+
import DefaultValueFlow::PathGraph
77
import TestUtilities.InlineFlowTest
88

9-
from DataFlow::PathNode source, DataFlow::PathNode sink, DefaultValueFlowConf conf
10-
where conf.hasFlowPath(source, sink)
9+
from DefaultValueFlow::PathNode source, DefaultValueFlow::PathNode sink
10+
where DefaultValueFlow::flowPath(source, sink)
1111
select sink, source, sink, "$@", source, source.toString()

csharp/ql/test/library-tests/dataflow/tuples/Tuples.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
*/
44

55
import csharp
6-
import DataFlow::PathGraph
6+
import DefaultValueFlow::PathGraph
77
import TestUtilities.InlineFlowTest
88

9-
from DataFlow::PathNode source, DataFlow::PathNode sink, DefaultValueFlowConf conf
10-
where conf.hasFlowPath(source, sink)
9+
from DefaultValueFlow::PathNode source, DefaultValueFlow::PathNode sink
10+
where DefaultValueFlow::flowPath(source, sink)
1111
select sink, source, sink, "$@", source, source.toString()

0 commit comments

Comments
 (0)