From 691a736cc0eeb0d74d6b24634135b91618051d9e Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 9 Mar 2018 14:20:51 +0100 Subject: [PATCH 01/34] adds dummy test for Get-ModuleDir --- tests/Helper/01_Get-ModuleBase.Tests.ps1 | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/Helper/01_Get-ModuleBase.Tests.ps1 diff --git a/tests/Helper/01_Get-ModuleBase.Tests.ps1 b/tests/Helper/01_Get-ModuleBase.Tests.ps1 new file mode 100644 index 0000000..8321900 --- /dev/null +++ b/tests/Helper/01_Get-ModuleBase.Tests.ps1 @@ -0,0 +1,32 @@ +#region HEADER +$RepoRoot = (Get-GitDirectory).replace('\.git', '') +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.' +$sut = $sut -replace "\d{2}`_", '' +$suthome = (Get-ChildItem -Path $RepoRoot -Exclude ".\tests\" -Filter $sut -Recurse).FullName +# Skip try loading the source file if it doesn't exists. +If ($suthome.Length -gt 0) { + . $suthome +} +Else { + Write-Warning ("Could not find source file {0}" -f $sut) +} + +# load additional functions defined in the repository. Replace the expression . +# . (Get-ChildItem -Path $RepoRoot -Filter ".ps1" -Recurse).FullName + +#endregion HEADER + +Describe "Get-ModuleBase" { + Context "Basic syntax check" { + It "Test1: Should not throw" { + { Get-ModuleBase } | Should -Not -Throw + } + } + Context "Testing basic scenario" { + # Dummy test. This can only be executed if it gets populated by the module itself. But it's + # private function an returns $null when it's called by pester... + It "Env: AppVeyor" { + Get-ModuleBase | Should -Be '' + } + } +} -- 2.45.2 From 4b99f83dd29837f96de61e64056ae8549d1d38b0 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 9 Mar 2018 14:24:40 +0100 Subject: [PATCH 02/34] fix dumy output --- tests/Helper/01_Get-ModuleBase.Tests.ps1 | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Helper/01_Get-ModuleBase.Tests.ps1 b/tests/Helper/01_Get-ModuleBase.Tests.ps1 index 8321900..55ba4f6 100644 --- a/tests/Helper/01_Get-ModuleBase.Tests.ps1 +++ b/tests/Helper/01_Get-ModuleBase.Tests.ps1 @@ -22,11 +22,4 @@ Describe "Get-ModuleBase" { { Get-ModuleBase } | Should -Not -Throw } } - Context "Testing basic scenario" { - # Dummy test. This can only be executed if it gets populated by the module itself. But it's - # private function an returns $null when it's called by pester... - It "Env: AppVeyor" { - Get-ModuleBase | Should -Be '' - } - } } -- 2.45.2 From 687b2728061956da62f0109bdbc2f1d820037b06 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 9 Mar 2018 14:39:16 +0100 Subject: [PATCH 03/34] add Get-RandomKey tests --- src/Helper/Get-RandomKey.ps1 | 1 + tests/Helper/01_Get-RandomKey.Tests.ps1 | 39 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/Helper/01_Get-RandomKey.Tests.ps1 diff --git a/src/Helper/Get-RandomKey.ps1 b/src/Helper/Get-RandomKey.ps1 index 206f400..907160a 100644 --- a/src/Helper/Get-RandomKey.ps1 +++ b/src/Helper/Get-RandomKey.ps1 @@ -32,6 +32,7 @@ function Get-RandomKey { [CmdletBinding()] param( [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] [ValidateSet(16, 24, 32)] [string]$size ) diff --git a/tests/Helper/01_Get-RandomKey.Tests.ps1 b/tests/Helper/01_Get-RandomKey.Tests.ps1 new file mode 100644 index 0000000..f6ab645 --- /dev/null +++ b/tests/Helper/01_Get-RandomKey.Tests.ps1 @@ -0,0 +1,39 @@ +#region HEADER +$RepoRoot = (Get-GitDirectory).replace('\.git', '') +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.' +$sut = $sut -replace "\d{2}`_", '' +$suthome = (Get-ChildItem -Path $RepoRoot -Exclude ".\tests\" -Filter $sut -Recurse).FullName +# Skip try loading the source file if it doesn't exists. +If ($suthome.Length -gt 0) { + . $suthome +} +Else { + Write-Warning ("Could not find source file {0}" -f $sut) +} + +# load additional functions defined in the repository. Replace the expression . +# . (Get-ChildItem -Path $RepoRoot -Filter ".ps1" -Recurse).FullName + +#endregion HEADER + +Describe "Get-RandomKey" { + Context "Basic input tests" { + It "Test1: Should throw if wrong size is given" { + {Get-RandomKey -size 43} | Should -Throw + } + } + Context "Basic syntax check" { + It "Test1: Should return a key with a length of 16" { + $Key = Get-RandomKey -size 16 + $Key.length | Should -Be 16 + } + It "Test2: Should return a key with a length of 24" { + $Key = Get-RandomKey -size 24 + $Key.length | Should -Be 24 + } + It "Test3: Should return a key with a length of 32" { + $Key = Get-RandomKey -size 32 + $Key.length | Should -Be 32 + } + } +} -- 2.45.2 From e2af175b9f4ec771539561cc8ec9a45a3bdd2179 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Mon, 12 Mar 2018 13:57:07 +0100 Subject: [PATCH 04/34] adds tests for Test-ChallengeFile --- .../01_Test-ChallengeFile.Tests.ps1 | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/ChallengeFile/01_Test-ChallengeFile.Tests.ps1 diff --git a/tests/ChallengeFile/01_Test-ChallengeFile.Tests.ps1 b/tests/ChallengeFile/01_Test-ChallengeFile.Tests.ps1 new file mode 100644 index 0000000..f5318cd --- /dev/null +++ b/tests/ChallengeFile/01_Test-ChallengeFile.Tests.ps1 @@ -0,0 +1,39 @@ +#region HEADER +$RepoRoot = (Get-GitDirectory).replace('\.git', '') +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.' +$sut = $sut -replace "\d{2}`_", '' +$suthome = (Get-ChildItem -Path $RepoRoot -Exclude ".\tests\" -Filter $sut -Recurse).FullName +# Skip try loading the source file if it doesn't exists. +If ($suthome.Length -gt 0) { + . $suthome +} +Else { + Write-Warning ("Could not find source file {0}" -f $sut) +} + +# load additional functions defined in the repository. Replace the expression . +. (Get-ChildItem -Path $RepoRoot -Filter "Test-ChallengeFile.ps1" -Recurse).FullName + +#endregion HEADER + +Describe "Test-ChallengeFile" { + Context "Basic input tests" { + Mock Test-Path {return $true} + It "No parameter with existing challenge file" { + {Test-ChallengeFile} | Should -Not -Throw + } + It "No parameter and existing file should return true" { + Test-ChallengeFile | Should -Be $true + } + Context "Execute with parameter" { + $TestChFile = "{0}\resources\Challenge.bin" -f $RepoRoot + It "Provide valid path" { + Test-ChallengeFile -Path $TestChFile | Should -Be $true + } + It "Provide fake path" { + Test-ChallengeFile -Path "C:\notexisting.bin" | Should -Be $false + } + } + + } +} -- 2.45.2 From 793035fa47a5c762627bd2e16c4c096ab2a042d3 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Mon, 12 Mar 2018 13:59:41 +0100 Subject: [PATCH 05/34] fix pester syntax --- .../01_Test-ChallengeFile.Tests.ps1 | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/ChallengeFile/01_Test-ChallengeFile.Tests.ps1 b/tests/ChallengeFile/01_Test-ChallengeFile.Tests.ps1 index f5318cd..7b93681 100644 --- a/tests/ChallengeFile/01_Test-ChallengeFile.Tests.ps1 +++ b/tests/ChallengeFile/01_Test-ChallengeFile.Tests.ps1 @@ -25,15 +25,14 @@ Describe "Test-ChallengeFile" { It "No parameter and existing file should return true" { Test-ChallengeFile | Should -Be $true } - Context "Execute with parameter" { - $TestChFile = "{0}\resources\Challenge.bin" -f $RepoRoot - It "Provide valid path" { - Test-ChallengeFile -Path $TestChFile | Should -Be $true - } - It "Provide fake path" { - Test-ChallengeFile -Path "C:\notexisting.bin" | Should -Be $false - } + } + Context "Execute with parameter" { + $TestChFile = "{0}\resources\Challenge.bin" -f $RepoRoot + It "Provide valid path" { + Test-ChallengeFile -Path $TestChFile | Should -Be $true + } + It "Provide fake path" { + Test-ChallengeFile -Path "C:\notexisting.bin" | Should -Be $false } - } } -- 2.45.2 From 139ea6c5ce6969f776e207e310f17ee9e477a1e0 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Mon, 12 Mar 2018 14:01:51 +0100 Subject: [PATCH 06/34] fix path to test cs file --- tests/ChallengeFile/01_Test-ChallengeFile.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ChallengeFile/01_Test-ChallengeFile.Tests.ps1 b/tests/ChallengeFile/01_Test-ChallengeFile.Tests.ps1 index 7b93681..ca61842 100644 --- a/tests/ChallengeFile/01_Test-ChallengeFile.Tests.ps1 +++ b/tests/ChallengeFile/01_Test-ChallengeFile.Tests.ps1 @@ -27,7 +27,7 @@ Describe "Test-ChallengeFile" { } } Context "Execute with parameter" { - $TestChFile = "{0}\resources\Challenge.bin" -f $RepoRoot + $TestChFile = "{0}\resources\cs\Challenge.bin" -f $RepoRoot It "Provide valid path" { Test-ChallengeFile -Path $TestChFile | Should -Be $true } -- 2.45.2 From 5910c443562ee785100c8ba8c9271db8c69ff3b3 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Mon, 12 Mar 2018 15:55:23 +0100 Subject: [PATCH 07/34] adds Sdt-ChallengeFile tests --- .../01_Set-ChallengeFile.Tests.ps1 | 34 +++++++++++++++++++ .../01_Test-ChallengeFile.Tests.ps1 | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 diff --git a/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 b/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 new file mode 100644 index 0000000..762df84 --- /dev/null +++ b/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 @@ -0,0 +1,34 @@ +#region HEADER +$RepoRoot = (Get-GitDirectory).replace('\.git', '') +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.' +$sut = $sut -replace "\d{2}`_", '' +$suthome = (Get-ChildItem -Path $RepoRoot -Exclude ".\tests\" -Filter $sut -Recurse).FullName +# Skip try loading the source file if it doesn't exists. +If ($suthome.Length -gt 0) { + . $suthome +} +Else { + Write-Warning ("Could not find source file {0}" -f $sut) +} + +# load additional functions defined in the repository. Replace the expression . +. (Get-ChildItem -Path $RepoRoot -Filter "Get-RandomKey.ps1" -Recurse).FullName + +#endregion HEADER + +Describe "Set-ChallengeFile" { + Context "Tests with custom path" { + It "Working dir and path not exist" { + Set-ChallengeFile -Path 'C:\CredentialStore\Challenge.bin' | Should -Not -Throw + } + It "No parameter and non file should return true" { + if (Test-Path -Path ("{0}\PSCredentialStore\Challenge.bin" -f $env:ProgramData)) { + Remove-Item -Path ("{0}\PSCredentialStore\Challenge.bin" -f $env:ProgramData) + } + Set-ChallengeFile | Should -Be $true + } + It "Existing Credential file should return error" { + { Set-ChallengeFile } | Should -Throw + } + } +} diff --git a/tests/ChallengeFile/01_Test-ChallengeFile.Tests.ps1 b/tests/ChallengeFile/01_Test-ChallengeFile.Tests.ps1 index ca61842..285fddc 100644 --- a/tests/ChallengeFile/01_Test-ChallengeFile.Tests.ps1 +++ b/tests/ChallengeFile/01_Test-ChallengeFile.Tests.ps1 @@ -12,7 +12,7 @@ Else { } # load additional functions defined in the repository. Replace the expression . -. (Get-ChildItem -Path $RepoRoot -Filter "Test-ChallengeFile.ps1" -Recurse).FullName +#. (Get-ChildItem -Path $RepoRoot -Filter "Test-ChallengeFile.ps1" -Recurse).FullName #endregion HEADER -- 2.45.2 From a440a61b10e2816fda814bee15daadf26da3f5a3 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Mon, 12 Mar 2018 16:00:21 +0100 Subject: [PATCH 08/34] update should syntax with -throw parameter --- tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 b/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 index 762df84..71f7c9c 100644 --- a/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 +++ b/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 @@ -19,7 +19,7 @@ Else { Describe "Set-ChallengeFile" { Context "Tests with custom path" { It "Working dir and path not exist" { - Set-ChallengeFile -Path 'C:\CredentialStore\Challenge.bin' | Should -Not -Throw + {Set-ChallengeFile -Path 'C:\PSCredentialStore\Challenge.bin'} | Should -Not -Throw } It "No parameter and non file should return true" { if (Test-Path -Path ("{0}\PSCredentialStore\Challenge.bin" -f $env:ProgramData)) { -- 2.45.2 From 700208a44b16dcbc686a470ca4ac51f10e875e17 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Mon, 12 Mar 2018 16:03:32 +0100 Subject: [PATCH 09/34] update pester tests --- tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 b/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 index 71f7c9c..2de7e8c 100644 --- a/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 +++ b/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 @@ -25,10 +25,12 @@ Describe "Set-ChallengeFile" { if (Test-Path -Path ("{0}\PSCredentialStore\Challenge.bin" -f $env:ProgramData)) { Remove-Item -Path ("{0}\PSCredentialStore\Challenge.bin" -f $env:ProgramData) } - Set-ChallengeFile | Should -Be $true + Set-ChallengeFile + Test-Path -Path ("{0}\PSCredentialStore\Challenge.bin" -f $env:ProgramData) | Should -Be $true } It "Existing Credential file should return error" { { Set-ChallengeFile } | Should -Throw + Remove-Item -Path ("{0}\PSCredentialStore\Challenge.bin" -f $env:ProgramData) } } } -- 2.45.2 From d6aa68521e1d6ca32235b38b61b734e25e4c4e73 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 13 Mar 2018 13:52:18 +0100 Subject: [PATCH 10/34] try to fix coverage report error --- tools/AppVeyor.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/AppVeyor.psm1 b/tools/AppVeyor.psm1 index 71e1e85..0dd1a84 100644 --- a/tools/AppVeyor.psm1 +++ b/tools/AppVeyor.psm1 @@ -154,7 +154,7 @@ Function Invoke-CoverageReport() { [String]$RepoToken = $Env:CoverallsToken ) - Import-Module ('.\src\{0}.psm1' -f $CALLSIGN) -Verbose -Force + #Import-Module ('.\src\{0}.psm1' -f $CALLSIGN) -Verbose -Force $FileMap = New-PesterFileMap -SourceRoot '.\src' -PesterRoot '.\tests' $CoverageReport = New-CoverageReport -PesterFileMap $FileMap -RepoToken $RepoToken Write-Host "CoverageReport JSON:" -ForegroundColor Yellow -- 2.45.2 From 29e03852c055681e3b83c687978cbe628c432bc9 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 13 Mar 2018 13:54:44 +0100 Subject: [PATCH 11/34] Remove module load before coverage report creation. fix buld errors --- tools/AppVeyor.psm1 | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/AppVeyor.psm1 b/tools/AppVeyor.psm1 index 0dd1a84..ac35426 100644 --- a/tools/AppVeyor.psm1 +++ b/tools/AppVeyor.psm1 @@ -154,7 +154,6 @@ Function Invoke-CoverageReport() { [String]$RepoToken = $Env:CoverallsToken ) - #Import-Module ('.\src\{0}.psm1' -f $CALLSIGN) -Verbose -Force $FileMap = New-PesterFileMap -SourceRoot '.\src' -PesterRoot '.\tests' $CoverageReport = New-CoverageReport -PesterFileMap $FileMap -RepoToken $RepoToken Write-Host "CoverageReport JSON:" -ForegroundColor Yellow -- 2.45.2 From d8d57570368a0be9581eaf261206f54b71898fc5 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 13 Mar 2018 14:13:08 +0100 Subject: [PATCH 12/34] adds Test-Module pester tests --- tests/Helper/01_Test-Module.Tests.ps1 | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/Helper/01_Test-Module.Tests.ps1 diff --git a/tests/Helper/01_Test-Module.Tests.ps1 b/tests/Helper/01_Test-Module.Tests.ps1 new file mode 100644 index 0000000..e0cdec0 --- /dev/null +++ b/tests/Helper/01_Test-Module.Tests.ps1 @@ -0,0 +1,43 @@ +#region HEADER +$RepoRoot = (Get-GitDirectory).replace('\.git', '') +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.' +$sut = $sut -replace "\d{2}`_", '' +$suthome = (Get-ChildItem -Path $RepoRoot -Exclude ".\tests\" -Filter $sut -Recurse).FullName +# Skip try loading the source file if it doesn't exists. +If ($suthome.Length -gt 0) { + . $suthome +} +Else { + Write-Warning ("Could not find source file {0}" -f $sut) +} + +# load additional functions defined in the repository. Replace the expression . +#. (Get-ChildItem -Path $RepoRoot -Filter ".ps1" -Recurse).FullName + +#endregion HEADER + +Describe "Test-ModuleName" { + Context "Basic input tests" { + It "Testing standard module should not throw" { + { Test-Module -Name 'PowerShellGet' -Type Module } | Should -Not -Throw + } + It "Existing module should return true" { + Test-Module -Name 'PowerShellGet' -Type Module | Should -Be $true + } + } + Context "Custom Type tests" { + It "Using custom type should throw" { + { Test-Module -Name "foobarr" -Type Custom} | Should -Throw + } + } + Context "Working with PSSnapins" { + It "Loading first PSSnaping should not throw " { + $Snap = Get-PSSnapin -Registered | Select-Object -First 1 + { $loaded = Test-Module -Name $Snap.Name -Type PSSnapin } | Should -Not -Throw + Remove-PSSnapin -Name $Snap.Name + } + It "Loading first PSSnaping should return true" { + $loaded | Should -Be $true + } + } +} -- 2.45.2 From 1a6a861ad1a5c632c20f35e374a95e3ac7a0f05e Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 13 Mar 2018 14:16:46 +0100 Subject: [PATCH 13/34] show registered snapins on appveyor build --- src/Helper/Test-Module.ps1 | 2 +- tests/Helper/01_Test-Module.Tests.ps1 | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Helper/Test-Module.ps1 b/src/Helper/Test-Module.ps1 index 75d7720..70afa70 100644 --- a/src/Helper/Test-Module.ps1 +++ b/src/Helper/Test-Module.ps1 @@ -89,8 +89,8 @@ Could not find the required {0} called {1}. Please install the required {0} to r else { if ($StopIfFails) { Write-Error -Message $Message -ErrorAction Stop -Category NotInstalled - return $false } + return $false } } diff --git a/tests/Helper/01_Test-Module.Tests.ps1 b/tests/Helper/01_Test-Module.Tests.ps1 index e0cdec0..22f9181 100644 --- a/tests/Helper/01_Test-Module.Tests.ps1 +++ b/tests/Helper/01_Test-Module.Tests.ps1 @@ -32,7 +32,8 @@ Describe "Test-ModuleName" { } Context "Working with PSSnapins" { It "Loading first PSSnaping should not throw " { - $Snap = Get-PSSnapin -Registered | Select-Object -First 1 + $Snap = Get-PSSnapin -Registered + $Snap { $loaded = Test-Module -Name $Snap.Name -Type PSSnapin } | Should -Not -Throw Remove-PSSnapin -Name $Snap.Name } -- 2.45.2 From 64f1f05c761b4df1f73531b85c85359401769e08 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 13 Mar 2018 14:19:05 +0100 Subject: [PATCH 14/34] fix debug output --- tests/Helper/01_Test-Module.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Helper/01_Test-Module.Tests.ps1 b/tests/Helper/01_Test-Module.Tests.ps1 index 22f9181..51b4c0e 100644 --- a/tests/Helper/01_Test-Module.Tests.ps1 +++ b/tests/Helper/01_Test-Module.Tests.ps1 @@ -33,7 +33,7 @@ Describe "Test-ModuleName" { Context "Working with PSSnapins" { It "Loading first PSSnaping should not throw " { $Snap = Get-PSSnapin -Registered - $Snap + $Snap | Format-List | Out-String | Write-Verbose -Verbose { $loaded = Test-Module -Name $Snap.Name -Type PSSnapin } | Should -Not -Throw Remove-PSSnapin -Name $Snap.Name } -- 2.45.2 From a9a4967846d576f1a59e3d109a0eb55de70238b6 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 13 Mar 2018 14:21:49 +0100 Subject: [PATCH 15/34] fix snapin test logic --- tests/Helper/01_Test-Module.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Helper/01_Test-Module.Tests.ps1 b/tests/Helper/01_Test-Module.Tests.ps1 index 51b4c0e..b413836 100644 --- a/tests/Helper/01_Test-Module.Tests.ps1 +++ b/tests/Helper/01_Test-Module.Tests.ps1 @@ -31,11 +31,11 @@ Describe "Test-ModuleName" { } } Context "Working with PSSnapins" { + $loaded = $null It "Loading first PSSnaping should not throw " { $Snap = Get-PSSnapin -Registered $Snap | Format-List | Out-String | Write-Verbose -Verbose { $loaded = Test-Module -Name $Snap.Name -Type PSSnapin } | Should -Not -Throw - Remove-PSSnapin -Name $Snap.Name } It "Loading first PSSnaping should return true" { $loaded | Should -Be $true -- 2.45.2 From 5a4fcb4de57c33929f08817273e1936bc8dcfe9f Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 13 Mar 2018 14:25:56 +0100 Subject: [PATCH 16/34] adds additional pssnapin test --- tests/Helper/01_Test-Module.Tests.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Helper/01_Test-Module.Tests.ps1 b/tests/Helper/01_Test-Module.Tests.ps1 index b413836..86dcb80 100644 --- a/tests/Helper/01_Test-Module.Tests.ps1 +++ b/tests/Helper/01_Test-Module.Tests.ps1 @@ -31,14 +31,15 @@ Describe "Test-ModuleName" { } } Context "Working with PSSnapins" { - $loaded = $null It "Loading first PSSnaping should not throw " { $Snap = Get-PSSnapin -Registered $Snap | Format-List | Out-String | Write-Verbose -Verbose { $loaded = Test-Module -Name $Snap.Name -Type PSSnapin } | Should -Not -Throw } It "Loading first PSSnaping should return true" { - $loaded | Should -Be $true + $Snap = Get-PSSnapin -Registered + $Snap | Format-List | Out-String | Write-Verbose -Verbose + Test-Module -Name $Snap.Name -Type PSSnapin | Should -Be $true } } } -- 2.45.2 From 7e2da468d5b714b5cb7439747d0db026f93339fe Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 13 Mar 2018 14:32:15 +0100 Subject: [PATCH 17/34] minor fixes --- tests/Helper/01_Test-Module.Tests.ps1 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/Helper/01_Test-Module.Tests.ps1 b/tests/Helper/01_Test-Module.Tests.ps1 index 86dcb80..8c51325 100644 --- a/tests/Helper/01_Test-Module.Tests.ps1 +++ b/tests/Helper/01_Test-Module.Tests.ps1 @@ -33,12 +33,11 @@ Describe "Test-ModuleName" { Context "Working with PSSnapins" { It "Loading first PSSnaping should not throw " { $Snap = Get-PSSnapin -Registered - $Snap | Format-List | Out-String | Write-Verbose -Verbose + $Snap = Get-PSSnapin -Registered | Select-Object -First 1 { $loaded = Test-Module -Name $Snap.Name -Type PSSnapin } | Should -Not -Throw } It "Loading first PSSnaping should return true" { - $Snap = Get-PSSnapin -Registered - $Snap | Format-List | Out-String | Write-Verbose -Verbose + $Snap = Get-PSSnapin -Registered | Select-Object -First 1 Test-Module -Name $Snap.Name -Type PSSnapin | Should -Be $true } } -- 2.45.2 From e50acbcfbe54c3ce8b59f002b98179f2ffe73b3d Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 13 Mar 2018 14:37:44 +0100 Subject: [PATCH 18/34] adds test for StopIfFails --- tests/Helper/01_Test-Module.Tests.ps1 | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tests/Helper/01_Test-Module.Tests.ps1 b/tests/Helper/01_Test-Module.Tests.ps1 index 8c51325..3513521 100644 --- a/tests/Helper/01_Test-Module.Tests.ps1 +++ b/tests/Helper/01_Test-Module.Tests.ps1 @@ -32,13 +32,34 @@ Describe "Test-ModuleName" { } Context "Working with PSSnapins" { It "Loading first PSSnaping should not throw " { - $Snap = Get-PSSnapin -Registered $Snap = Get-PSSnapin -Registered | Select-Object -First 1 - { $loaded = Test-Module -Name $Snap.Name -Type PSSnapin } | Should -Not -Throw + { Test-Module -Name $Snap.Name -Type PSSnapin } | Should -Not -Throw } It "Loading first PSSnaping should return true" { $Snap = Get-PSSnapin -Registered | Select-Object -First 1 Test-Module -Name $Snap.Name -Type PSSnapin | Should -Be $true } + It "Not existing PSSnaping should return false" { + Test-Module -Name 'foobar2000' -Type PSSnapin | Should -Be $false + } + It "StopifFails switch should thrown an error" { + {Test-Module -Name 'foobar2000' -Type PSSnapin }| Should -Throw + } + } + Context "Working with modules" { + It "Loading first module should not throw " { + $Mod = Get-Module -ListAvailable | Select-Object -First 1 + { Test-Module -Name $Mod.Name -Type Module } | Should -Not -Throw + } + It "Loading first module should return true" { + $Snap = Get-Module -ListAvailable | Select-Object -First 1 + Test-Module -Name $Snap.Name -Type Module | Should -Be $true + } + It "Not existing module should return false" { + Test-Module -Name 'foobar2000' -Type Module | Should -Be $false + } + It "StopifFails switch should thrown an error" { + {Test-Module -Name 'foobar2000' -Type Module }| Should -Throw + } } } -- 2.45.2 From f33a243191c0562ce583876ed324751cf0efde0d Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 13 Mar 2018 14:44:26 +0100 Subject: [PATCH 19/34] fix stopiffails switch logic. suppress error output --- src/Helper/Test-Module.ps1 | 2 +- tests/Helper/01_Test-Module.Tests.ps1 | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Helper/Test-Module.ps1 b/src/Helper/Test-Module.ps1 index 70afa70..f116459 100644 --- a/src/Helper/Test-Module.ps1 +++ b/src/Helper/Test-Module.ps1 @@ -83,7 +83,7 @@ Could not find the required {0} called {1}. Please install the required {0} to r } 'PSSnapin' { - if (Get-PSSnapin -Name $Name -Registered) { + if (Get-PSSnapin -Name $Name -Registered -ErrorAction SilentlyContinue) { return $true } else { diff --git a/tests/Helper/01_Test-Module.Tests.ps1 b/tests/Helper/01_Test-Module.Tests.ps1 index 3513521..675a2dc 100644 --- a/tests/Helper/01_Test-Module.Tests.ps1 +++ b/tests/Helper/01_Test-Module.Tests.ps1 @@ -43,7 +43,7 @@ Describe "Test-ModuleName" { Test-Module -Name 'foobar2000' -Type PSSnapin | Should -Be $false } It "StopifFails switch should thrown an error" { - {Test-Module -Name 'foobar2000' -Type PSSnapin }| Should -Throw + {Test-Module -Name 'foobar2000' -Type PSSnapin -StopIfFails }| Should -Throw } } Context "Working with modules" { @@ -59,7 +59,7 @@ Describe "Test-ModuleName" { Test-Module -Name 'foobar2000' -Type Module | Should -Be $false } It "StopifFails switch should thrown an error" { - {Test-Module -Name 'foobar2000' -Type Module }| Should -Throw + {Test-Module -Name 'foobar2000' -Type Module -StopIfFails }| Should -Throw } } } -- 2.45.2 From 610bed55e1acbdfb96d55f26846f6192b4d085cd Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 13 Mar 2018 14:54:59 +0100 Subject: [PATCH 20/34] add Test-Credentialstore tests --- appveyor.yml | 2 +- tests/Store/01_Test-CredentialStore.Tests.ps1 | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index d1f3a05..db82d20 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,7 +20,7 @@ image: Visual Studio 2017 install: - ps: Import-Module .\tools\AppVeyor.psm1 - - ps: Invoke-InstallDependencies -Verbose + - ps: Invoke-InstallDependencies environment: NuGetToken: diff --git a/tests/Store/01_Test-CredentialStore.Tests.ps1 b/tests/Store/01_Test-CredentialStore.Tests.ps1 index 693184f..b32738f 100644 --- a/tests/Store/01_Test-CredentialStore.Tests.ps1 +++ b/tests/Store/01_Test-CredentialStore.Tests.ps1 @@ -36,5 +36,14 @@ Describe "Test-CredentialStore" { $res | Should Be $False $WarningPreference = $oWarningPreference } + It "Test4: Not existing path should return false" { + Test-CredentialStore -Path 'C:\foobar\CredentialStore.json' | Should -Be $false + } + It "Test5: testing private CredentialStore path" { + if (Test-Path -Path ("{0}\CredentialStore.json" -f $env:APPDATA) ) { + Remove-Item -Path ("{0}\CredentialStore.json" -f $env:APPDATA) + } + Test-CredentialStore | Should -Be $false + } } } -- 2.45.2 From 4fd762bcc680b0fc8f75d0daa26b30d4ef50d0c8 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 13 Mar 2018 15:51:02 +0100 Subject: [PATCH 21/34] add test for Get-CredentialStore --- tests/Store/01_Get-CredentialStore.Tests.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Store/01_Get-CredentialStore.Tests.ps1 b/tests/Store/01_Get-CredentialStore.Tests.ps1 index a0cab26..13e8aeb 100644 --- a/tests/Store/01_Get-CredentialStore.Tests.ps1 +++ b/tests/Store/01_Get-CredentialStore.Tests.ps1 @@ -33,5 +33,8 @@ Describe "Get-CredentialStore" { {Get-CredentialStore -Path $TestCredentialStore} | Should Not Throw } + It "Test3: Not existing path should return false" { + Get-CredentialStore -Path 'C:\foobar\CredentialStore.json' -Shared | Should -Be $false + } } } -- 2.45.2 From 9a4d50d097bfa7cd998588999a63af3712d78621 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 13 Mar 2018 15:53:23 +0100 Subject: [PATCH 22/34] fix pester test --- tests/Store/01_Get-CredentialStore.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Store/01_Get-CredentialStore.Tests.ps1 b/tests/Store/01_Get-CredentialStore.Tests.ps1 index 13e8aeb..e2d6b29 100644 --- a/tests/Store/01_Get-CredentialStore.Tests.ps1 +++ b/tests/Store/01_Get-CredentialStore.Tests.ps1 @@ -34,7 +34,7 @@ Describe "Get-CredentialStore" { {Get-CredentialStore -Path $TestCredentialStore} | Should Not Throw } It "Test3: Not existing path should return false" { - Get-CredentialStore -Path 'C:\foobar\CredentialStore.json' -Shared | Should -Be $false + { Get-CredentialStore -Path 'C:\foobar\CredentialStore.json' -Shared }| Should -Throw "Could not find the CredentialStore." } } } -- 2.45.2 From f4bac76d608c3637bad09edd7ef677410b156b27 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 13 Mar 2018 16:01:37 +0100 Subject: [PATCH 23/34] adds exception test for Get-CredentialStore --- tests/Store/01_Get-CredentialStore.Tests.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Store/01_Get-CredentialStore.Tests.ps1 b/tests/Store/01_Get-CredentialStore.Tests.ps1 index e2d6b29..e52f147 100644 --- a/tests/Store/01_Get-CredentialStore.Tests.ps1 +++ b/tests/Store/01_Get-CredentialStore.Tests.ps1 @@ -37,4 +37,11 @@ Describe "Get-CredentialStore" { { Get-CredentialStore -Path 'C:\foobar\CredentialStore.json' -Shared }| Should -Throw "Could not find the CredentialStore." } } + Context "Testing invalid json data" { + Mock Test-CredentialStore {return $true} + Mock Get-Content {return '"foo":"bar",'} + It "Should throw with invalid CredentialStore" { + { Get-Credentialstore -Path "C:\dummy.json"} | Should -Throw "Unknown CredentialStore format. Invalid JSON file." + } + } } -- 2.45.2 From 52aa4465a2e4951be80736af3f63f1bff8671730 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 14 Mar 2018 09:19:15 +0100 Subject: [PATCH 24/34] adds test for NewCredentialStore output exception --- tests/Store/01_New-CredentialStore.Tests.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/Store/01_New-CredentialStore.Tests.ps1 b/tests/Store/01_New-CredentialStore.Tests.ps1 index dfc47b0..b9d2eee 100644 --- a/tests/Store/01_New-CredentialStore.Tests.ps1 +++ b/tests/Store/01_New-CredentialStore.Tests.ps1 @@ -92,6 +92,12 @@ Describe "New-CredentialStore" { {New-CredentialStore -Path $pCS -Shared -Force} | Should Not Throw } } + Context "Test exception handling" { + Mock Out-File {throw "foobar exception"} + It "JSON Converstion should fail and throw" { + { New-CredentialStore -Path "C:\dummy.json"} | Should -Throw + } + } } # Cleanup test stores and restore existing ones. -- 2.45.2 From 76312fcb86d1fd8e11133c34d7296de16853caeb Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 14 Mar 2018 09:32:28 +0100 Subject: [PATCH 25/34] 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*" + } } } -- 2.45.2 From 1d009814544f35ae5b1d07772be763186f72168a Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 14 Mar 2018 09:36:32 +0100 Subject: [PATCH 26/34] fix pester test --- tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 b/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 index 631a7f8..3feffe7 100644 --- a/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 +++ b/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 @@ -42,7 +42,7 @@ Describe "Set-ChallengeFile" { } It "Test directory creation for shared store" { if (Test-Path -Path ("{0}\PSCredentialStore" -f $env:ProgramData)) { - Remove-Item -Path ("{0}\PSCredentialStore" -f $env:ProgramData) + Remove-Item -Path ("{0}\PSCredentialStore" -f $env:ProgramData) -Force -Recurse } Set-ChallengeFile Test-Path -Path ("{0}\PSCredentialStore" -f $env:ProgramData) | Should -Be $true @@ -52,7 +52,7 @@ Describe "Set-ChallengeFile" { 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) + Remove-Item -Path ("{0}\PSCredentialStore" -f $env:ProgramData) -Force -Recurse } { Set-ChallengeFile } | Should -Throw "Could not create the parent data dir*" } -- 2.45.2 From ebd0b790805b9887a22eb24efe435d3c9059ac64 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 14 Mar 2018 09:42:09 +0100 Subject: [PATCH 27/34] fix pester syntax for pester thes substring selection --- tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 b/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 index 3feffe7..0a68473 100644 --- a/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 +++ b/tests/ChallengeFile/01_Set-ChallengeFile.Tests.ps1 @@ -54,7 +54,7 @@ Describe "Set-ChallengeFile" { if (Test-Path -Path ("{0}\PSCredentialStore" -f $env:ProgramData)) { Remove-Item -Path ("{0}\PSCredentialStore" -f $env:ProgramData) -Force -Recurse } - { Set-ChallengeFile } | Should -Throw "Could not create the parent data dir*" + { Set-ChallengeFile } | Should -Throw "Could not create the parent data dir" } } } -- 2.45.2 From c46e3f5c534917a7e416f171cf878ea225c60f34 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 14 Mar 2018 09:55:13 +0100 Subject: [PATCH 28/34] adds New-CredentialStoreItem test with remotehost + identifier test --- tests/Item/02_New-CredentialStoreItem.Tests.ps1 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Item/02_New-CredentialStoreItem.Tests.ps1 b/tests/Item/02_New-CredentialStoreItem.Tests.ps1 index f1914bb..d84c1a7 100644 --- a/tests/Item/02_New-CredentialStoreItem.Tests.ps1 +++ b/tests/Item/02_New-CredentialStoreItem.Tests.ps1 @@ -61,5 +61,15 @@ Describe "New-CredentialStoreItem" { $res = Get-Member -InputObject $tmpCS -Name $RemoteHost -Membertype Properties $res.Name | Should Be $RemoteHost } + It "Adds Item with identifier to shared store" { + $tmpCS = 'C:\CredentialStore.json' + $UserName = "myuser" + $Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force + $mycreds = New-Object -TypeName PSCredential -ArgumentList $UserName, $Password + $RemoteHost = "foobar2" + New-CredentialStoreItem -Path $tmpCS -RemoteHost $RemoteHost -Credential $mycreds -Identifier 'Foo' + $writtenItem = Get-CredentialStoreItem -Path $tmpCS -RemoteHost $RemoteHost -Identifier 'Foo' + ($writtenItem.UserName -eq $UserName) -and ($writtenItem.Password.Length -gt 0) | Should -Be $true + } } } -- 2.45.2 From b5aff1f45b8a7c478434995c200232e112e22bf7 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 14 Mar 2018 13:13:28 +0100 Subject: [PATCH 29/34] adds aditional tests for New-CredentialStoreItem --- .../Item/02_New-CredentialStoreItem.Tests.ps1 | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/Item/02_New-CredentialStoreItem.Tests.ps1 b/tests/Item/02_New-CredentialStoreItem.Tests.ps1 index d84c1a7..93e663d 100644 --- a/tests/Item/02_New-CredentialStoreItem.Tests.ps1 +++ b/tests/Item/02_New-CredentialStoreItem.Tests.ps1 @@ -72,4 +72,30 @@ Describe "New-CredentialStoreItem" { ($writtenItem.UserName -eq $UserName) -and ($writtenItem.Password.Length -gt 0) | Should -Be $true } } + Context "Test optional parameter lookup" { + Mock Get-Credential { + return [PSCustomObject]@{ + UserName = 'myUser' + Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force + } + } + It "Test missing Credential" { + $tmpCS = 'C:\CredentialStore.json' + New-CredentialStoreItem -Path $tmpCs -Shared -RemoteHost 'foobar3' + $writtenItem = Get-CredentialStoreItem -Path $tmpCS -Shared -RemoteHost 'foobar3' + $writtenItem.UserName | Should -Be "myUser" + } + } + Context "General Exception handling" { + Mock Test-CredentialStore {return $false} + Mock Get-Credential { + return [PSCustomObject]@{ + UserName = 'myUser' + Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force + } + } + It "Missing CredentialStore should throw" { + New-CredentialStoreItem -Path 'C:\missingStore.json' -RemoteHost 'notrelevant' | Should -Throw "Could not add anything" + } + } } -- 2.45.2 From 82da4dc20a124179c911215f1fb48faac3ef11c6 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 14 Mar 2018 13:22:17 +0100 Subject: [PATCH 30/34] fix syntax error --- .../Item/02_New-CredentialStoreItem.Tests.ps1 | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/Item/02_New-CredentialStoreItem.Tests.ps1 b/tests/Item/02_New-CredentialStoreItem.Tests.ps1 index 93e663d..7e4e9aa 100644 --- a/tests/Item/02_New-CredentialStoreItem.Tests.ps1 +++ b/tests/Item/02_New-CredentialStoreItem.Tests.ps1 @@ -73,29 +73,29 @@ Describe "New-CredentialStoreItem" { } } Context "Test optional parameter lookup" { + $UserName = 'myUser' + $Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force Mock Get-Credential { - return [PSCustomObject]@{ - UserName = 'myUser' - Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force - } - } - It "Test missing Credential" { - $tmpCS = 'C:\CredentialStore.json' - New-CredentialStoreItem -Path $tmpCs -Shared -RemoteHost 'foobar3' - $writtenItem = Get-CredentialStoreItem -Path $tmpCS -Shared -RemoteHost 'foobar3' - $writtenItem.UserName | Should -Be "myUser" + return [PSCredential]::new($UserName, $Password) + } } - Context "General Exception handling" { - Mock Test-CredentialStore {return $false} - Mock Get-Credential { - return [PSCustomObject]@{ - UserName = 'myUser' - Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force - } - } - It "Missing CredentialStore should throw" { - New-CredentialStoreItem -Path 'C:\missingStore.json' -RemoteHost 'notrelevant' | Should -Throw "Could not add anything" - } + It "Test missing Credential" { + $tmpCS = 'C:\CredentialStore.json' + New-CredentialStoreItem -Path $tmpCs -Shared -RemoteHost 'foobar3' + $writtenItem = Get-CredentialStoreItem -Path $tmpCS -Shared -RemoteHost 'foobar3' + $writtenItem.UserName | Should -Be "myUser" + } +} +Context "General Exception handling" { + Mock Test-CredentialStore {return $false} + $UserName = 'myUser' + $Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force + Mock Get-Credential { + return [PSCredential]::new($UserName, $Password) + + } + It "Missing CredentialStore should throw" { + New-CredentialStoreItem -Path 'C:\missingStore.json' -RemoteHost 'notrelevant' | Should -Throw "Could not add anything" } } -- 2.45.2 From 7ab662c860647c81859950265c62315b4e3f3bdd Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 21 Mar 2018 11:40:13 +0100 Subject: [PATCH 31/34] fix scoping issue in test file --- .../Item/02_New-CredentialStoreItem.Tests.ps1 | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/tests/Item/02_New-CredentialStoreItem.Tests.ps1 b/tests/Item/02_New-CredentialStoreItem.Tests.ps1 index 7e4e9aa..4ed64f7 100644 --- a/tests/Item/02_New-CredentialStoreItem.Tests.ps1 +++ b/tests/Item/02_New-CredentialStoreItem.Tests.ps1 @@ -79,23 +79,24 @@ Describe "New-CredentialStoreItem" { return [PSCredential]::new($UserName, $Password) } + It "Test missing Credential" { + $tmpCS = 'C:\CredentialStore.json' + New-CredentialStoreItem -Path $tmpCs -Shared -RemoteHost 'foobar3' + $writtenItem = Get-CredentialStoreItem -Path $tmpCS -Shared -RemoteHost 'foobar3' + $writtenItem.UserName | Should -Be "myUser" + } } - It "Test missing Credential" { - $tmpCS = 'C:\CredentialStore.json' - New-CredentialStoreItem -Path $tmpCs -Shared -RemoteHost 'foobar3' - $writtenItem = Get-CredentialStoreItem -Path $tmpCS -Shared -RemoteHost 'foobar3' - $writtenItem.UserName | Should -Be "myUser" - } -} -Context "General Exception handling" { - Mock Test-CredentialStore {return $false} - $UserName = 'myUser' - $Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force - Mock Get-Credential { - return [PSCredential]::new($UserName, $Password) + Context "General Exception handling" { + Mock Test-CredentialStore {return $false} + $UserName = 'myUser' + $Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force + Mock Get-Credential { + return [PSCredential]::new($UserName, $Password) + } + It "Missing CredentialStore should throw" { + New-CredentialStoreItem -Path 'C:\missingStore.json' -RemoteHost 'notrelevant' | Should -Throw "Could not add anything" + } } - It "Missing CredentialStore should throw" { - New-CredentialStoreItem -Path 'C:\missingStore.json' -RemoteHost 'notrelevant' | Should -Throw "Could not add anything" - } + } -- 2.45.2 From 0417ecd9f61451325bd13d8eae6763a7566f23d8 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 21 Mar 2018 12:02:17 +0100 Subject: [PATCH 32/34] fix pscredential mocking --- tests/Item/02_New-CredentialStoreItem.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Item/02_New-CredentialStoreItem.Tests.ps1 b/tests/Item/02_New-CredentialStoreItem.Tests.ps1 index 4ed64f7..01c6266 100644 --- a/tests/Item/02_New-CredentialStoreItem.Tests.ps1 +++ b/tests/Item/02_New-CredentialStoreItem.Tests.ps1 @@ -73,9 +73,9 @@ Describe "New-CredentialStoreItem" { } } Context "Test optional parameter lookup" { - $UserName = 'myUser' - $Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force Mock Get-Credential { + $UserName = 'testuser' + $Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force return [PSCredential]::new($UserName, $Password) } @@ -83,7 +83,7 @@ Describe "New-CredentialStoreItem" { $tmpCS = 'C:\CredentialStore.json' New-CredentialStoreItem -Path $tmpCs -Shared -RemoteHost 'foobar3' $writtenItem = Get-CredentialStoreItem -Path $tmpCS -Shared -RemoteHost 'foobar3' - $writtenItem.UserName | Should -Be "myUser" + $writtenItem.UserName | Should -Be "testuser" } } Context "General Exception handling" { -- 2.45.2 From 811a83b4bcb5e5d688a30d37a72aa21378b5e9e0 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 21 Mar 2018 12:06:59 +0100 Subject: [PATCH 33/34] fix var scoping in pester test --- tests/Item/02_New-CredentialStoreItem.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Item/02_New-CredentialStoreItem.Tests.ps1 b/tests/Item/02_New-CredentialStoreItem.Tests.ps1 index 01c6266..d81f646 100644 --- a/tests/Item/02_New-CredentialStoreItem.Tests.ps1 +++ b/tests/Item/02_New-CredentialStoreItem.Tests.ps1 @@ -88,9 +88,9 @@ Describe "New-CredentialStoreItem" { } Context "General Exception handling" { Mock Test-CredentialStore {return $false} - $UserName = 'myUser' - $Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force Mock Get-Credential { + $UserName = 'myUser' + $Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force return [PSCredential]::new($UserName, $Password) } -- 2.45.2 From c4a3403a26fa865acf2b696e74deec5a0165e353 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 21 Mar 2018 12:09:05 +0100 Subject: [PATCH 34/34] fix test syntax issue with trhow statement --- tests/Item/02_New-CredentialStoreItem.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Item/02_New-CredentialStoreItem.Tests.ps1 b/tests/Item/02_New-CredentialStoreItem.Tests.ps1 index d81f646..6b711ef 100644 --- a/tests/Item/02_New-CredentialStoreItem.Tests.ps1 +++ b/tests/Item/02_New-CredentialStoreItem.Tests.ps1 @@ -95,7 +95,7 @@ Describe "New-CredentialStoreItem" { } It "Missing CredentialStore should throw" { - New-CredentialStoreItem -Path 'C:\missingStore.json' -RemoteHost 'notrelevant' | Should -Throw "Could not add anything" + { New-CredentialStoreItem -Path 'C:\missingStore.json' -RemoteHost 'notrelevant' } | Should -Throw "Could not add anything" } } -- 2.45.2