Skip to content
This repository was archived by the owner on Jun 22, 2026. It is now read-only.

Commit 8f47b9c

Browse files
jshigetomiandyleejordanGitOpsJustin Chung
authored
Fix PSAvoidUsingConvertToSecureStringWithPlainText in tests (#115)
* Inventory drift * [SECURITY] Bump dotnet-sdk from 8.0.300 to 8.0.318 * Update EsMetadata schema versions to 1.0.0 * Add suppression * Fix PSAvoidUsingConvertToSecureStringWithPlainText in tests --------- Co-authored-by: Andy Jordan <2226434+andyleejordan@users.noreply.github.com> Co-authored-by: GitOps <gitops@microsoft.com> Co-authored-by: Dependabot <Dependabot> Co-authored-by: MerlinBot <MerlinBot> Co-authored-by: Justin Chung <chungjustin@microsoft.com>
1 parent 234be8a commit 8f47b9c

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

es-metadata.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
schemaVersion: 1.0.0
2+
providers:
3+
- provider: InventoryAsCode
4+
version: 1.0.0
5+
metadata:
6+
isProduction: true
7+
accountableOwners:
8+
service: cef1de07-99d6-45df-b907-77d0066032ec
9+
routing:
10+
defaultAreaPath:
11+
org: msazure
12+
path: One\MGMT\Compute\Powershell\Powershell

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "8.0.300",
3+
"version": "8.0.318",
44
"rollForward": "latestFeature",
55
"allowPrerelease": false
66
}

test/Microsoft.PowerShell.SecretStore.Tests.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Describe "Test Microsoft.PowerShell.SecretStore module" {
123123
}
124124

125125
It "Verifies Unlock-SecretStore throws expected error when in no password mode" {
126-
$token = ConvertTo-SecureString -String "None" -AsPlainText -Force
126+
$token = [System.Net.NetworkCredential]::new('', 'None').SecurePassword
127127
{ Unlock-SecretStore -Password $token } | Should -Throw -ErrorId 'InvalidOperation,Microsoft.PowerShell.SecretStore.UnlockSecretStoreCommand'
128128
}
129129
}
@@ -329,7 +329,7 @@ Describe "Test Microsoft.PowerShell.SecretStore module" {
329329
BeforeAll {
330330
$secretName = [System.IO.Path]::GetFileNameWithoutExtension([System.IO.Path]::GetRandomFileName())
331331
$randomSecret = [System.IO.Path]::GetRandomFileName()
332-
$secureStringToWrite = ConvertTo-SecureString -String $randomSecret -AsPlainText -Force
332+
$secureStringToWrite = [System.Net.NetworkCredential]::new('', $randomSecret).SecurePassword
333333
$errorMsg = ""
334334
}
335335

@@ -395,7 +395,7 @@ Describe "Test Microsoft.PowerShell.SecretStore module" {
395395
}
396396

397397
It "Verifies PSCredential type write to SecretStore" {
398-
$cred = [pscredential]::new('UserL', (ConvertTo-SecureString $randomSecret -AsPlainText -Force))
398+
$cred = [pscredential]::new('UserL', ([System.Net.NetworkCredential]::new('', $randomSecret).SecurePassword))
399399
$success = [Microsoft.PowerShell.SecretStore.LocalSecretStore]::GetInstance().WriteObject(
400400
$secretName,
401401
$cred,
@@ -462,8 +462,8 @@ Describe "Test Microsoft.PowerShell.SecretStore module" {
462462
$ht = @{
463463
Blob = ([byte[]] @(1,2))
464464
Str = "TestHashtableString"
465-
SecureString = (ConvertTo-SecureString $randomSecretA -AsPlainText -Force)
466-
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)))
467467
}
468468

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

0 commit comments

Comments
 (0)