adds aditional tests for New-CredentialStoreItem

This commit is contained in:
OCram85 2018-03-14 13:13:28 +01:00
parent c46e3f5c53
commit b5aff1f45b

View File

@ -72,4 +72,30 @@ Describe "New-CredentialStoreItem" {
($writtenItem.UserName -eq $UserName) -and ($writtenItem.Password.Length -gt 0) | Should -Be $true
}
}
Context "Test optional parameter lookup" {
Mock Get-Credential {
return [PSCustomObject]@{
UserName = 'myUser'
Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force
}
}
It "Test missing Credential" {
$tmpCS = 'C:\CredentialStore.json'
New-CredentialStoreItem -Path $tmpCs -Shared -RemoteHost 'foobar3'
$writtenItem = Get-CredentialStoreItem -Path $tmpCS -Shared -RemoteHost 'foobar3'
$writtenItem.UserName | Should -Be "myUser"
}
}
Context "General Exception handling" {
Mock Test-CredentialStore {return $false}
Mock Get-Credential {
return [PSCustomObject]@{
UserName = 'myUser'
Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force
}
}
It "Missing CredentialStore should throw" {
New-CredentialStoreItem -Path 'C:\missingStore.json' -RemoteHost 'notrelevant' | Should -Throw "Could not add anything"
}
}
}