PSCredentialStore/src/Store/Get-CredentialStore.Tests.ps1

46 lines
1.7 KiB
PowerShell
Raw Normal View History

BeforeAll {
$ManifestFile = (Get-Item -Path "./src/*.psd1").FullName
Import-Module $ManifestFile -Force
$PrivateFunctions = (Get-ChildItem -Path "./src/Private/*.ps1" | Where-Object {
$_.BaseName -notmatch '.Tests'
}
).FullName
foreach ( $func in $PrivateFunctions) {
. $func
}
}
Describe "Get-CredentialStore" {
Context "Basic logic tests" {
It "Read CS without params" {
if (! (Test-Path -Path (Get-DefaultCredentialStorePath)) ) {
{ New-CredentialStore -Force } | Should -Not -Throw
}
{ Get-CredentialStore } | Should -Not -Throw
}
It "Read Credential Store with testing data" {
$TestCredentialStore = './resources/cs/CredentialStore.json'
$TestPfxCert = './resources/cs/PSCredentialStore.pfx'
{
Use-CSCertificate -Shared -CredentialStore $TestCredentialStore -Path $TestPfxCert
} | Should -Not -Throw
{ Get-CredentialStore -Shared -Path $TestCredentialStore } | Should -Not -Throw
}
It "Test3: Not existing path should return false" {
{
Get-CredentialStore -Shared -Path './CredentialStore.json'
} | Should -Throw "Could not find the CredentialStore."
}
}
Context "Testing invalid json data" {
It "Should throw with invalid CredentialStore" {
$BrokenCS = './resources/cs/Broken_CS.json'
Write-Verbose -Message ('BrokenCS Path: {0}' -f $BrokenCS) -Verbose
{
Get-CredentialStore -Path -Shared $BrokenCS
} | Should -Throw
}
}
}