forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecureString.Tests.ps1
More file actions
46 lines (42 loc) · 1.72 KB
/
Copy pathSecureString.Tests.ps1
File metadata and controls
46 lines (42 loc) · 1.72 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
38
39
40
41
42
43
44
45
46
Describe "SecureString conversion tests" -Tags "CI" {
BeforeAll {
$string = "ABCD"
$secureString = [System.Security.SecureString]::New()
$string.ToCharArray() | foreach-object { $securestring.AppendChar($_) }
$defaultParamValues = $PSdefaultParameterValues.Clone()
$PSdefaultParameterValues = @{}
if ( ! $IsWindows ) { $PSdefaultParameterValues["it:pending"] = $true }
}
AfterAll {
$PSdefaultParameterValues = $defaultParamValues
}
It "using null arguments to ConvertFrom-SecureString produces an exception" {
try {
ConvertFrom-SecureString -secureString $null -key $null
throw "No Exception!"
}
catch {
$_.FullyQualifiedErrorId | should be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertFromSecureStringCommand"
}
}
It "using a bad key produces an exception" {
try {
$badkey = [byte[]]@(1,2)
ConvertFrom-SecureString -securestring $secureString -key $badkey
throw "Command did not throw exception"
}
catch {
$_.FullyQualifiedErrorId | should be "Argument,Microsoft.PowerShell.Commands.ConvertFromSecureStringCommand"
}
}
It "Can convert to a secure string" {
$ss = ConvertTo-SecureString -AsPlainText -Force abcd
$ss | Should BeOfType SecureString
}
It "can convert back from a secure string" {
$secret = "abcd"
$ss1 = ConvertTo-SecureString -AsPlainText -Force $secret
$ss2 = convertfrom-securestring $ss1 | convertto-securestring
[pscredential]::New("user",$ss2).GetNetworkCredential().Password | should be $secret
}
}