Skip to content

Commit ab91071

Browse files
author
Justin Chung
committed
Fix PSAvoidUsingConvertToSecureStringWithPlainText in tests
1 parent 4057afd commit ab91071

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

test/Microsoft.PowerShell.SecretStore.Tests.ps1

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'Tests create SecureStrings from known test data')]
5-
param()
6-
74
Describe "Test Microsoft.PowerShell.SecretStore module" {
85
BeforeAll {
96
Import-Module -Force -Name Microsoft.PowerShell.SecretManagement
@@ -126,7 +123,7 @@ Describe "Test Microsoft.PowerShell.SecretStore module" {
126123
}
127124

128125
It "Verifies Unlock-SecretStore throws expected error when in no password mode" {
129-
$token = ConvertTo-SecureString -String "None" -AsPlainText -Force
126+
$token = [System.Net.NetworkCredential]::new('', 'None').SecurePassword
130127
{ Unlock-SecretStore -Password $token } | Should -Throw -ErrorId 'InvalidOperation,Microsoft.PowerShell.SecretStore.UnlockSecretStoreCommand'
131128
}
132129
}
@@ -332,7 +329,7 @@ Describe "Test Microsoft.PowerShell.SecretStore module" {
332329
BeforeAll {
333330
$secretName = [System.IO.Path]::GetFileNameWithoutExtension([System.IO.Path]::GetRandomFileName())
334331
$randomSecret = [System.IO.Path]::GetRandomFileName()
335-
$secureStringToWrite = ConvertTo-SecureString -String $randomSecret -AsPlainText -Force
332+
$secureStringToWrite = [System.Net.NetworkCredential]::new('', $randomSecret).SecurePassword
336333
$errorMsg = ""
337334
}
338335

@@ -398,7 +395,7 @@ Describe "Test Microsoft.PowerShell.SecretStore module" {
398395
}
399396

400397
It "Verifies PSCredential type write to SecretStore" {
401-
$cred = [pscredential]::new('UserL', (ConvertTo-SecureString $randomSecret -AsPlainText -Force))
398+
$cred = [pscredential]::new('UserL', ([System.Net.NetworkCredential]::new('', $randomSecret).SecurePassword))
402399
$success = [Microsoft.PowerShell.SecretStore.LocalSecretStore]::GetInstance().WriteObject(
403400
$secretName,
404401
$cred,
@@ -465,8 +462,8 @@ Describe "Test Microsoft.PowerShell.SecretStore module" {
465462
$ht = @{
466463
Blob = ([byte[]] @(1,2))
467464
Str = "TestHashtableString"
468-
SecureString = (ConvertTo-SecureString $randomSecretA -AsPlainText -Force)
469-
Cred = ([pscredential]::New("UserA", (ConvertTo-SecureString $randomSecretB -AsPlainText -Force)))
465+
SecureString = ([System.Net.NetworkCredential]::new('', $randomSecretA).SecurePassword)
466+
Cred = ([pscredential]::New("UserA", ([System.Net.NetworkCredential]::new('', $randomSecretB).SecurePassword)))
470467
}
471468

472469
$success = [Microsoft.PowerShell.SecretStore.LocalSecretStore]::GetInstance().WriteObject(

0 commit comments

Comments
 (0)