Skip to content

Commit 5103d34

Browse files
committed
PS: Add tests.
1 parent 46ead0d commit 5103d34

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

powershell/ql/lib/semmle/code/powershell/controlflow/CfgNodes.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ abstract private class NonExprChildMapping extends ChildMapping {
128128
abstract private class AbstractCallCfgNode extends AstCfgNode {
129129
override string getAPrimaryQlClass() { result = "CfgCall" }
130130

131+
final predicate hasName(string name) { this.getName() = name }
132+
131133
abstract string getName();
132134

133135
ExprCfgNode getQualifier() { none() }
@@ -231,7 +233,7 @@ module ExprNodes {
231233
final override ExprCfgNode getCommand() { none() }
232234
}
233235

234-
/** A control-flow node that wraps an `ConstructorCall` expression. */
236+
/** A control-flow node that wraps an `ConstructorCall` expression. */
235237
class ConstructorCallCfgNode extends InvokeMemberCfgNode {
236238
ConstructorCallCfgNode() { super.getExpr() instanceof ConstructorCall }
237239

powershell/ql/lib/semmle/code/powershell/dataflow/internal/DataFlowDispatch.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private predicate qualifiedCall(CfgNodes::CallCfgNode call, Node receiver, strin
155155
call.getName() = method
156156
}
157157

158-
private Node trackInstance(Type t, boolean exact) {
158+
Node trackInstance(Type t, boolean exact) {
159159
result =
160160
CallGraphConstruction::Make<TrackInstanceInput>::track(TrackInstanceInput::MkState(t, exact))
161161
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
testFailures
2+
failures
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class MyClass {
2+
[string] $field
3+
MyClass($val) {
4+
$this.field = $val
5+
}
6+
}
7+
8+
$myClass = [MyClass]::new("hello")
9+
10+
Sink $myClass # $ MISSING: type=MyClass
11+
12+
13+
$withNamedArg = New-Object -TypeName PSObject
14+
15+
Sink $withNamedArg # $ MISSING: type=PSObject
16+
17+
$withPositionalArg = New-Object PSObject
18+
19+
Sink $withPositionalArg # $ MISSING: type=PSObject
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import powershell
2+
import semmle.code.powershell.dataflow.internal.DataFlowDispatch
3+
import semmle.code.powershell.dataflow.internal.DataFlowPublic
4+
import semmle.code.powershell.dataflow.internal.DataFlowPrivate
5+
import TestUtilities.InlineExpectationsTest
6+
7+
module TypeTrackingTest implements TestSig {
8+
string getARelevantTag() { result = "type" }
9+
10+
predicate hasActualResult(Location location, string element, string tag, string value) {
11+
exists(Node n, DataFlowCall c, Type t |
12+
location = n.getLocation() and
13+
element = n.toString() and
14+
tag = "type" and
15+
value = t.getName() and
16+
n = trackInstance(t, _) and
17+
isArgumentNode(n, c, _) and
18+
c.asCall().hasName("Sink")
19+
)
20+
}
21+
}
22+
23+
import MakeTest<TypeTrackingTest>

0 commit comments

Comments
 (0)