wip
This commit is contained in:
parent
8e73cf346c
commit
01de79fe11
@ -9,37 +9,39 @@ BeforeAll {
|
||||
foreach ( $func in $PrivateFunctions) {
|
||||
. $func
|
||||
}
|
||||
|
||||
$RepoRoot = (Get-Item -Path (Get-GitDirectory) -Force).Parent | Select-Object -ExpandProperty 'FullName'
|
||||
}
|
||||
|
||||
Describe "Get-CredentialStore" {
|
||||
Context "Basic logic tests" {
|
||||
$TestCredentialStore = Join-Path -Path $RepoRoot -ChildPath 'resources/cs/CredentialStore.json'
|
||||
$TestPfxCert = Join-Path -Path $RepoRoot -ChildPath 'resources/cs/PSCredentialStore.pfx'
|
||||
'TestCredentialStore: {0}' -f $TestCredentialStore
|
||||
It "Test1: Read CS without params" {
|
||||
$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
|
||||
}
|
||||
It "Test2: Read Credential Store with testing data" {
|
||||
{ Use-CSCertificate -Shared -CredentialStore $TestCredentialStore -Path $TestPfxCert } | Should -Not -Throw
|
||||
$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."
|
||||
{
|
||||
Get-CredentialStore -Shared -Path './CredentialStore.json'
|
||||
} | Should -Throw "Could not find the CredentialStore."
|
||||
}
|
||||
}
|
||||
Context "Testing invalid json data" {
|
||||
#Mock Test-CredentialStore {return $true}
|
||||
#Mock Get-Content {return '"foo":"bar",'}
|
||||
$BrokenCS = Join-Path -Path $RepoRoot -ChildPath 'resources/cs/Broken_CS.json'
|
||||
Write-Verbose -Message ('BrokenCS Path: {0}' -f $BrokenCS) -Verbose
|
||||
It "Should throw with invalid CredentialStore" {
|
||||
{ Get-CredentialStore -Path -Shared $BrokenCS } | Should -Throw
|
||||
$BrokenCS = './resources/cs/Broken_CS.json'
|
||||
Write-Verbose -Message ('BrokenCS Path: {0}' -f $BrokenCS) -Verbose
|
||||
{
|
||||
Get-CredentialStore -Path -Shared $BrokenCS
|
||||
} | Should -Throw
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,8 +33,8 @@ BeforeAll {
|
||||
|
||||
Describe "New-CredentialStore" {
|
||||
Context "Private CS tests" {
|
||||
$pCS = Get-DefaultCredentialStorePath
|
||||
It "Test1: Create new private CredentialStore" {
|
||||
$pCS = Get-DefaultCredentialStorePath
|
||||
{ New-CredentialStore -Confirm:$false } | Should -Not -Throw
|
||||
$result = Test-Path -Path $pCS
|
||||
$CS = Get-Content -Path $pCS -Raw | ConvertFrom-Json
|
||||
@ -44,6 +44,7 @@ Describe "New-CredentialStore" {
|
||||
{ New-CredentialStore -Confirm:$false } | Should -Throw
|
||||
}
|
||||
It "Test3: Reset existing Credential Store" {
|
||||
$pCS = Get-DefaultCredentialStorePath
|
||||
$now = Get-Date
|
||||
$CS = Get-Content -Path $pCS -Raw | ConvertFrom-Json
|
||||
$CSCreation = [DateTime]$CS.Created
|
||||
@ -52,8 +53,8 @@ Describe "New-CredentialStore" {
|
||||
}
|
||||
}
|
||||
Context "Shared CS tests" {
|
||||
$sCS = Get-DefaultCredentialStorePath -Shared
|
||||
It "Test1: Create a new Shared Credential Store" {
|
||||
$sCS = Get-DefaultCredentialStorePath -Shared
|
||||
{ New-CredentialStore -Confirm:$false -Shared } | Should -Not -Throw
|
||||
Test-Path -Path $sCS | Should -Be $true
|
||||
}
|
||||
@ -61,6 +62,7 @@ Describe "New-CredentialStore" {
|
||||
{ New-CredentialStore -Shared -Confirm:$false } | Should -Throw
|
||||
}
|
||||
It "Test3: Reset shared CredentialStore" {
|
||||
$sCS = Get-DefaultCredentialStorePath -Shared
|
||||
$now = Get-Date
|
||||
$CS = Get-Content -Path $sCS -Raw | ConvertFrom-Json
|
||||
$CSCreation = [DateTime]$CS.Created
|
||||
@ -69,14 +71,16 @@ Describe "New-CredentialStore" {
|
||||
}
|
||||
}
|
||||
Context "Custom Shared CS tests" {
|
||||
$cCS = Join-Path -Path (Get-TempDir) -ChildPath "CredentialStore.json"
|
||||
It "Test1: Create new custom shared" {
|
||||
$cCS = Join-Path -Path (Get-TempDir) -ChildPath "CredentialStore.json"
|
||||
{ New-CredentialStore -Path $cCS -Shared -Confirm:$false } | Should -Not -Throw
|
||||
}
|
||||
It "Test2: Try to override exiting one" {
|
||||
$cCS = Join-Path -Path (Get-TempDir) -ChildPath "CredentialStore.json"
|
||||
{ New-CredentialStore -Path $cCS -Shared -Confirm:$false } | Should -Throw
|
||||
}
|
||||
It "Test3: Reset existing custom CredentialStore" {
|
||||
$cCS = Join-Path -Path (Get-TempDir) -ChildPath "CredentialStore.json"
|
||||
{ New-CredentialStore -Path $cCS -Shared -Force -Confirm:$false } | Should -Not -Throw
|
||||
}
|
||||
}
|
||||
@ -109,6 +113,7 @@ Describe "New-CredentialStore" {
|
||||
}
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
# Cleanup test stores and restore existing ones.
|
||||
$VerbosePreference = "Continue"
|
||||
Write-Verbose "Restoring private CredentialStore"
|
||||
@ -127,3 +132,5 @@ If (Test-Path -Path $BackupSharedFile) {
|
||||
}
|
||||
}
|
||||
$VerbosePreference = "SilentlyContinue"
|
||||
|
||||
}
|
||||
|
@ -15,16 +15,17 @@ BeforeAll {
|
||||
|
||||
Describe "Test-CredentialStore" {
|
||||
Context "Basic logic tests" {
|
||||
$TestCredentialStore = Join-Path -Path $RepoRoot -ChildPath '/resources/cs/CredentialStore.json'
|
||||
It "Test1: Should Not Throw" {
|
||||
$TestCredentialStore = './resources/cs/CredentialStore.json'
|
||||
{ Test-CredentialStore -Shared -Path $TestCredentialStore } | Should -Not -Throw
|
||||
}
|
||||
It "Test2: Read valid CredentialStore" {
|
||||
$TestCredentialStore = './resources/cs/CredentialStore.json'
|
||||
$res = Test-CredentialStore -Shared -Path $TestCredentialStore
|
||||
$res | Should -Be $true
|
||||
}
|
||||
It "Test3: Read a broken CredentialStore" {
|
||||
$BrokenCS = Join-Path -Path $RepoRoot -ChildPath '{0}/resources/cs/Broken_CS.json'
|
||||
$BrokenCS = './resources/cs/Broken_CS.json'
|
||||
$oWarningPreference = $WarningPreference
|
||||
$WarningPreference = 'SilentlyContinue'
|
||||
$res = Test-CredentialStore -Shared -Path $BrokenCS
|
||||
|
Loading…
Reference in New Issue
Block a user