Emit warning if ConvertTo-Json exceeds -Depth value (#13692)

This commit is contained in:
Steve Lee
2020-09-28 21:22:40 +05:00
committed by GitHub
parent 36ba1092a8
commit 9bf512ff5d
4 changed files with 29 additions and 3 deletions
@@ -1,5 +1,9 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
param()
Describe "SecureString conversion tests" -Tags "CI" {
BeforeAll {
$string = "ABCD"
@@ -24,9 +28,8 @@ Describe "SecureString conversion tests" -Tags "CI" {
}
It "can convert back from a secure string" {
$secret = "abcd"
$ss1 = ConvertTo-SecureString -AsPlainText -Force $secret
$ss1 = ConvertTo-SecureString -AsPlainText -Force $string
$ss2 = ConvertFrom-SecureString $ss1 | ConvertTo-SecureString
$ss2 | ConvertFrom-SecureString -AsPlainText | Should -Be $secret
$ss2 | ConvertFrom-SecureString -AsPlainText | Should -Be $string
}
}
@@ -1463,4 +1463,11 @@ Describe "Json Bug fixes" -Tags "Feature" {
$result = "[1,","2,","3]" | ConvertFrom-Json
$result.Count | Should -Be 3
}
It 'ConvertTo-Json will output warning if depth is exceeded.' {
$a = @{ a = @{ b = @{ c = @{ d = 1 } } } }
$json = $a | ConvertTo-Json -Depth 2 -WarningVariable warningMessage -WarningAction SilentlyContinue
$json | Should -Not -BeNullOrEmpty
$warningMessage | Should -Not -BeNullOrEmpty
}
}