Skip to content

Commit f745642

Browse files
committed
Refactor Android tests
1 parent 95c2896 commit f745642

File tree

5 files changed

+43
-37
lines changed

5 files changed

+43
-37
lines changed

java/ql/test/library-tests/frameworks/android/content-provider/test.ql

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@ import java
22
import semmle.code.java.dataflow.FlowSources
33
import TestUtilities.InlineFlowTest
44

5-
class EnableLegacy extends EnableLegacyConfiguration {
6-
EnableLegacy() { exists(this) }
7-
}
5+
module ProviderTaintFlowConfig implements DataFlow::ConfigSig {
6+
predicate isSource(DataFlow::Node n) { n instanceof RemoteFlowSource }
7+
8+
predicate isSink(DataFlow::Node n) { DefaultFlowConfig::isSink(n) }
89

9-
class ProviderTaintFlowConf extends DefaultTaintFlowConf {
10-
override predicate isSource(DataFlow::Node n) { n instanceof RemoteFlowSource }
10+
int fieldFlowBranchLimit() { result = DefaultFlowConfig::fieldFlowBranchLimit() }
1111
}
1212

13+
module ProviderTaintFlow = TaintTracking::Global<ProviderTaintFlowConfig>;
14+
1315
class ProviderInlineFlowTest extends InlineFlowTest {
14-
override DataFlow::Configuration getValueFlowConfig() { none() }
16+
override predicate hasValueFlow(DataFlow::Node src, DataFlow::Node sink) { none() }
17+
18+
override predicate hasTaintFlow(DataFlow::Node src, DataFlow::Node sink) {
19+
ProviderTaintFlow::flow(src, sink)
20+
}
1521
}

java/ql/test/library-tests/frameworks/android/external-storage/test.ql

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,18 @@ import semmle.code.java.dataflow.DataFlow
33
import semmle.code.java.dataflow.FlowSources
44
import TestUtilities.InlineFlowTest
55

6-
class EnableLegacy extends EnableLegacyConfiguration {
7-
EnableLegacy() { exists(this) }
8-
}
9-
10-
class Conf extends TaintTracking::Configuration {
11-
Conf() { this = "test:AndroidExternalFlowConf" }
6+
module Config implements DataFlow::ConfigSig {
7+
predicate isSource(DataFlow::Node src) { src instanceof RemoteFlowSource }
128

13-
override predicate isSource(DataFlow::Node src) { src instanceof RemoteFlowSource }
14-
15-
override predicate isSink(DataFlow::Node sink) {
9+
predicate isSink(DataFlow::Node sink) {
1610
sink.asExpr().(Argument).getCall().getCallee().hasName("sink")
1711
}
1812
}
1913

14+
module Flow = TaintTracking::Global<Config>;
15+
2016
class ExternalStorageTest extends InlineFlowTest {
21-
override DataFlow::Configuration getValueFlowConfig() { none() }
17+
override predicate hasValueFlow(DataFlow::Node src, DataFlow::Node sink) { none() }
2218

23-
override DataFlow::Configuration getTaintFlowConfig() { result instanceof Conf }
19+
override predicate hasTaintFlow(DataFlow::Node src, DataFlow::Node sink) { Flow::flow(src, sink) }
2420
}

java/ql/test/library-tests/frameworks/android/sources/OnActivityResultSourceTest.ql

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@ import java
22
import semmle.code.java.dataflow.FlowSources
33
import TestUtilities.InlineFlowTest
44

5-
class EnableLegacy extends EnableLegacyConfiguration {
6-
EnableLegacy() { exists(this) }
7-
}
5+
module SourceValueFlowConfig implements DataFlow::ConfigSig {
6+
predicate isSource(DataFlow::Node src) { src instanceof RemoteFlowSource }
7+
8+
predicate isSink(DataFlow::Node sink) { DefaultFlowConfig::isSink(sink) }
89

9-
class SourceValueFlowConf extends DefaultValueFlowConf {
10-
override predicate isSource(DataFlow::Node src) { src instanceof RemoteFlowSource }
10+
int fieldFlowBranchLimit() { result = DefaultFlowConfig::fieldFlowBranchLimit() }
1111
}
1212

13+
module SourceValueFlow = DataFlow::Global<SourceValueFlowConfig>;
14+
1315
class SourceInlineFlowTest extends InlineFlowTest {
14-
override DataFlow::Configuration getTaintFlowConfig() { none() }
16+
override predicate hasValueFlow(DataFlow::Node src, DataFlow::Node sink) {
17+
SourceValueFlow::flow(src, sink)
18+
}
19+
20+
override predicate hasTaintFlow(DataFlow::Node src, DataFlow::Node sink) { none() }
1521
}

java/ql/test/library-tests/frameworks/android/taint-database/flowSteps.ql

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import semmle.code.java.dataflow.FlowSources
44
import semmle.code.java.security.QueryInjection
55
import TestUtilities.InlineExpectationsTest
66

7-
class Conf extends TaintTracking::Configuration {
8-
Conf() { this = "qltest:dataflow:android::flow" }
9-
10-
override predicate isSource(DataFlow::Node source) {
7+
module Config implements DataFlow::ConfigSig {
8+
predicate isSource(DataFlow::Node source) {
119
source.asExpr().(MethodAccess).getMethod().hasName("taint")
1210
}
1311

14-
override predicate isSink(DataFlow::Node sink) { sink.asExpr() = any(ReturnStmt r).getResult() }
12+
predicate isSink(DataFlow::Node sink) { sink.asExpr() = any(ReturnStmt r).getResult() }
1513
}
1614

15+
module Flow = TaintTracking::Global<Config>;
16+
1717
class FlowStepTest extends InlineExpectationsTest {
1818
FlowStepTest() { this = "FlowStepTest" }
1919

@@ -22,8 +22,7 @@ class FlowStepTest extends InlineExpectationsTest {
2222
override predicate hasActualResult(Location l, string element, string tag, string value) {
2323
tag = "taintReachesReturn" and
2424
value = "" and
25-
exists(Conf conf, DataFlow::Node source |
26-
conf.hasFlow(source, _) and
25+
exists(DataFlow::Node source | Flow::flow(source, _) |
2726
l = source.getLocation() and
2827
element = source.toString()
2928
)

java/ql/test/library-tests/frameworks/android/taint-database/sinks.ql

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import semmle.code.java.dataflow.FlowSources
44
import semmle.code.java.security.QueryInjection
55
import TestUtilities.InlineExpectationsTest
66

7-
class Conf extends TaintTracking::Configuration {
8-
Conf() { this = "qltest:dataflow:android::flow" }
9-
10-
override predicate isSource(DataFlow::Node source) {
7+
module Config implements DataFlow::ConfigSig {
8+
predicate isSource(DataFlow::Node source) {
119
source.asExpr().(MethodAccess).getMethod().hasName("taint")
1210
}
1311

14-
override predicate isSink(DataFlow::Node sink) { sink instanceof QueryInjectionSink }
12+
predicate isSink(DataFlow::Node sink) { sink instanceof QueryInjectionSink }
1513
}
1614

15+
module Flow = TaintTracking::Global<Config>;
16+
1717
class SinkTest extends InlineExpectationsTest {
1818
SinkTest() { this = "SinkTest" }
1919

@@ -22,8 +22,7 @@ class SinkTest extends InlineExpectationsTest {
2222
override predicate hasActualResult(Location l, string element, string tag, string value) {
2323
tag = "taintReachesSink" and
2424
value = "" and
25-
exists(Conf conf, DataFlow::Node source |
26-
conf.hasFlow(source, _) and
25+
exists(DataFlow::Node source | Flow::flow(source, _) |
2726
l = source.getLocation() and
2827
element = source.toString()
2928
)

0 commit comments

Comments
 (0)