Skip to content

Commit

Permalink
UPDATE Tests
Browse files Browse the repository at this point in the history
Existing pester tests ammended for Get-PASAccountGroup, Get-PASDirectory, Get-PASPSMConnectionParameter, New-PASSession.

Relates to #109
  • Loading branch information
pspete committed Oct 31, 2018
1 parent e6d8ccb commit a503893
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
18 changes: 17 additions & 1 deletion Tests/Get-PASAccountGroup.Tests.ps1
Expand Up @@ -64,7 +64,7 @@ Describe $FunctionName {

}

$response = $InputObj | Get-PASAccountGroup -verbose
$response = $InputObj | Get-PASAccountGroup -UseV9API -verbose

Context "Input" {

Expand Down Expand Up @@ -100,6 +100,22 @@ Describe $FunctionName {
{$InputObj | Get-PASAccountGroup -ExternalVersion "1.0"} | Should Throw
}

It "sends request to expected endpoint - V10 ParameterSet" {

$InputObj | Get-PASAccountGroup -safe "SomeSafe" -verbose

Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {

$URI -eq "$($InputObj.BaseURI)/$($InputObj.PVWAAppName)/API/Safes/SomeSafe/AccountGroups"

} -Times 1 -Exactly -Scope It

}

It "throws error if version requirement not met" {
{$InputObj | Get-PASAccountGroup -safe "SomeSafe" -ExternalVersion 1.1} | Should Throw
}

}

Context "Output" {
Expand Down
4 changes: 2 additions & 2 deletions Tests/Get-PASDirectory.Tests.ps1
Expand Up @@ -62,7 +62,7 @@ Describe $FunctionName {

}

$response = $InputObj | Get-PASDirectory
$response = $InputObj | Get-PASDirectory -id SomeDir

Context "Input" {

Expand All @@ -76,7 +76,7 @@ Describe $FunctionName {

Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {

$URI -eq "$($InputObj.BaseURI)/$($InputObj.PVWAAppName)/api/Configuration/LDAP/Directories"
$URI -eq "$($InputObj.BaseURI)/$($InputObj.PVWAAppName)/api/Configuration/LDAP/Directories/SomeDir/"

} -Times 1 -Exactly -Scope Describe

Expand Down
32 changes: 30 additions & 2 deletions Tests/Get-PASPSMConnectionParameter.Tests.ps1
Expand Up @@ -49,6 +49,19 @@ Describe $FunctionName {

}

$AdHocObj = [pscustomobject]@{
"sessionToken" = @{"Authorization" = "P_AuthValue"}
"WebSession" = New-Object Microsoft.PowerShell.Commands.WebRequestSession
"BaseURI" = "https://P_URI"
"PVWAAppName" = "P_App"
"ConnectionComponent" = "SomeConnectionComponent"
"UserName" = "SomeUser"
"secret" = "SomeSecret" | ConvertTo-SecureString -AsPlainText -Force
"address" = "Some.Address"
"platformID" = "SomePlatform"

}

Context "Mandatory Parameters" {

$Parameters = @{Parameter = 'BaseURI'},
Expand All @@ -60,7 +73,7 @@ Describe $FunctionName {

param($Parameter)

(Get-Command Get-PASPSMConnectionParameter).Parameters["$Parameter"].Attributes.Mandatory | Should Be $true
(Get-Command Get-PASPSMConnectionParameter).Parameters["$Parameter"].Attributes.Mandatory | Select-Object -Unique | Should Be $true

}

Expand All @@ -76,7 +89,7 @@ Describe $FunctionName {

}

It "sends request to expected endpoint" {
It "sends request to expected endpoint for PSMConnect" {

Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {

Expand Down Expand Up @@ -136,6 +149,21 @@ Describe $FunctionName {
{$InputObj | Get-PASPSMConnectionParameter -ConnectionMethod PSMGW -ExternalVersion "9.10"} | Should Throw
}

It "sends request to expected endpoint for AdHocConnect" {

$AdHocObj | Get-PASPSMConnectionParameter -ConnectionMethod RDP
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {

$URI -eq "$($InputObj.BaseURI)/$($InputObj.PVWAAppName)/API/Accounts/AdHocConnect"

} -Times 1 -Exactly -Scope It

}

It "throws error if version requirement not met for AdHocConnect" {
{$AdHocObj | Get-PASPSMConnectionParameter -ConnectionMethod PSMGW -ExternalVersion "10.4"} | Should Throw
}

}

Context "Output" {
Expand Down
13 changes: 13 additions & 0 deletions Tests/New-PASSession.Tests.ps1
Expand Up @@ -173,6 +173,17 @@ Describe $FunctionName {

}

It "sends request to expected v10 URL for WINDOWS Authentication" {

$response = New-PASSession -BaseURI "https://P_URI" -UseDefaultCredentials
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {

$URI -eq "https://P_URI/PasswordVault/api/Auth/Windows/Logon"

} -Times 1 -Exactly -Scope It

}

It "calls Get-PASServer" {

$response = $Credentials | New-PASSession -BaseURI "https://P_URI" -type LDAP
Expand All @@ -187,6 +198,8 @@ Describe $FunctionName {

}



}

Context "Output" {
Expand Down

0 comments on commit a503893

Please sign in to comment.