Skip to content

Commit d6d21e3

Browse files
committed
Go: Update remaining inline expectation tests to use the paramterized module
1 parent 890a67d commit d6d21e3

File tree

6 files changed

+70
-79
lines changed

6 files changed

+70
-79
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
failures
2+
testFailures
Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import go
22
import TestUtilities.InlineExpectationsTest
33

4-
class UntrustedFlowSourceTest extends InlineExpectationsTest {
5-
UntrustedFlowSourceTest() { this = "untrustedflowsource" }
4+
module UntrustedFlowSourceTest implements TestSig {
5+
string getARelevantTag() { result = "untrustedflowsource" }
66

7-
override string getARelevantTag() { result = "untrustedflowsource" }
8-
9-
override predicate hasActualResult(Location location, string element, string tag, string value) {
7+
predicate hasActualResult(Location location, string element, string tag, string value) {
108
tag = "untrustedflowsource" and
119
value = element and
1210
exists(UntrustedFlowSource src | value = "\"" + src.toString() + "\"" |
@@ -16,12 +14,10 @@ class UntrustedFlowSourceTest extends InlineExpectationsTest {
1614
}
1715
}
1816

19-
class HeaderWriteTest extends InlineExpectationsTest {
20-
HeaderWriteTest() { this = "headerwrite" }
21-
22-
override string getARelevantTag() { result = "headerwrite" }
17+
module HeaderWriteTest implements TestSig {
18+
string getARelevantTag() { result = "headerwrite" }
2319

24-
override predicate hasActualResult(Location location, string element, string tag, string value) {
20+
predicate hasActualResult(Location location, string element, string tag, string value) {
2521
tag = "headerwrite" and
2622
exists(Http::HeaderWrite hw, string name, string val | element = hw.toString() |
2723
hw.definesHeader(name, val) and
@@ -32,12 +28,10 @@ class HeaderWriteTest extends InlineExpectationsTest {
3228
}
3329
}
3430

35-
class LoggerTest extends InlineExpectationsTest {
36-
LoggerTest() { this = "LoggerTest" }
37-
38-
override string getARelevantTag() { result = "logger" }
31+
module LoggerTest implements TestSig {
32+
string getARelevantTag() { result = "logger" }
3933

40-
override predicate hasActualResult(Location location, string element, string tag, string value) {
34+
predicate hasActualResult(Location location, string element, string tag, string value) {
4135
exists(LoggerCall log |
4236
log.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(),
4337
location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and
@@ -48,32 +42,32 @@ class LoggerTest extends InlineExpectationsTest {
4842
}
4943
}
5044

51-
class Config extends TaintTracking::Configuration {
52-
Config() { this = "goproxy config" }
53-
54-
override predicate isSource(DataFlow::Node n) {
45+
module Config implements DataFlow::ConfigSig {
46+
predicate isSource(DataFlow::Node n) {
5547
n = any(DataFlow::CallNode c | c.getCalleeName().matches("tainted%")).getResult()
5648
}
5749

58-
override predicate isSink(DataFlow::Node n) {
50+
predicate isSink(DataFlow::Node n) {
5951
n = any(DataFlow::CallNode cn | cn.getTarget().getName() = "sink").getAnArgument()
6052
}
6153
}
6254

63-
class TaintFlow extends InlineExpectationsTest {
64-
TaintFlow() { this = "goproxy flow" }
55+
module Flow = TaintTracking::Global<Config>;
6556

66-
override string getARelevantTag() { result = "taintflow" }
57+
module TaintFlow implements TestSig {
58+
string getARelevantTag() { result = "taintflow" }
6759

68-
override predicate hasActualResult(Location location, string element, string tag, string value) {
60+
predicate hasActualResult(Location location, string element, string tag, string value) {
6961
tag = "taintflow" and
7062
value = "" and
7163
element = "" and
72-
exists(Config c, DataFlow::Node toNode |
64+
exists(DataFlow::Node toNode |
7365
toNode
7466
.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(),
7567
location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and
76-
c.hasFlowTo(toNode)
68+
Flow::flowTo(toNode)
7769
)
7870
}
7971
}
72+
73+
import MakeTest<MergeTests4<UntrustedFlowSourceTest, HeaderWriteTest, LoggerTest, TaintFlow>>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
failures
2+
testFailures
Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import go
22
import TestUtilities.InlineExpectationsTest
33

4-
class SqlTest extends InlineExpectationsTest {
5-
SqlTest() { this = "SQLTest" }
4+
module SqlTest implements TestSig {
5+
string getARelevantTag() { result = "query" }
66

7-
override string getARelevantTag() { result = "query" }
8-
9-
override predicate hasActualResult(Location location, string element, string tag, string value) {
7+
predicate hasActualResult(Location location, string element, string tag, string value) {
108
tag = "query" and
119
exists(SQL::Query q, SQL::QueryString qs | qs = q.getAQueryString() |
1210
q.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(),
@@ -17,12 +15,10 @@ class SqlTest extends InlineExpectationsTest {
1715
}
1816
}
1917

20-
class QueryString extends InlineExpectationsTest {
21-
QueryString() { this = "QueryString no Query" }
22-
23-
override string getARelevantTag() { result = "querystring" }
18+
module QueryString implements TestSig {
19+
string getARelevantTag() { result = "querystring" }
2420

25-
override predicate hasActualResult(Location location, string element, string tag, string value) {
21+
predicate hasActualResult(Location location, string element, string tag, string value) {
2622
tag = "querystring" and
2723
element = "" and
2824
exists(SQL::QueryString qs | not exists(SQL::Query q | qs = q.getAQueryString()) |
@@ -33,30 +29,30 @@ class QueryString extends InlineExpectationsTest {
3329
}
3430
}
3531

36-
class Config extends TaintTracking::Configuration {
37-
Config() { this = "pg-orm config" }
32+
module Config implements DataFlow::ConfigSig {
33+
predicate isSource(DataFlow::Node n) { n.asExpr() instanceof StringLit }
3834

39-
override predicate isSource(DataFlow::Node n) { n.asExpr() instanceof StringLit }
40-
41-
override predicate isSink(DataFlow::Node n) {
35+
predicate isSink(DataFlow::Node n) {
4236
n = any(DataFlow::CallNode cn | cn.getTarget().getName() = "sink").getAnArgument()
4337
}
4438
}
4539

46-
class TaintFlow extends InlineExpectationsTest {
47-
TaintFlow() { this = "pg-orm flow" }
40+
module Flow = TaintTracking::Global<Config>;
4841

49-
override string getARelevantTag() { result = "flowfrom" }
42+
module TaintFlow implements TestSig {
43+
string getARelevantTag() { result = "flowfrom" }
5044

51-
override predicate hasActualResult(Location location, string element, string tag, string value) {
45+
predicate hasActualResult(Location location, string element, string tag, string value) {
5246
tag = "flowfrom" and
5347
element = "" and
54-
exists(Config c, DataFlow::Node fromNode, DataFlow::Node toNode |
48+
exists(DataFlow::Node fromNode, DataFlow::Node toNode |
5549
toNode
5650
.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(),
5751
location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and
58-
c.hasFlow(fromNode, toNode) and
52+
Flow::flow(fromNode, toNode) and
5953
value = fromNode.asExpr().(StringLit).getValue()
6054
)
6155
}
6256
}
57+
58+
import MakeTest<MergeTests3<SqlTest, QueryString, TaintFlow>>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
failures
2+
testFailures

go/ql/test/library-tests/semmle/go/frameworks/Yaml/tests.ql

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,29 @@ DataFlow::CallNode getAYamlCall() {
1111
isYamlFunction(result.getACalleeIncludingExternals().asFunction())
1212
}
1313

14-
class TaintTransitsFunctionConfig extends TaintTracking::Configuration {
15-
TaintTransitsFunctionConfig() { this = "TaintTransitsFunctionConfig" }
16-
17-
predicate isSourceSinkPair(DataFlow::Node inNode, DataFlow::Node outNode) {
18-
exists(DataFlow::CallNode cn | cn = getAYamlCall() |
19-
inNode = [cn.getAnArgument(), cn.getReceiver()] and
20-
(
21-
outNode.(DataFlow::PostUpdateNode).getPreUpdateNode() =
22-
[cn.getAnArgument(), cn.getReceiver()]
23-
or
24-
outNode = cn.getAResult()
25-
)
14+
predicate isSourceSinkPair(DataFlow::Node inNode, DataFlow::Node outNode) {
15+
exists(DataFlow::CallNode cn | cn = getAYamlCall() |
16+
inNode = [cn.getAnArgument(), cn.getReceiver()] and
17+
(
18+
outNode.(DataFlow::PostUpdateNode).getPreUpdateNode() = [cn.getAnArgument(), cn.getReceiver()]
19+
or
20+
outNode = cn.getAResult()
2621
)
27-
}
22+
)
23+
}
2824

29-
override predicate isSource(DataFlow::Node n) { this.isSourceSinkPair(n, _) }
25+
module TaintTransitsFunctionConfig implements DataFlow::ConfigSig {
26+
predicate isSource(DataFlow::Node n) { isSourceSinkPair(n, _) }
3027

31-
override predicate isSink(DataFlow::Node n) { this.isSourceSinkPair(_, n) }
28+
predicate isSink(DataFlow::Node n) { isSourceSinkPair(_, n) }
3229
}
3330

34-
class TaintFunctionModelTest extends InlineExpectationsTest {
35-
TaintFunctionModelTest() { this = "TaintFunctionModelTest" }
31+
module TaintTransitsFunctionFlow = TaintTracking::Global<TaintTransitsFunctionConfig>;
3632

37-
override string getARelevantTag() { result = "ttfnmodelstep" }
33+
module TaintFunctionModelTest implements TestSig {
34+
string getARelevantTag() { result = "ttfnmodelstep" }
3835

39-
override predicate hasActualResult(Location location, string element, string tag, string value) {
36+
predicate hasActualResult(Location location, string element, string tag, string value) {
4037
tag = "ttfnmodelstep" and
4138
(
4239
exists(TaintTracking::FunctionModel model, DataFlow::CallNode call | call = model.getACall() |
@@ -46,9 +43,9 @@ class TaintFunctionModelTest extends InlineExpectationsTest {
4643
value = "\"" + model.getAnInputNode(call) + " -> " + model.getAnOutputNode(call) + "\""
4744
)
4845
or
49-
exists(TaintTransitsFunctionConfig config, DataFlow::Node arg, DataFlow::Node output |
50-
config.hasFlow(arg, output) and
51-
config.isSourceSinkPair(arg, output) and
46+
exists(DataFlow::Node arg, DataFlow::Node output |
47+
TaintTransitsFunctionFlow::flow(arg, output) and
48+
isSourceSinkPair(arg, output) and
5249
arg.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(),
5350
location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and
5451
element = arg.toString() and
@@ -58,12 +55,10 @@ class TaintFunctionModelTest extends InlineExpectationsTest {
5855
}
5956
}
6057

61-
class MarshalerTest extends InlineExpectationsTest {
62-
MarshalerTest() { this = "MarshalerTest" }
63-
64-
override string getARelevantTag() { result = "marshaler" }
58+
module MarshalerTest implements TestSig {
59+
string getARelevantTag() { result = "marshaler" }
6560

66-
override predicate hasActualResult(Location location, string element, string tag, string value) {
61+
predicate hasActualResult(Location location, string element, string tag, string value) {
6762
tag = "marshaler" and
6863
exists(MarshalingFunction m, DataFlow::CallNode call | call = m.getACall() |
6964
call.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(),
@@ -76,12 +71,10 @@ class MarshalerTest extends InlineExpectationsTest {
7671
}
7772
}
7873

79-
class UnmarshalerTest extends InlineExpectationsTest {
80-
UnmarshalerTest() { this = "UnmarshalerTest" }
74+
module UnmarshalerTest implements TestSig {
75+
string getARelevantTag() { result = "unmarshaler" }
8176

82-
override string getARelevantTag() { result = "unmarshaler" }
83-
84-
override predicate hasActualResult(Location location, string element, string tag, string value) {
77+
predicate hasActualResult(Location location, string element, string tag, string value) {
8578
tag = "unmarshaler" and
8679
exists(UnmarshalingFunction m, DataFlow::CallNode call | call = m.getACall() |
8780
call.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(),
@@ -93,3 +86,5 @@ class UnmarshalerTest extends InlineExpectationsTest {
9386
)
9487
}
9588
}
89+
90+
import MakeTest<MergeTests3<TaintFunctionModelTest, MarshalerTest, UnmarshalerTest>>

0 commit comments

Comments
 (0)