-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMeasure-SecureStringWithKey.ps1
More file actions
37 lines (35 loc) · 1.83 KB
/
Copy pathMeasure-SecureStringWithKey.ps1
File metadata and controls
37 lines (35 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Describe 'Measure-TODOComment' {
BeforeAll {
if ( -not $env:BHPSModuleManifest ) {
Set-BuildEnvironment -Path "$PSScriptRoot\.." -Force
}
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
$outputDir = Join-Path -Path $env:BHProjectPath -ChildPath 'Output'
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName
$outputModVerDir = Join-Path -Path $outputModDir -ChildPath $manifest.ModuleVersion
$outputModVerManifest = Join-Path -Path $outputModVerDir -ChildPath "$($env:BHProjectName).psd1"
# Get module commands
# Remove all versions of the module from the session. Pester can't handle multiple versions.
Get-Module $env:BHProjectName | Remove-Module -Force -ErrorAction Ignore
Import-Module -Name $outputModVerManifest -Verbose:$false -ErrorAction Stop
}
It 'Detects missing key' {
$fakeScript = @'
$secureString = 'Hello, World!' | ConvertTo-SecureString -AsPlainText -Force
ConvertFrom-SecureString -SecureString $secureString
'@
$ast = [System.Management.Automation.Language.Parser]::ParseInput($fakeScript, [ref]$null, [ref]$null)
$result = Measure-TODOComment -ScriptBlockAst $ast
$result.Count | Should -BeExactly 1
$result[0].Message | Should -Be 'ConvertFrom-SecureString should be used with a Key.'
}
It 'does not detect correct usage' {
$fakeScript = @'
$secureString = 'Hello, World!' | ConvertTo-SecureString -AsPlainText -Force
ConvertFrom-SecureString -SecureString $secureString -Key (1..16)
'@
$ast = [System.Management.Automation.Language.Parser]::ParseInput($fakeScript, [ref]$null, [ref]$null)
$result = Measure-TODOComment -ScriptBlockAst $ast
$results | Should -BeNullOrEmpty
}
}