Skip to content

Commit ba4d326

Browse files
authored
Merge pull request github#12902 from egregius313/egregius313/java/dataflow/refactor-integration-tests
Java: Refactor Kotlin Integration tests to new DataFlow API
2 parents 8ade724 + 19e6a9a commit ba4d326

File tree

3 files changed

+21
-21
lines changed
  • java/ql/integration-tests/all-platforms/kotlin
    • default-parameter-mad-flow
    • kotlin-interface-inherited-default
    • kotlin_java_static_fields

3 files changed

+21
-21
lines changed

java/ql/integration-tests/all-platforms/kotlin/default-parameter-mad-flow/test.ql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@ import semmle.code.java.dataflow.TaintTracking
33
import TestUtilities.InlineExpectationsTest
44
private import semmle.code.java.dataflow.ExternalFlow
55

6-
class Config extends TaintTracking::Configuration {
7-
Config() { this = "Config" }
8-
9-
override predicate isSource(DataFlow::Node n) {
6+
module Config implements DataFlow::ConfigSig {
7+
predicate isSource(DataFlow::Node n) {
108
n.asExpr().(MethodAccess).getCallee().getName() = "source"
119
or
1210
sourceNode(n, "kotlinMadFlowTest")
1311
}
1412

15-
override predicate isSink(DataFlow::Node n) {
13+
predicate isSink(DataFlow::Node n) {
1614
n.asExpr().(Argument).getCall().getCallee().getName() = "sink"
1715
or
1816
sinkNode(n, "kotlinMadFlowTest")
1917
}
2018
}
2119

20+
module Flow = TaintTracking::Global<Config>;
21+
2222
class InlineFlowTest extends InlineExpectationsTest {
2323
InlineFlowTest() { this = "HasFlowTest" }
2424

2525
override string getARelevantTag() { result = "flow" }
2626

2727
override predicate hasActualResult(Location location, string element, string tag, string value) {
2828
tag = "flow" and
29-
exists(DataFlow::Node sink, Config c | c.hasFlowTo(sink) |
29+
exists(DataFlow::Node sink | Flow::flowTo(sink) |
3030
sink.getLocation() = location and
3131
element = sink.toString() and
3232
value = ""

java/ql/integration-tests/all-platforms/kotlin/kotlin-interface-inherited-default/test.ql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ query predicate superAccesses(
1919
enclosingType = enclosingCallable.getDeclaringType()
2020
}
2121

22-
class Config extends DataFlow::Configuration {
23-
Config() { this = "testconfig" }
24-
25-
override predicate isSource(DataFlow::Node x) {
22+
module Config implements DataFlow::ConfigSig {
23+
predicate isSource(DataFlow::Node x) {
2624
x.asExpr() instanceof IntegerLiteral and x.getEnclosingCallable().fromSource()
2725
}
2826

29-
override predicate isSink(DataFlow::Node x) {
27+
predicate isSink(DataFlow::Node x) {
3028
x.asExpr().(Argument).getCall().getCallee().getName() = "sink"
3129
}
3230
}
3331

34-
from Config c, DataFlow::Node source, DataFlow::Node sink
35-
where c.hasFlow(source, sink)
32+
module Flow = DataFlow::Global<Config>;
33+
34+
from DataFlow::Node source, DataFlow::Node sink
35+
where Flow::flow(source, sink)
3636
select source, sink
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import java
22
import semmle.code.java.dataflow.DataFlow
3-
import DataFlow::PathGraph
3+
import Flow::PathGraph
44

5-
class Config extends DataFlow::Configuration {
6-
Config() { this = "Config" }
5+
module Config implements DataFlow::ConfigSig {
6+
predicate isSource(DataFlow::Node n) { n.asExpr().(StringLiteral).getValue() = "taint" }
77

8-
override predicate isSource(DataFlow::Node n) { n.asExpr().(StringLiteral).getValue() = "taint" }
9-
10-
override predicate isSink(DataFlow::Node n) {
8+
predicate isSink(DataFlow::Node n) {
119
n.asExpr().(Argument).getCall().getCallee().getName() = "sink"
1210
}
1311
}
1412

15-
from DataFlow::PathNode source, DataFlow::PathNode sink, Config c
16-
where c.hasFlowPath(source, sink)
13+
module Flow = DataFlow::Global<Config>;
14+
15+
from Flow::PathNode source, Flow::PathNode sink
16+
where Flow::flowPath(source, sink)
1717
select source, source, sink, "flow path"

0 commit comments

Comments
 (0)