Migrates to Pester5+ tests #59

Merged
OCram85 merged 47 commits from Pester5 into master 2022-07-14 13:37:13 +02:00
2 changed files with 17 additions and 13 deletions
Showing only changes of commit 642af42d7e - Show all commits

View File

@ -13,7 +13,7 @@ BeforeAll {
Describe "Get-CredentialStore" { Describe "Get-CredentialStore" {
Context "Basic logic tests" { Context "Basic logic tests" {
It "Test1: Read CS without params" { It "Read CS without params" {
$TestCredentialStore = './resources/cs/CredentialStore.json' $TestCredentialStore = './resources/cs/CredentialStore.json'
$TestPfxCert = './resources/cs/PSCredentialStore.pfx' $TestPfxCert = './resources/cs/PSCredentialStore.pfx'
if (! (Test-Path -Path (Get-DefaultCredentialStorePath)) ) { if (! (Test-Path -Path (Get-DefaultCredentialStorePath)) ) {
@ -21,7 +21,7 @@ Describe "Get-CredentialStore" {
} }
{ Get-CredentialStore } | Should -Not -Throw { Get-CredentialStore } | Should -Not -Throw
} }
It "Test2: Read Credential Store with testing data" { It "Read Credential Store with testing data" {
$TestCredentialStore = './resources/cs/CredentialStore.json' $TestCredentialStore = './resources/cs/CredentialStore.json'
$TestPfxCert = './resources/cs/PSCredentialStore.pfx' $TestPfxCert = './resources/cs/PSCredentialStore.pfx'
{ {

View File

@ -34,17 +34,17 @@ BeforeAll {
Describe "New-CredentialStore" { Describe "New-CredentialStore" {
Context "Private CS tests" { Context "Private CS tests" {
It "Test1: Create new private CredentialStore" { It "Create new private CredentialStore" {
$pCS = Get-DefaultCredentialStorePath $pCS = Get-DefaultCredentialStorePath
{ New-CredentialStore -Confirm:$false -Force } | Should -Not -Throw { New-CredentialStore -Confirm:$false -Force } | Should -Not -Throw
$result = Test-Path -Path $pCS $result = Test-Path -Path $pCS
$CS = Get-Content -Path $pCS -Raw | ConvertFrom-Json $CS = Get-Content -Path $pCS -Raw | ConvertFrom-Json
($result -eq $true) -and ($CS.Type -eq "Private") | Should -Be $true ($result -eq $true) -and ($CS.Type -eq "Private") | Should -Be $true
} }
It "Test2: Try to override private Store" { It "Try to override private Store" {
{ New-CredentialStore -Confirm:$false } | Should -Throw { New-CredentialStore -Confirm:$false } | Should -Throw
} }
It "Test3: Reset existing Credential Store" { It "Reset existing Credential Store" {
$pCS = Get-DefaultCredentialStorePath $pCS = Get-DefaultCredentialStorePath
$now = Get-Date $now = Get-Date
$CS = Get-Content -Path $pCS -Raw | ConvertFrom-Json $CS = Get-Content -Path $pCS -Raw | ConvertFrom-Json
@ -54,15 +54,15 @@ Describe "New-CredentialStore" {
} }
} }
Context "Shared CS tests" { Context "Shared CS tests" {
It "Test1: Create a new Shared Credential Store" { It "Create a new Shared Credential Store" {
$sCS = Get-DefaultCredentialStorePath -Shared $sCS = Get-DefaultCredentialStorePath -Shared
{ New-CredentialStore -Confirm:$false -Shared } | Should -Not -Throw { New-CredentialStore -Confirm:$false -Shared } | Should -Not -Throw
Test-Path -Path $sCS | Should -Be $true Test-Path -Path $sCS | Should -Be $true
} }
It "Test2: Try to override existing shared CS" { It "Try to override existing shared CS" {
{ New-CredentialStore -Shared -Confirm:$false } | Should -Throw { New-CredentialStore -Shared -Confirm:$false } | Should -Throw
} }
It "Test3: Reset shared CredentialStore" { It "Reset shared CredentialStore" {
$sCS = Get-DefaultCredentialStorePath -Shared $sCS = Get-DefaultCredentialStorePath -Shared
$now = Get-Date $now = Get-Date
$CS = Get-Content -Path $sCS -Raw | ConvertFrom-Json $CS = Get-Content -Path $sCS -Raw | ConvertFrom-Json
@ -72,15 +72,15 @@ Describe "New-CredentialStore" {
} }
} }
Context "Custom Shared CS tests" { Context "Custom Shared CS tests" {
It "Test1: Create new custom shared" { It "Create new custom shared" {
$cCS = Join-Path -Path (Get-TempDir) -ChildPath "CredentialStore.json" $cCS = Join-Path -Path (Get-TempDir) -ChildPath "CredentialStore.json"
{ New-CredentialStore -Path $cCS -Shared -Confirm:$false } | Should -Not -Throw { New-CredentialStore -Path $cCS -Shared -Confirm:$false -SkipPFXCertCreation } | Should -Not -Throw
} }
It "Test2: Try to override exiting one" { It "Try to override exiting one" {
$cCS = Join-Path -Path (Get-TempDir) -ChildPath "CredentialStore.json" $cCS = Join-Path -Path (Get-TempDir) -ChildPath "CredentialStore.json"
{ New-CredentialStore -Path $cCS -Shared -Confirm:$false } | Should -Throw { New-CredentialStore -Path $cCS -Shared -Confirm:$false } | Should -Throw
} }
It "Test3: Reset existing custom CredentialStore" { It "Reset existing custom CredentialStore" {
$cCS = Join-Path -Path (Get-TempDir) -ChildPath "CredentialStore.json" $cCS = Join-Path -Path (Get-TempDir) -ChildPath "CredentialStore.json"
{ New-CredentialStore -Path $cCS -Shared -Force -Confirm:$false } | Should -Not -Throw { New-CredentialStore -Path $cCS -Shared -Force -Confirm:$false } | Should -Not -Throw
} }
@ -88,7 +88,11 @@ Describe "New-CredentialStore" {
Context "Test exception handling" { Context "Test exception handling" {
Mock Out-File { throw "foobar exception" } Mock Out-File { throw "foobar exception" }
It "JSON Conversion should fail and throw" { It "JSON Conversion should fail and throw" {
{ New-CredentialStore -Path (Join-Path -Path (Get-TempDir) -ChildPath '/dummy.json') -Shared -Confirm:$false } | Should -Throw {
New-CredentialStore -Path (
Join-Path -Path (Get-TempDir) -ChildPath '/dummy.json'
) -Shared -Confirm:$false
} | Should -Throw
} }
} }
Context "Tests for Windows certificate store" { Context "Tests for Windows certificate store" {