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

48 lines
1.8 KiB
PowerShell
Raw Normal View History

2022-06-28 14:54:20 +02:00
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" {
2022-07-01 11:27:28 +02:00
It "Read CS without params" {
2022-06-28 15:18:22 +02:00
$TestCredentialStore = './resources/cs/CredentialStore.json'
$TestPfxCert = './resources/cs/PSCredentialStore.pfx'
if (! (Test-Path -Path (Get-DefaultCredentialStorePath)) ) {
{ New-CredentialStore -Force } | Should -Not -Throw
}
{ Get-CredentialStore } | Should -Not -Throw
}
2022-07-01 11:27:28 +02:00
It "Read Credential Store with testing data" {
2022-06-28 15:18:22 +02:00
$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" {
2022-06-28 15:18:22 +02:00
{
Get-CredentialStore -Shared -Path './CredentialStore.json'
} | Should -Throw "Could not find the CredentialStore."
}
}
Context "Testing invalid json data" {
It "Should throw with invalid CredentialStore" {
2022-06-28 15:18:22 +02:00
$BrokenCS = './resources/cs/Broken_CS.json'
Write-Verbose -Message ('BrokenCS Path: {0}' -f $BrokenCS) -Verbose
{
Get-CredentialStore -Path -Shared $BrokenCS
} | Should -Throw
}
}
}