Skip to content

Commit 8830f15

Browse files
author
Benjamin Muskalla
committed
Convert some tests to use InlineFlowTest
1 parent acb0554 commit 8830f15

File tree

3 files changed

+10
-49
lines changed

3 files changed

+10
-49
lines changed

java/ql/test/TestUtilities/InlineFlowTest.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class DefaultValueFlowConf extends DataFlow::Configuration {
1111
}
1212

1313
override predicate isSink(DataFlow::Node n) {
14-
n.asExpr().(Argument).getCall().getCallee().hasName("sink")
14+
exists(MethodAccess ma | ma.getMethod().hasName("sink") | n.asExpr() = ma.getAnArgument())
1515
}
1616
}
1717

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
import java
22
import semmle.code.java.dataflow.DataFlow
33
import semmle.code.java.dataflow.FlowSteps
4-
import TestUtilities.InlineExpectationsTest
5-
6-
class Conf extends DataFlow::Configuration {
7-
Conf() { this = "qltest:dataflow:fluent-methods" }
8-
9-
override predicate isSource(DataFlow::Node n) {
10-
n.asExpr().(MethodAccess).getMethod().hasName("source")
11-
}
12-
13-
override predicate isSink(DataFlow::Node n) {
14-
exists(MethodAccess ma | ma.getMethod().hasName("sink") | n.asExpr() = ma.getAnArgument())
15-
}
16-
}
4+
import TestUtilities.InlineFlowTest
175

186
class Model extends FluentMethod {
197
Model() { this.getName() = "modelledFluentMethod" }
@@ -25,17 +13,6 @@ class IdentityModel extends ValuePreservingMethod {
2513
override predicate returnsValue(int arg) { arg = 0 }
2614
}
2715

28-
class HasFlowTest extends InlineExpectationsTest {
29-
HasFlowTest() { this = "HasFlowTest" }
30-
31-
override string getARelevantTag() { result = "hasTaintFlow" }
32-
33-
override predicate hasActualResult(Location location, string element, string tag, string value) {
34-
tag = "hasTaintFlow" and
35-
exists(DataFlow::Node src, DataFlow::Node sink, Conf conf | conf.hasFlow(src, sink) |
36-
sink.getLocation() = location and
37-
element = sink.toString() and
38-
value = ""
39-
)
40-
}
16+
class HasFlowTest extends InlineFlowTest {
17+
override DataFlow::Configuration getValueFlowConfig() { none() }
4118
}
Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import java
22
import semmle.code.java.dataflow.TaintTracking
3-
import TestUtilities.InlineExpectationsTest
3+
import TestUtilities.InlineFlowTest
44

55
class TaintFlowConf extends TaintTracking::Configuration {
66
TaintFlowConf() { this = "qltest:frameworks:jax-rs-taint" }
@@ -27,28 +27,12 @@ class ValueFlowConf extends DataFlow::Configuration {
2727
exists(MethodAccess ma | ma.getMethod().hasName("sink") | n.asExpr() = ma.getAnArgument())
2828
}
2929

30+
// TODO: move to default?
3031
override int fieldFlowBranchLimit() { result = 1000 }
3132
}
3233

33-
class HasFlowTest extends InlineExpectationsTest {
34-
HasFlowTest() { this = "HasFlowTest" }
35-
36-
override string getARelevantTag() { result = ["hasTaintFlow", "hasValueFlow"] }
37-
38-
override predicate hasActualResult(Location location, string element, string tag, string value) {
39-
tag = "hasTaintFlow" and
40-
exists(DataFlow::Node src, DataFlow::Node sink, TaintFlowConf conf | conf.hasFlow(src, sink) |
41-
not any(ValueFlowConf vconf).hasFlow(src, sink) and
42-
sink.getLocation() = location and
43-
element = sink.toString() and
44-
value = ""
45-
)
46-
or
47-
tag = "hasValueFlow" and
48-
exists(DataFlow::Node src, DataFlow::Node sink, ValueFlowConf conf | conf.hasFlow(src, sink) |
49-
sink.getLocation() = location and
50-
element = sink.toString() and
51-
value = ""
52-
)
53-
}
34+
class HasFlowTest extends InlineFlowTest {
35+
override DataFlow::Configuration getValueFlowConfig() { result = any(ValueFlowConf config) }
36+
37+
override DataFlow::Configuration getTaintFlowConfig() { result = any(TaintFlowConf config) }
5438
}

0 commit comments

Comments
 (0)