Skip to content

Commit 646e158

Browse files
committed
Make tests use config from InlineFlowTest
For InterProceduralDataFlow, it's hard to get it to use InlineFlowTest because you need to show both the source and the sink, and there are problems with quoting when the source is already surrounded by quotes.
1 parent 8185427 commit 646e158

5 files changed

Lines changed: 19 additions & 43 deletions

File tree

go/ql/test/library-tests/semmle/go/dataflow/ChannelField/test.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
failures
12
edges
23
| test.go:9:9:9:11 | selection of c [collection] | test.go:9:7:9:11 | <-... |
34
| test.go:13:16:13:16 | definition of s [pointer, c, collection] | test.go:16:2:16:2 | s [pointer, c, collection] |
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
import go
2-
import DataFlow::PathGraph
2+
import TestUtilities.InlineFlowTest
33

4-
class TestConfig extends DataFlow::Configuration {
5-
TestConfig() { this = "test config" }
4+
module Flow = DataFlow::Global<DefaultFlowConfig>;
65

7-
override predicate isSource(DataFlow::Node source) {
8-
source.(DataFlow::CallNode).getTarget().getName() = "source"
9-
}
6+
import Flow::PathGraph
107

11-
override predicate isSink(DataFlow::Node sink) {
12-
sink = any(DataFlow::CallNode c | c.getTarget().getName() = "sink").getAnArgument()
13-
}
14-
}
15-
16-
from DataFlow::PathNode source, DataFlow::PathNode sink, TestConfig c
17-
where c.hasFlowPath(source, sink)
8+
from Flow::PathNode source, Flow::PathNode sink
9+
where Flow::flowPath(source, sink)
1810
select source, source, sink, "path"

go/ql/test/library-tests/semmle/go/dataflow/InterProceduralDataFlow/Test.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
failures
2+
#select
13
| destructuring.go:6:13:6:21 | "tainted" | destructuring.go:20:11:20:12 | s1 |
24
| destructuring.go:6:13:6:21 | "tainted" | destructuring.go:27:11:27:12 | s1 |
35
| destructuring.go:11:13:11:26 | "also tainted" | destructuring.go:34:11:34:12 | s3 |
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
import go
2+
import TestUtilities.InlineFlowTest
23

3-
class MyConfiguration extends DataFlow::Configuration {
4-
MyConfiguration() { this = "MyConfiguration" }
5-
6-
override predicate isSource(DataFlow::Node nd) {
4+
module Config implements DataFlow::ConfigSig {
5+
predicate isSource(DataFlow::Node nd) {
76
exists(ValueEntity v, Write w |
87
v.getName().matches("source%") and
98
w.writes(v, nd)
109
)
1110
}
1211

13-
override predicate isSink(DataFlow::Node nd) {
12+
predicate isSink(DataFlow::Node nd) {
1413
exists(ValueEntity v, Write w |
1514
v.getName().matches("sink%") and
1615
w.writes(v, nd)
1716
)
1817
}
1918
}
2019

21-
from MyConfiguration cfg, DataFlow::Node source, DataFlow::Node sink
22-
where cfg.hasFlow(source, sink)
20+
module Flow = DataFlow::Global<Config>;
21+
22+
from DataFlow::Node source, DataFlow::Node sink
23+
where Flow::flow(source, sink)
2324
select source, sink

go/ql/test/library-tests/semmle/go/dataflow/PromotedMethods/DataFlowConfig.ql

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,13 @@
11
import go
2-
import TestUtilities.InlineExpectationsTest
2+
import TestUtilities.InlineFlowTest
33

4-
class SourceFunction extends Function {
5-
SourceFunction() { this.getName() = "source" }
6-
}
7-
8-
class SinkFunction extends Function {
9-
SinkFunction() { this.getName() = "sink" }
10-
}
11-
12-
class TestConfig extends DataFlow::Configuration {
13-
TestConfig() { this = "testconfig" }
14-
15-
override predicate isSource(DataFlow::Node source) {
16-
source = any(SourceFunction f).getACall().getAResult()
17-
}
18-
19-
override predicate isSink(DataFlow::Node sink) {
20-
sink = any(SinkFunction f).getACall().getAnArgument()
21-
}
22-
}
4+
module ValueFlow = DataFlow::Global<DefaultFlowConfig>;
235

246
module PromotedMethodsTest implements TestSig {
257
string getARelevantTag() { result = "promotedmethods" }
268

279
predicate hasActualResult(Location location, string element, string tag, string value) {
28-
exists(TestConfig config, DataFlow::Node source, DataFlow::Node sink |
29-
config.hasFlow(source, sink)
30-
|
10+
exists(DataFlow::Node source, DataFlow::Node sink | ValueFlow::flow(source, sink) |
3111
sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(),
3212
location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and
3313
element = sink.toString() and

0 commit comments

Comments
 (0)