Skip to content

Commit e702680

Browse files
authored
Merge pull request #351 from microsoft/powershell-inline-expectationstests
Adding InlineExpectationsTests to Powershell
2 parents b6567f9 + d39e54a commit e702680

40 files changed

Lines changed: 217 additions & 157 deletions
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @kind test-postprocess
3+
*/
4+
5+
private import powershell
6+
private import codeql.util.test.InlineExpectationsTest as T
7+
private import internal.InlineExpectationsTestImpl
8+
import T::TestPostProcessing
9+
import T::TestPostProcessing::Make<Impl, Input>
10+
11+
private module Input implements T::TestPostProcessing::InputSig<Impl> {
12+
string getRelativeUrl(Location location) {
13+
exists(File f, int startline, int startcolumn, int endline, int endcolumn |
14+
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
15+
f = location.getFile()
16+
|
17+
result =
18+
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
19+
)
20+
}
21+
}
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+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
experimental/ConvertToSecureStringAsPlainText.ql
1+
query: experimental/ConvertToSecureStringAsPlainText.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
$UserInput = Read-Host 'Please enter your secure code'
2-
$EncryptedInput = ConvertTo-SecureString -String $UserInput -AsPlainText -Force
2+
$EncryptedInput = ConvertTo-SecureString -String $UserInput -AsPlainText -Force # $ Alert
33

44
$SecureUserInput = Read-Host 'Please enter your secure code' -AsSecureString
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
experimental/HardcodedComputerName.ql
1+
query: experimental/HardcodedComputerName.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql

powershell/ql/test/query-tests/security/HardcodedComputerName/test.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Function Invoke-MyRemoteCommand ()
22
{
3-
Invoke-Command -Port 343 -ComputerName hardcoderemotehostname
3+
Invoke-Command -Port 343 -ComputerName hardcoderemotehostname # $ Alert
44
}
55

66
Function Invoke-MyCommand ($ComputerName)
@@ -10,7 +10,7 @@ Function Invoke-MyCommand ($ComputerName)
1010

1111
Function Invoke-MyLocalCommand ()
1212
{
13-
Invoke-Command -Port 343 -ComputerName hardcodelocalhostname
13+
Invoke-Command -Port 343 -ComputerName hardcodelocalhostname # $ Alert
1414
}
1515

1616
Function Invoke-MyLocalCommand ()
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
experimental/UseOfReservedCmdletChar.ql
1+
query: experimental/UseOfReservedCmdletChar.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
function MyFunction[1]
2-
{...}
2+
{...} # $ Alert Alert
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
experimental/UsernameOrPasswordParameter.ql
1+
query: experimental/UsernameOrPasswordParameter.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql

0 commit comments

Comments
 (0)