PowerShell / SecretManagement

PowerShell module to consistent usage of secrets through different extension vaults
MIT License
317 stars 46 forks source link

[1.1.0-preview] Warning Stream does not flow back from the command #151

Closed JustinGrote closed 3 years ago

JustinGrote commented 3 years ago

In SecretManagement.KeePass, this test fails:

        It 'Should not create a duplicate entry with Set-Secret' {
            $secretPassword = 'PesterPassword'
            $secret = [PSCredential]::new('PesterUser',($secretPassword | ConvertTo-SecureString -AsPlainText -Force))
            Set-Secret -Name $secretName -Vault $VaultName -Secret $secret
            [String]$DuplicateSecretWarning = Set-Secret -Name $secretName -Vault $VaultName -Secret $secret -WarningAction Stop *>&1
            [String]$DuplicateSecretWarning | Should -BeLike "*A secret with the title $secretName already exists*"
        }

because previously with the same-runspace nested module I could capture the warning stream and test it. Now it appears the warning stream gets emitted separately and thus is uncapturable not just by my test but by a normal user, so they cannot suppress or otherwise redirect warning streams as they would expect.

SecretManagement should capture the streams from the runspace and emit them as part of the original command call so they can be acted upon appropriatley.

PaulHigin commented 3 years ago

Warning, Verbose, Debug data streams are currently written directly to the host, so they are currently not redirectable. This is to allow extension vaults to directly prompt the user (via cmdlet/host calls). I don't think there is any way to stream back to the calling cmdlet without causing duplicate messages to be displayed. But I'll look into it.

PaulHigin commented 3 years ago

Ok, I think I have a fix for this and will include it in the next release.

PaulHigin commented 3 years ago

Fixed in preview2.

JustinGrote commented 2 years ago

@PaulHigin sorry for the late closing of the circle on this, yes it worked for me except for 1 test but I think I can work around that. Thanks!