Skip to content

Commit 7fc8219

Browse files
committed
PS: Add inline expectations test library.
1 parent ccbfe0f commit 7fc8219

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
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 Powershell.
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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Inline flow tests for Powershell.
3+
* See `shared/util/codeql/dataflow/test/InlineFlowTest.qll`
4+
*/
5+
6+
import powershell
7+
private import codeql.dataflow.test.InlineFlowTest
8+
private import semmle.code.powershell.dataflow.internal.DataFlowImplSpecific
9+
private import semmle.code.powershell.dataflow.internal.TaintTrackingImplSpecific
10+
private import internal.InlineExpectationsTestImpl
11+
12+
private module FlowTestImpl implements InputSig<Location, PowershellDataFlow> {
13+
import TestUtilities.InlineFlowTestUtil
14+
15+
bindingset[src, sink]
16+
string getArgString(DataFlow::Node src, DataFlow::Node sink) {
17+
(if exists(getSourceArgString(src)) then result = getSourceArgString(src) else result = "") and
18+
exists(sink)
19+
}
20+
21+
predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) { none() }
22+
}
23+
24+
import InlineFlowTestMake<Location, PowershellDataFlow, PowershellTaintTracking, Impl, FlowTestImpl>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Defines the default source and sink recognition for `InlineFlowTest.qll`.
3+
*/
4+
5+
import powershell
6+
import semmle.code.powershell.dataflow.DataFlow
7+
8+
predicate defaultSource(DataFlow::Node src) {
9+
src.asStmt().getStmt().(Cmd).getCommandName() = ["Source", "Taint"]
10+
}
11+
12+
predicate defaultSink(DataFlow::Node sink) {
13+
exists(Cmd cmd | cmd.getCommandName() = "Sink" | sink.asExpr().getExpr() = cmd.getAnArgument())
14+
}
15+
16+
string getSourceArgString(DataFlow::Node src) {
17+
defaultSource(src) and
18+
src.asStmt().getStmt().(Cmd).getAnArgument().(StringConstExpr).getValue().getValue() = result
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
private import powershell as P
2+
private import codeql.util.test.InlineExpectationsTest
3+
4+
module Impl implements InlineExpectationsTestSig {
5+
/**
6+
* A class representing line comments in Powershell.
7+
*/
8+
class ExpectationComment extends P::SingleLineComment {
9+
string getContents() { result = this.getCommentContents().getValue().suffix(1) }
10+
}
11+
12+
class Location = P::Location;
13+
}

0 commit comments

Comments
 (0)