Skip to content

Commit 6360e0b

Browse files
committed
Add flow-through test case generator
1 parent 6fee40c commit 6360e0b

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

java/ql/src/utils/GenerateFlowTestCase.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
workDir = tempfile.mkdtemp()
3333

34-
# Step 1: make a database that touches all types whose methods we want to test:
34+
# Make a database that touches all types whose methods we want to test:
3535
print("Creating Maven project")
3636
projectDir = os.path.join(workDir, "mavenProject")
3737
os.makedirs(projectDir)
@@ -138,6 +138,10 @@ def getTuples(queryName, jsonResult, fname):
138138
with open(os.path.join(scriptPath, "testFooter.qlfrag"), "r") as header:
139139
shutil.copyfileobj(header, f)
140140

141+
# Make an empty .expected file, since this is an inline-exectations test
142+
with open(os.path.join(sys.argv[3], "test.expected")):
143+
pass
144+
141145
cmd = ['codeql', 'query', 'format', '-qq', '-i', resultQl]
142146
subprocess.call(cmd)
143147

java/ql/src/utils/GenerateFlowTestCase.qll

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import java
22
import semmle.code.java.dataflow.internal.DataFlowPrivate
33
import semmle.code.java.dataflow.ExternalFlow
44
import semmle.code.java.dataflow.FlowSummary
5+
import semmle.code.java.dataflow.internal.FlowSummaryImpl
56

67
bindingset[this]
78
abstract class CsvRow extends string { }
89

9-
Type getParameterType(SummarizedCallableExternal callable, int i) {
10+
Type getParameterType(Private::External::SummarizedCallableExternal callable, int i) {
1011
if i = -1 then result = callable.getDeclaringType() else result = callable.getParameterType(i)
1112
}
1213

@@ -66,15 +67,15 @@ Type getRootSourceDeclaration(Type t) {
6667

6768
newtype TRowTestSnippet =
6869
MkSnippet(
69-
CsvRow row, SummarizedCallableExternal callable, SummaryComponentStack input,
70+
CsvRow row, Private::External::SummarizedCallableExternal callable, SummaryComponentStack input,
7071
SummaryComponentStack output, boolean preservesValue
7172
) {
7273
callable.propagatesFlowForRow(input, output, preservesValue, row)
7374
}
7475

7576
class RowTestSnippet extends TRowTestSnippet {
7677
string row;
77-
SummarizedCallableExternal callable;
78+
Private::External::SummarizedCallableExternal callable;
7879
SummaryComponentStack input;
7980
SummaryComponentStack output;
8081
SummaryComponentStack baseInput;
@@ -122,7 +123,10 @@ class RowTestSnippet extends TRowTestSnippet {
122123
// new Type(filler, in, out, filler);
123124
exists(string storePrefix, string invokePrefix, string args |
124125
(
125-
if baseOutput = SummaryComponentStack::return()
126+
if
127+
baseOutput = SummaryComponentStack::return()
128+
or
129+
callable instanceof Constructor and baseOutput = SummaryComponentStack::argument(-1)
126130
then storePrefix = "out = "
127131
else storePrefix = ""
128132
) and
@@ -213,15 +217,15 @@ class RowTestSnippet extends TRowTestSnippet {
213217

214218
string getASupportMethodModel() {
215219
exists(SummaryComponent c, string contentSsvDescription |
216-
c = input.drop(_).head() and c = interpretComponent(contentSsvDescription)
220+
c = input.drop(_).head() and c = Private::External::interpretComponent(contentSsvDescription)
217221
|
218222
result =
219223
"generatedtest;Test;false;newWith" + contentToken(getContent(c)) + ";;;Argument[0];" +
220224
contentSsvDescription + " of ReturnValue;value"
221225
)
222226
or
223227
exists(SummaryComponent c, string contentSsvDescription |
224-
c = output.drop(_).head() and c = interpretComponent(contentSsvDescription)
228+
c = output.drop(_).head() and c = Private::External::interpretComponent(contentSsvDescription)
225229
|
226230
result =
227231
"generatedtest;Test;false;get" + contentToken(getContent(c)) + ";;;" + contentSsvDescription

java/ql/src/utils/testFooter.qlfrag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class HasFlowTest extends InlineExpectationsTest {
3232
)
3333
or
3434
tag = "hasTaintFlow" and
35-
exists(DataFlow::Node src, DataFlow::Node sink, TaintFlowConf conf | conf.hasFlow(src, sink) |
35+
exists(DataFlow::Node src, DataFlow::Node sink, TaintFlowConf conf | conf.hasFlow(src, sink) and not any(ValueFlowConf c).hasFlow(src, sink) |
3636
sink.getLocation() = location and
3737
element = sink.toString() and
3838
value = ""

0 commit comments

Comments
 (0)