From 3ab629d17da8886ddcfc07fcf819de473e4ae1cc Mon Sep 17 00:00:00 2001 From: OCram85 Date: Thu, 28 Mar 2019 10:45:15 +0100 Subject: [PATCH] add cert store tests for New-CredentialStoreItem --- .../Item/03_New-CredentialStoreItem.Tests.ps1 | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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' + } + } }