Publish Pre-release (#1)
* adds basic module layout * fix module manifest encoding * fix callsign in appveyor helper * adds challenge file related functions * adds connection manager functions * adds Test-ChallengeFile * adds item related functions * adds store related functions * adds cSpell dictionary * adds CredentialStore related Pester tests * [WIP] test Pester file * fix typo * adds file dependencies * [WIP] fix pester tests * fix exception state * [WIP] add file dependencies * fix gitkeep filename * set constant debug module version string * adds Pester Tests for New-CredentialStoreItem * adds basic readme file * adds functions to export; adds meta data * adds vscode debug config * adds test for optional dependencies * [WIP] Implements optional dependency test * adds taskrunner definitions * adds CBH * add gitignore file * adds basic Build tasks * typo fixed * adds build folder to ignore list * adds Cisco and NetApp opt dependencies * adds build task * fix end of line dequence * remove task.json error * adds sources for optional modules * enables Pester and posh-git * prepare pre-release
This commit is contained in:
0
tests/.gitkeep
Normal file
0
tests/.gitkeep
Normal file
65
tests/Item/01_New-CredentialStoreItem.Tests.ps1
Normal file
65
tests/Item/01_New-CredentialStoreItem.Tests.ps1
Normal file
@ -0,0 +1,65 @@
|
||||
#region HEADER
|
||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
# $RepoRoot = (Get-Item -Path $here).Parent.Parent.FullName
|
||||
$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 <FunctionName>.
|
||||
. (Get-ChildItem -Path $RepoRoot -Filter "Test-CredentialStore.ps1" -Recurse).FullName
|
||||
. (Get-ChildItem -Path $RepoRoot -Filter "New-CredentialStore.ps1" -Recurse).FullName
|
||||
. (Get-ChildItem -Path $RepoRoot -Filter "Get-CredentialStore.ps1" -Recurse).FullName
|
||||
. (Get-ChildItem -Path $RepoRoot -Filter "Get-CredentialStoreItem.ps1" -Recurse).FullName
|
||||
. (Get-ChildItem -Path $RepoRoot -Filter "Test-ChallengeFile.ps1" -Recurse).FullName
|
||||
. (Get-ChildItem -Path $RepoRoot -Filter "Get-ChallengeFile.ps1" -Recurse).FullName
|
||||
. (Get-ChildItem -Path $RepoRoot -Filter "Set-ChallengeFile.ps1" -Recurse).FullName
|
||||
. (Get-ChildItem -Path $RepoRoot -Filter "Get-RandomKey.ps1" -Recurse).FullName
|
||||
|
||||
#endregion HEADER
|
||||
|
||||
Describe "New-CredentialStoreItem" {
|
||||
Context "Private Credential Store tests" {
|
||||
It "Test1: Add entry to existing private store." {
|
||||
If (-not (Test-CredentialStore)) {
|
||||
New-CredentialStore
|
||||
}
|
||||
[String]$tmp = (65..90) + (97..122) | Get-Random -Count 5 | % {[char]$_}
|
||||
$tmp = $tmp.Replace(' ', '')
|
||||
$tmpUser = "MyUser"
|
||||
$tmpPwd = "fooobarysdfsfs" | ConvertTo-SecureString -AsPlainText -Force
|
||||
$creds = New-Object -TypeName PsCredential -ArgumentList $tmpUser, $tmpPwd
|
||||
New-CredentialStoreItem -RemoteHost $tmp -Credential $creds
|
||||
# Had to remove the `{ <exp> } | Shoud Not Throw` because the return would be empty.
|
||||
$content = Get-CredentialStoreItem -RemoteHost $tmp
|
||||
$content.UserName | Should Be "MyUser"
|
||||
#Cleanup Temp entry
|
||||
$CS = Get-CredentialStore
|
||||
$CS.PSObject.Properties.Remove($tmp)
|
||||
ConvertTo-Json -InputObject $CS | Out-File -FilePath ("{0}\CredentialStore.json" -f $env:AppData)
|
||||
}
|
||||
}
|
||||
Context "Test with new shared Credential Store" {
|
||||
It "Test2: Create new RemoteHost entry" {
|
||||
# prepare test environment
|
||||
$tmpCS = 'C:\CredentialStore.json'
|
||||
New-CredentialStore -Shared -Path $tmpCS
|
||||
|
||||
$UserName = "myuser"
|
||||
$Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force
|
||||
$mycreds = New-Object -TypeName PSCredential -ArgumentList $UserName, $Password
|
||||
$RemoteHost = "foobar"
|
||||
{ New-CredentialStoreItem -Path $tmpCS -RemoteHost $RemoteHost -Credential $mycreds -Shared } | Should Not Throw
|
||||
$tmpCS = Get-Content -Path $tmpCS -Raw | ConvertFrom-Json
|
||||
$res = Get-Member -InputObject $tmpCS -Name $RemoteHost -Membertype Properties
|
||||
$res.Name | Should Be $RemoteHost
|
||||
}
|
||||
}
|
||||
}
|
37
tests/Store/00_Get-CredentialStore.Tests.ps1
Normal file
37
tests/Store/00_Get-CredentialStore.Tests.ps1
Normal file
@ -0,0 +1,37 @@
|
||||
#region HEADER
|
||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
# $RepoRoot = (Get-Item -Path $here).Parent.Parent.FullName
|
||||
$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 <FunctionName>.
|
||||
. (Get-ChildItem -Path $RepoRoot -Filter "Test-CredentialStore.ps1" -Recurse).FullName
|
||||
|
||||
#endregion HEADER
|
||||
|
||||
Describe "Get-CredentialStore" {
|
||||
Context "Basic logic tests" {
|
||||
$TestCredentialStore = Resolve-Path -Path ("{0}\resources\cs\CredentialStore.json" -f $RepoRoot)
|
||||
It "Test1: Read CS without params" {
|
||||
If (Test-Path -Path ("{0}\CredentialStore.json" -f $env:APPDATA)) {
|
||||
{Get-CredentialStore} | Should Not Throw
|
||||
}
|
||||
Else {
|
||||
Write-Warning "Default private Credential Store not found. Skipping..."
|
||||
}
|
||||
}
|
||||
It "Test2: Read Credential Store with testing data" {
|
||||
|
||||
{Get-CredentialStore -Path $TestCredentialStore} | Should Not Throw
|
||||
}
|
||||
}
|
||||
}
|
114
tests/Store/00_New-CredentialStore.Tests.ps1
Normal file
114
tests/Store/00_New-CredentialStore.Tests.ps1
Normal file
@ -0,0 +1,114 @@
|
||||
#region HEADER
|
||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
# $RepoRoot = (Get-Item -Path $here).Parent.Parent.FullName
|
||||
$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 <FunctionName>.
|
||||
. (Get-ChildItem -Path $RepoRoot -Filter "Test-CredentialStore.ps1" -Recurse).FullName
|
||||
. (Get-ChildItem -Path $RepoRoot -Filter "Test-ChallengeFile.ps1" -Recurse).FullName
|
||||
. (Get-ChildItem -Path $RepoRoot -Filter "Set-ChallengeFile.ps1" -Recurse).FullName
|
||||
. (Get-ChildItem -Path $RepoRoot -Filter "Get-RandomKey.ps1" -Recurse).FullName
|
||||
|
||||
#endregion HEADER
|
||||
|
||||
|
||||
# Backup existing credential stores
|
||||
$VerbosePreference = "Continue"
|
||||
Write-Verbose "Backup private Credential Store..."
|
||||
$CSPath = ("{0}\CredentialStore.json" -f $env:APPDATA)
|
||||
$BackupFile = "{0}.back" -f $CSPath
|
||||
If (Test-Path -Path $CSPath) {
|
||||
Move-Item -Path $CSPath -Destination $BackupFile
|
||||
}
|
||||
Write-Verbose "Backup shared CredentialStore..."
|
||||
$CSShared = ("{0}\PSCredentialStore\CredentialStore.json" -f $env:ProgramData)
|
||||
$BackupSharedFile = "{0}.back" -f $CSShared
|
||||
If (Test-Path -Path $CSShared) {
|
||||
Move-Item -Path $CSShared -Destination $BackupSharedFile
|
||||
}
|
||||
Write-Verbose "Remove old CredentialStore in Temp dir"
|
||||
$CSTemp = "{0}\CredentialStore.json" -f $Env:TEMP
|
||||
If (Test-Path -Path $CSTemp) {
|
||||
Remove-Item -Path $CSTemp
|
||||
}
|
||||
$VerbosePreference = "SilentlyContinue"
|
||||
|
||||
Describe "New-CredentialStore" {
|
||||
Context "Private CS tests" {
|
||||
$pCS = Join-Path -Path $env:APPDATA -ChildPath "CredentialStore.json"
|
||||
It "Test1: Create new private CredentialStore" {
|
||||
New-CredentialStore
|
||||
$result = Test-Path -Path $pCS
|
||||
$CS = Get-Content -Path $pCS -Raw | ConvertFrom-Json -ErrorAction SilentlyContinue
|
||||
($result -eq $True) -and ($CS.Type -eq "Private") | Should Be $True
|
||||
}
|
||||
It "Test2: Try to override private Store" {
|
||||
{New-CredentialStore} | Should Throw
|
||||
}
|
||||
It "Test3: Reset existing Credential Store" {
|
||||
$now = Get-Date
|
||||
$CS = Get-Content -Path $pCS -Raw | ConvertFrom-Json
|
||||
$CSCreation = [DateTime]$CS.Creation
|
||||
New-CredentialStore -Force
|
||||
$now -gt $csCreation | Should Be $True
|
||||
}
|
||||
}
|
||||
Context "Shared CS tests" {
|
||||
$pCS = Join-Path -Path $env:ProgramData -ChildPath "PSCredentialStore\CredentialStore.json"
|
||||
It "Test1: Create a new Shared Credential Store" {
|
||||
New-CredentialStore -Shared
|
||||
Test-Path -Path ("{0}\PSCredentialStore\CredentialStore.json" -f $env:ProgramData) | Should Be $True
|
||||
}
|
||||
It "Test2: Try to override existing shared CS" {
|
||||
{New-CredentialStore -Shared} | Should Throw
|
||||
}
|
||||
It "Test3: Reset shared CredentialStore" {
|
||||
$now = Get-Date
|
||||
$CS = Get-Content -Path $pCS -Raw | ConvertFrom-Json
|
||||
$CSCreation = [DateTime]$CS.Creation
|
||||
New-CredentialStore -Force -Shared
|
||||
$now -gt $csCreation | Should Be $True
|
||||
}
|
||||
}
|
||||
Context "Custom Shared CS tests" {
|
||||
$pCS = Join-Path -Path $env:TEMP -ChildPath "CredentialStore.json"
|
||||
It "Test1: Create new custom shared" {
|
||||
{New-CredentialStore -Path $pCS -Shared} | Should Not Throw
|
||||
}
|
||||
It "Test2: Try to override exiting one" {
|
||||
{New-CredentialStore -Path $pCS -Shared} | Should Throw
|
||||
}
|
||||
It "Test3: Reset existing custom CredentialStore" {
|
||||
{New-CredentialStore -Path $pCS -Shared -Force} | Should Not Throw
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Cleanup test stores and restore existing ones.
|
||||
$VerbosePreference = "Continue"
|
||||
Write-Verbose "Restoring private CredentialStore"
|
||||
If (Test-Path -Path $BackupFile) {
|
||||
If (Test-Path -Path $CSPath) {
|
||||
Remove-Item -Path $CSPath
|
||||
Move-Item -Path $BackupFile -Destination $CSPath
|
||||
}
|
||||
}
|
||||
|
||||
Write-Verbose "Restoring shared CredentialStore"
|
||||
If (Test-Path -Path $BackupSharedFile) {
|
||||
If (Test-Path -Path $CSShared) {
|
||||
Remove-Item -Path $CSShared
|
||||
Move-Item -Path $BackupSharedFile -Destination $CSShared
|
||||
}
|
||||
}
|
||||
$VerbosePreference = "SilentlyContinue"
|
40
tests/Store/00_Test-CredentialStore.Tests.ps1
Normal file
40
tests/Store/00_Test-CredentialStore.Tests.ps1
Normal file
@ -0,0 +1,40 @@
|
||||
#region HEADER
|
||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
# $RepoRoot = (Get-Item -Path $here).Parent.Parent.FullName
|
||||
$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 <FunctionName>.
|
||||
# . (Get-ChildItem -Path $RepoRoot -Filter "<Function-Name>.ps1" -Recurse).FullName
|
||||
|
||||
#endregion HEADER
|
||||
|
||||
Describe "Test-CredentialStore" {
|
||||
Context "Basic logic tests" {
|
||||
$TestCredentialStore = Resolve-Path -Path ("{0}\resources\cs\CredentialStore.json" -f $RepoRoot)
|
||||
It "Test1: Should Not Throw" {
|
||||
{ Test-CredentialStore -Path $TestCredentialStore } | Should Not Throw
|
||||
}
|
||||
It "Test2: Read valid CredentialStore" {
|
||||
$res = Test-CredentialStore -Path $TestCredentialStore
|
||||
$res | Should Be $True
|
||||
}
|
||||
It "Test3: Read a broken CredentialStore" {
|
||||
$BrokenCS = Resolve-Path -Path ("{0}\resources\cs\Broken_CS.json" -f $RepoRoot)
|
||||
$oWarningPreference = $WarningPreference
|
||||
$WarningPreference = 'SilentlyContinue'
|
||||
$res = Test-CredentialStore -Path $BrokenCS
|
||||
$res | Should Be $False
|
||||
$WarningPreference = $oWarningPreference
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user