Skip to content

Commit

Permalink
Merge pull request #221 from pspete/11_1-UserFunctions
Browse files Browse the repository at this point in the history
11.1 user functions
  • Loading branch information
pspete committed Nov 30, 2019
2 parents 71a201d + f7b1540 commit e9d06f7
Show file tree
Hide file tree
Showing 9 changed files with 1,020 additions and 75 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -4,7 +4,7 @@

Use PowerShell to manage CyberArk via the Web Services REST API.

Contains all published methods of the API up to CyberArk v10.10.
Contains all published methods of the API up to CyberArk v11.1.

**Existing psPAS Users**: Module Version 3.0 introduced breaking changes; review the [Changelog](CHANGELOG.md) for full details.

Expand Down
3 changes: 3 additions & 0 deletions Tests/New-PASDirectoryMapping.Tests.ps1
Expand Up @@ -103,16 +103,19 @@ Describe $FunctionName {
It "throws error if version requirement not met" {
$Script:ExternalVersion = "10.6"
{ $InputObj | New-PASDirectoryMapping -VaultGroups "Group1", "Group2" } | Should -Throw
$Script:ExternalVersion = "0.0"
}

It "throws error if version requirement not met" {
$Script:ExternalVersion = "10.9"
{ $InputObj | New-PASDirectoryMapping -RestoreAllSafes -BackupAllSafes -VaultGroups "Group1", "Group2" -UserActivityLogPeriod 10 } | Should -Throw
$Script:ExternalVersion = "0.0"
}

It "does not throw if version requirement met" {
$Script:ExternalVersion = "10.10"
{ $InputObj | New-PASDirectoryMapping -RestoreAllSafes -BackupAllSafes -VaultGroups "Group1", "Group2" -UserActivityLogPeriod 10 } | Should -Not -Throw
$Script:ExternalVersion = "0.0"
}

}
Expand Down
139 changes: 139 additions & 0 deletions Tests/New-PASGroup.Tests.ps1
@@ -0,0 +1,139 @@
#Get Current Directory
$Here = Split-Path -Parent $MyInvocation.MyCommand.Path

#Get Function Name
$FunctionName = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -Replace ".Tests.ps1"

#Assume ModuleName from Repository Root folder
$ModuleName = Split-Path (Split-Path $Here -Parent) -Leaf

#Resolve Path to Module Directory
$ModulePath = Resolve-Path "$Here\..\$ModuleName"

#Define Path to Module Manifest
$ManifestPath = Join-Path "$ModulePath" "$ModuleName.psd1"

if ( -not (Get-Module -Name $ModuleName -All)) {

Import-Module -Name "$ManifestPath" -ArgumentList $true -Force -ErrorAction Stop

}

BeforeAll {

$Script:RequestBody = $null
$Script:BaseURI = "https://SomeURL/SomeApp"
$Script:ExternalVersion = "0.0"
$Script:WebSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession

}

AfterAll {

$Script:RequestBody = $null

}

Describe $FunctionName {

InModuleScope $ModuleName {

Context "Input" {

BeforeEach {

Mock Invoke-PASRestMethod -MockWith { }

$InputObject = [PSCustomObject]@{
GroupName = "SomeGroup"
Description = "Some Description"
Location = "\Some\Location"
}

}

It "sends request" {
$InputObject | New-PASGroup
Assert-MockCalled Invoke-PASRestMethod -Times 1 -Exactly -Scope It

}

It "sends request to expected endpoint" {
$InputObject | New-PASGroup
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {

$URI -eq "$($Script:BaseURI)/API/UserGroups"

} -Times 1 -Exactly -Scope It

}

It "uses expected method" {
$InputObject | New-PASGroup
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter { $Method -match 'POST' } -Times 1 -Exactly -Scope It

}

It "sends request with expected body" {
New-PASGroup -groupName SomeGroup -description "Some Description" -location "/Some/Location"
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {

$Body -ne $null

} -Times 1 -Exactly -Scope It

}

It "throws error if version requirement not met" {
$Script:ExternalVersion = "1.2"

{ $InputObject | New-PASGroup } | Should throw

$Script:ExternalVersion = "0.0"

}

}

Context "Output" {

BeforeEach {

$InputObject = [PSCustomObject]@{
GroupName = "SomeGroup"
Description = "Some Description"
Location = "\Some\Location"
}

Mock Invoke-PASRestMethod -MockWith {
[pscustomobject]@{
"Prop1" = "Value1"
"Prop2" = "Value2"
"Prop3" = "Value3"
"Prop4" = "Value4"
}
}

}

it "provides output" {

$response = $InputObject | New-PASGroup
$response | Should not BeNullOrEmpty

}

It "has output with expected number of properties" {

$response = $InputObject | New-PASGroup
($response | Get-Member -MemberType NoteProperty).length | Should Be 4

}



}

}

}
34 changes: 22 additions & 12 deletions Tests/Remove-PASUser.Tests.ps1
Expand Up @@ -43,7 +43,7 @@ Describe $FunctionName {
}

$InputObj = [pscustomobject]@{
"UserName" = "ThatUser"
"UserName" = "ThatUser"

}

Expand All @@ -61,35 +61,45 @@ Describe $FunctionName {

}

$response = $InputObj | Remove-PASUser


Context "Input" {

It "sends request" {

Assert-MockCalled Invoke-PASRestMethod -Times 1 -Exactly -Scope Describe
$InputObj | Remove-PASUser
Assert-MockCalled Invoke-PASRestMethod -Times 1 -Exactly -Scope It

}

It "sends request to expected endpoint" {

It "sends request to expected endpoint - Classic API" {
$InputObj | Remove-PASUser
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {

$URI -eq "$($Script:BaseURI)/WebServices/PIMServices.svc/Users/ThatUser"

} -Times 1 -Exactly -Scope Describe
} -Times 1 -Exactly -Scope It

}

It "uses expected method" {
It "sends request to expected endpoint - V2 API" {
Remove-PASUser -id 1234
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {

$URI -eq "$($Script:BaseURI)/api/Users/1234"

Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {$Method -match 'DELETE' } -Times 1 -Exactly -Scope Describe
} -Times 1 -Exactly -Scope It

}

It "sends request with no body" {
It "uses expected method" {
$InputObj | Remove-PASUser
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter { $Method -match 'DELETE' } -Times 1 -Exactly -Scope It

Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {$Body -eq $null} -Times 1 -Exactly -Scope Describe
}

It "sends request with no body" {
$InputObj | Remove-PASUser
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter { $Body -eq $null } -Times 1 -Exactly -Scope It

}

Expand All @@ -98,7 +108,7 @@ Describe $FunctionName {
Context "Output" {

it "provides no output" {

$response = $InputObj | Remove-PASUser
$response | Should BeNullOrEmpty

}
Expand Down

0 comments on commit e9d06f7

Please sign in to comment.