diff --git a/tests/Item/03_New-CredentialStoreItem.Tests.ps1 b/tests/Item/03_New-CredentialStoreItem.Tests.ps1 index 8c1dad6..d02883f 100644 --- a/tests/Item/03_New-CredentialStoreItem.Tests.ps1 +++ b/tests/Item/03_New-CredentialStoreItem.Tests.ps1 @@ -81,5 +81,25 @@ Describe "New-CredentialStoreItem" { (Get-CredentialStoreItem -RemoteHost 'PipeHost').UserName | Should -Be 'pipeUser' } } + Context "Testing items with certficiate store" { + It "Create item in new store with cert store link" { + { New-CredentialStore -UseCertStore -Force } | Should -Not -Throw + $Path = Get-DefaultCredentialStorePath + $StoreHome = Split-Path -Path $Path -Parent + $CertFile = Join-Path -Path $StoreHome -ChildPath 'PSCredentialStore.pfx' + certutil.exe -Importpfx -user MY $CertFile "NoProtect, NoRoot" + function global:Get-Credential ([string]$Message) { + $UserName = 'testuser' + $Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force + return [PSCredential]::new($UserName, $Password) + } + New-CredentialStoreItem -RemoteHost 'foobarcerts' + Remove-Item -Path 'Function:\Get-Credential' + + $writtenItem = Get-CredentialStoreItem -Path $tmpCS -Shared -RemoteHost 'foobarcerts' + $writtenItem.UserName | Should -Be "testuser" + $writtenItem.GetNetworkCredential().Password | Should -Be 'mypasswd' + } + } }