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

49 lines
1.9 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 "Test-CredentialStore" {
Context "Basic logic tests" {
2022-07-01 11:30:53 +02:00
It "Should Not Throw" {
2022-06-28 15:18:22 +02:00
$TestCredentialStore = './resources/cs/CredentialStore.json'
{ Test-CredentialStore -Shared -Path $TestCredentialStore } | Should -Not -Throw
}
2022-07-01 11:30:53 +02:00
It "Read valid CredentialStore" {
2022-06-28 15:18:22 +02:00
$TestCredentialStore = './resources/cs/CredentialStore.json'
$res = Test-CredentialStore -Shared -Path $TestCredentialStore
$res | Should -Be $true
}
2022-07-01 11:30:53 +02:00
It "Read a broken CredentialStore" -Skip {
2022-06-28 15:18:22 +02:00
$BrokenCS = './resources/cs/Broken_CS.json'
$oWarningPreference = $WarningPreference
$WarningPreference = 'SilentlyContinue'
$res = Test-CredentialStore -Shared -Path $BrokenCS
$res | Should -Be $false
$WarningPreference = $oWarningPreference
}
2022-07-01 11:30:53 +02:00
It "Not existing path should return false" {
if ($isWindows -or ($PSVersionTable.PSVersion.Major -eq 5)) {
Test-CredentialStore -Shared -Path 'C:\foobar\CredentialStore.json' | Should -Be $false
}
elseif ($isWindows -or $IsMacOS) {
Test-CredentialStore -Shared -Path '/var/opt/foo.json' | Should -Be $false
}
}
2022-07-01 11:30:53 +02:00
It "testing private CredentialStore path" {
if (Test-Path -Path (Get-DefaultCredentialStorePath)) {
Remove-Item -Path (Get-DefaultCredentialStorePath)
}
Test-CredentialStore | Should -Be $false
}
}
}