mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Kotlin: Copy TestUtilities into the kotlin testsuites
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Inline expectation tests for Java.
|
||||
* See `shared/util/codeql/util/test/InlineExpectationsTest.qll`
|
||||
*/
|
||||
|
||||
private import codeql.util.test.InlineExpectationsTest
|
||||
private import internal.InlineExpectationsTestImpl
|
||||
import Make<Impl>
|
||||
33
java/ql/test-kotlin1/TestUtilities/InlineFlowTest.qll
Normal file
33
java/ql/test-kotlin1/TestUtilities/InlineFlowTest.qll
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Inline flow tests for Java.
|
||||
* See `shared/util/codeql/dataflow/test/InlineFlowTest.qll`
|
||||
*/
|
||||
|
||||
import java
|
||||
import semmle.code.java.dataflow.DataFlow
|
||||
private import codeql.dataflow.test.InlineFlowTest
|
||||
private import semmle.code.java.dataflow.internal.DataFlowImplSpecific
|
||||
private import semmle.code.java.dataflow.internal.TaintTrackingImplSpecific
|
||||
private import internal.InlineExpectationsTestImpl
|
||||
|
||||
private module FlowTestImpl implements InputSig<JavaDataFlow> {
|
||||
predicate defaultSource(DataFlow::Node source) {
|
||||
source.asExpr().(MethodCall).getMethod().getName() = ["source", "taint"]
|
||||
}
|
||||
|
||||
predicate defaultSink(DataFlow::Node sink) {
|
||||
exists(MethodCall ma | ma.getMethod().hasName("sink") | sink.asExpr() = ma.getAnArgument())
|
||||
}
|
||||
|
||||
private string getSourceArgString(DataFlow::Node src) {
|
||||
defaultSource(src) and
|
||||
src.asExpr().(MethodCall).getAnArgument().(StringLiteral).getValue() = result
|
||||
}
|
||||
|
||||
string getArgString(DataFlow::Node src, DataFlow::Node sink) {
|
||||
(if exists(getSourceArgString(src)) then result = getSourceArgString(src) else result = "") and
|
||||
exists(sink)
|
||||
}
|
||||
}
|
||||
|
||||
import InlineFlowTestMake<JavaDataFlow, JavaTaintTracking, Impl, FlowTestImpl>
|
||||
@@ -0,0 +1,35 @@
|
||||
private import java as J
|
||||
private import codeql.util.test.InlineExpectationsTest
|
||||
|
||||
module Impl implements InlineExpectationsTestSig {
|
||||
/**
|
||||
* A class representing line comments in Java, which is simply Javadoc restricted
|
||||
* to EOL comments, with an extra accessor used by the InlineExpectations core code
|
||||
*/
|
||||
abstract class ExpectationComment extends J::Top {
|
||||
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
|
||||
abstract string getContents();
|
||||
}
|
||||
|
||||
private class JavadocExpectationComment extends J::Javadoc, ExpectationComment {
|
||||
JavadocExpectationComment() { isEolComment(this) }
|
||||
|
||||
override string getContents() { result = this.getChild(0).toString() }
|
||||
}
|
||||
|
||||
private class KtExpectationComment extends J::KtComment, ExpectationComment {
|
||||
KtExpectationComment() { this.isEolComment() }
|
||||
|
||||
override string getContents() { result = this.getText().suffix(2).trim() }
|
||||
}
|
||||
|
||||
private class XmlExpectationComment extends ExpectationComment instanceof J::XmlComment {
|
||||
override string getContents() { result = super.getText().trim() }
|
||||
|
||||
override Location getLocation() { result = J::XmlComment.super.getLocation() }
|
||||
|
||||
override string toString() { result = J::XmlComment.super.toString() }
|
||||
}
|
||||
|
||||
class Location = J::Location;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Inline expectation tests for Java.
|
||||
* See `shared/util/codeql/util/test/InlineExpectationsTest.qll`
|
||||
*/
|
||||
|
||||
private import codeql.util.test.InlineExpectationsTest
|
||||
private import internal.InlineExpectationsTestImpl
|
||||
import Make<Impl>
|
||||
33
java/ql/test-kotlin2/TestUtilities/InlineFlowTest.qll
Normal file
33
java/ql/test-kotlin2/TestUtilities/InlineFlowTest.qll
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Inline flow tests for Java.
|
||||
* See `shared/util/codeql/dataflow/test/InlineFlowTest.qll`
|
||||
*/
|
||||
|
||||
import java
|
||||
import semmle.code.java.dataflow.DataFlow
|
||||
private import codeql.dataflow.test.InlineFlowTest
|
||||
private import semmle.code.java.dataflow.internal.DataFlowImplSpecific
|
||||
private import semmle.code.java.dataflow.internal.TaintTrackingImplSpecific
|
||||
private import internal.InlineExpectationsTestImpl
|
||||
|
||||
private module FlowTestImpl implements InputSig<JavaDataFlow> {
|
||||
predicate defaultSource(DataFlow::Node source) {
|
||||
source.asExpr().(MethodCall).getMethod().getName() = ["source", "taint"]
|
||||
}
|
||||
|
||||
predicate defaultSink(DataFlow::Node sink) {
|
||||
exists(MethodCall ma | ma.getMethod().hasName("sink") | sink.asExpr() = ma.getAnArgument())
|
||||
}
|
||||
|
||||
private string getSourceArgString(DataFlow::Node src) {
|
||||
defaultSource(src) and
|
||||
src.asExpr().(MethodCall).getAnArgument().(StringLiteral).getValue() = result
|
||||
}
|
||||
|
||||
string getArgString(DataFlow::Node src, DataFlow::Node sink) {
|
||||
(if exists(getSourceArgString(src)) then result = getSourceArgString(src) else result = "") and
|
||||
exists(sink)
|
||||
}
|
||||
}
|
||||
|
||||
import InlineFlowTestMake<JavaDataFlow, JavaTaintTracking, Impl, FlowTestImpl>
|
||||
@@ -0,0 +1,35 @@
|
||||
private import java as J
|
||||
private import codeql.util.test.InlineExpectationsTest
|
||||
|
||||
module Impl implements InlineExpectationsTestSig {
|
||||
/**
|
||||
* A class representing line comments in Java, which is simply Javadoc restricted
|
||||
* to EOL comments, with an extra accessor used by the InlineExpectations core code
|
||||
*/
|
||||
abstract class ExpectationComment extends J::Top {
|
||||
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
|
||||
abstract string getContents();
|
||||
}
|
||||
|
||||
private class JavadocExpectationComment extends J::Javadoc, ExpectationComment {
|
||||
JavadocExpectationComment() { isEolComment(this) }
|
||||
|
||||
override string getContents() { result = this.getChild(0).toString() }
|
||||
}
|
||||
|
||||
private class KtExpectationComment extends J::KtComment, ExpectationComment {
|
||||
KtExpectationComment() { this.isEolComment() }
|
||||
|
||||
override string getContents() { result = this.getText().suffix(2).trim() }
|
||||
}
|
||||
|
||||
private class XmlExpectationComment extends ExpectationComment instanceof J::XmlComment {
|
||||
override string getContents() { result = super.getText().trim() }
|
||||
|
||||
override Location getLocation() { result = J::XmlComment.super.getLocation() }
|
||||
|
||||
override string toString() { result = J::XmlComment.super.toString() }
|
||||
}
|
||||
|
||||
class Location = J::Location;
|
||||
}
|
||||
Reference in New Issue
Block a user