Skip to content

Commit 9efb681

Browse files
committed
Java: Add a copy of all testutilities.
1 parent 7156f18 commit 9efb681

File tree

5 files changed

+99
-1
lines changed

5 files changed

+99
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Inline expectation tests for Java.
3+
* See `shared/util/codeql/util/test/InlineExpectationsTest.qll`
4+
*/
5+
6+
private import codeql.util.test.InlineExpectationsTest
7+
private import internal.InlineExpectationsTestImpl
8+
import Make<Impl>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Inline flow tests for Java.
3+
* See `shared/util/codeql/dataflow/test/InlineFlowTest.qll`
4+
*/
5+
6+
import java
7+
import semmle.code.java.dataflow.DataFlow
8+
private import codeql.dataflow.test.InlineFlowTest
9+
private import semmle.code.java.dataflow.internal.DataFlowImplSpecific
10+
private import semmle.code.java.dataflow.internal.TaintTrackingImplSpecific
11+
private import semmle.code.java.dataflow.ExternalFlow as ExternalFlow
12+
private import internal.InlineExpectationsTestImpl
13+
14+
private module FlowTestImpl implements InputSig<Location, JavaDataFlow> {
15+
predicate defaultSource(DataFlow::Node source) {
16+
source.asExpr().(MethodCall).getMethod().getName() = ["source", "taint"]
17+
}
18+
19+
predicate defaultSink(DataFlow::Node sink) {
20+
exists(MethodCall ma | ma.getMethod().hasName("sink") | sink.asExpr() = ma.getAnArgument())
21+
}
22+
23+
private string getSourceArgString(DataFlow::Node src) {
24+
defaultSource(src) and
25+
src.asExpr().(MethodCall).getAnArgument().(StringLiteral).getValue() = result
26+
}
27+
28+
string getArgString(DataFlow::Node src, DataFlow::Node sink) {
29+
(if exists(getSourceArgString(src)) then result = getSourceArgString(src) else result = "") and
30+
exists(sink)
31+
}
32+
33+
predicate interpretModelForTest = ExternalFlow::interpretModelForTest/2;
34+
}
35+
36+
import InlineFlowTestMake<Location, JavaDataFlow, JavaTaintTracking, Impl, FlowTestImpl>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
private import java as J
2+
private import codeql.mad.test.InlineMadTest
3+
4+
private module InlineMadTestLang implements InlineMadTestLangSig {
5+
class Callable = J::Callable;
6+
7+
string getComment(Callable c) {
8+
exists(J::Javadoc doc |
9+
hasJavadoc(c, doc) and
10+
isNormalComment(doc) and
11+
result = doc.getChild(0).toString()
12+
)
13+
}
14+
}
15+
16+
import InlineMadTestImpl<InlineMadTestLang>

java/test/TestUtilities/PrettyPrintModels.ql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
*/
44

55
import semmle.code.java.dataflow.ExternalFlow
6-
import codeql.dataflow.test.ProvenancePathGraph
76
import codeql.dataflow.test.ProvenancePathGraph::TestPostProcessing::TranslateProvenanceResults<interpretModelForTest/2>
7+
8+
from string relation, int row, int column, string data
9+
where results(relation, row, column, data)
10+
select relation, row, column, data
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
private import java as J
2+
private import codeql.util.test.InlineExpectationsTest
3+
4+
module Impl implements InlineExpectationsTestSig {
5+
/**
6+
* A class representing line comments in Java, which is simply Javadoc restricted
7+
* to EOL comments, with an extra accessor used by the InlineExpectations core code
8+
*/
9+
abstract class ExpectationComment extends J::Top {
10+
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
11+
abstract string getContents();
12+
}
13+
14+
private class JavadocExpectationComment extends J::Javadoc, ExpectationComment {
15+
JavadocExpectationComment() { isEolComment(this) }
16+
17+
override string getContents() { result = this.getChild(0).toString() }
18+
}
19+
20+
private class KtExpectationComment extends J::KtComment, ExpectationComment {
21+
KtExpectationComment() { this.isEolComment() }
22+
23+
override string getContents() { result = this.getText().suffix(2).trim() }
24+
}
25+
26+
private class XmlExpectationComment extends ExpectationComment instanceof J::XmlComment {
27+
override string getContents() { result = super.getText().trim() }
28+
29+
override Location getLocation() { result = J::XmlComment.super.getLocation() }
30+
31+
override string toString() { result = J::XmlComment.super.toString() }
32+
}
33+
34+
class Location = J::Location;
35+
}

0 commit comments

Comments
 (0)