From 76312fcb86d1fd8e11133c34d7296de16853caeb Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 14 Mar 2018 09:32:28 +0100 Subject: [PATCH] adds exception handling for Set-ChallengeFile --- .../01_Set-ChallengeFile.Tests.ps1 | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 b/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 index 2de7e8c..631a7f8 100644 --- a/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 +++ b/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 @@ -32,5 +32,29 @@ Describe "Set-ChallengeFile" { { Set-ChallengeFile } | Should -Throw Remove-Item -Path ("{0}\PSCredentialStore\Challenge.bin" -f $env:ProgramData) } + It "Use -Force switch should create a new challenge file" { + # prepare for test and clean up old data + if (Test-Path -Path ("{0}\PSCredentialStore\Challenge.bin" -f $env:ProgramData)) { + Remove-Item -Path ("{0}\PSCredentialStore\Challenge.bin" -f $env:ProgramData) + } + Set-ChallengeFile + { Set-ChallengeFile -Force } | Should -Not -Throw + } + It "Test directory creation for shared store" { + if (Test-Path -Path ("{0}\PSCredentialStore" -f $env:ProgramData)) { + Remove-Item -Path ("{0}\PSCredentialStore" -f $env:ProgramData) + } + Set-ChallengeFile + Test-Path -Path ("{0}\PSCredentialStore" -f $env:ProgramData) | Should -Be $true + } + } + Context "General Exception handling" { + Mock New-Item {throw "foobar exception"} + It "Test exception handling if the root directory could not be created" { + if (Test-Path -Path ("{0}\PSCredentialStore" -f $env:ProgramData)) { + Remove-Item -Path ("{0}\PSCredentialStore" -f $env:ProgramData) + } + { Set-ChallengeFile } | Should -Throw "Could not create the parent data dir*" + } } }