mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Based on standard practices, we need to have a copyright and license notice at the top of each source file. Removed existing copyrights and updated/added copyright notices for .h, .cpp, .cs, .ps1, and .psm1 files. Updated module manifests for consistency to have Author = "PowerShell" and Company = "Microsoft Corporation". Removed multiple line breaks. Separate PR coming to update contribution document for new source files: #6140 Manually reviewed each change. Fix #6073
49 lines
1.8 KiB
PowerShell
49 lines
1.8 KiB
PowerShell
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
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 {
|
|
$global: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
|
|
}
|
|
}
|