Tests/Unit/Private/Protect-SIALogValue.Tests.ps1
|
BeforeAll { $moduleRoot = (Resolve-Path (Join-Path $PSScriptRoot '../../..')).Path Import-Module (Join-Path $moduleRoot 'psSIA.psd1') -Force } Describe 'Protect-SIALogValue' { It 'redacts a bearer token' { InModuleScope psSIA { $result = Protect-SIALogValue -InputObject 'Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.abc.def' $result | Should -Not -Match 'eyJhbGciOiJIUzI1NiJ9' $result | Should -Match '\*\*\*REDACTED\*\*\*' } } It 'redacts client_secret in a JSON body' { InModuleScope psSIA { $json = '{"client_id":"svc-account","client_secret":"sup3rSecret!"}' $result = Protect-SIALogValue -InputObject $json $result | Should -Not -Match 'sup3rSecret!' $result | Should -Match 'svc-account' } } It 'redacts password in a form-encoded string' { InModuleScope psSIA { $form = 'grant_type=client_credentials&client_id=svc&client_secret=hunter2' $result = Protect-SIALogValue -InputObject $form $result | Should -Not -Match 'hunter2' } } It 'leaves non-sensitive text unchanged' { InModuleScope psSIA { $text = 'GET https://contoso.dpa.cyberark.cloud/api/connectors' Protect-SIALogValue -InputObject $text | Should -Be $text } } It 'accepts an empty string' { InModuleScope psSIA { Protect-SIALogValue -InputObject '' | Should -Be '' } } } |