Skip to content

Commit

Permalink
Merge pull request #287 from pspete/dev
Browse files Browse the repository at this point in the history
Feature 11.5
  • Loading branch information
pspete authored Jul 14, 2020
2 parents cc954d3 + 061acfd commit 07eee91
Show file tree
Hide file tree
Showing 54 changed files with 2,475 additions and 197 deletions.
52 changes: 50 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,58 @@

## Planned Updates

- Update for PAS 11.5
- Continued development to encompass any new documented features of the CyberArk API.
- Rename `Get-PASPSMConnectionParameter` to something... better.... suggestions welcome.
- psPAS v5.0...

## **4.1.11** (July 14th 2020)

### Module update to cover CyberArk 11.5 API features

- **Behaviour Changes**
- `Get-PASPlatform`
- When invoked with no parameters to return details of all configured platforms, defaults to operation against the endpoint for the 11.4 API.
- When invoked with a value provided for the `Active` parameter, will perform operation against the endpoint for the 11.4 API.
- To utilise the 11.1 api endpoint, a value should be provided for the `PlatformType` and/or `Search` parameters, or, `Active` and `PlatformType` and/or `Search` parameters.
- `New-PASSession`
- Value for OTP will be prompted for if no value is provided for this parameter.
- The prompt will now relay the text of the response from the RADIUS server.

- New Functions
- `Copy-PASPlatform`
- Duplicates target, dependent, group or rotational group platform to a new platform.
- 11.4 functionality, missed in the `4.0.0` release.
- `Disable-PASPlatform`
- Disables, target, group or rotational group platform.
- 11.4 functionality, missed in the `4.0.0` release.
- `Enable-PASPlatform`
- Enables, target, group or rotational group platform.
- 11.4 functionality, missed in the `4.0.0` release.
- `Remove-PASPlatform`
- Deletes, target, dependent, group or rotational group platform.
- 11.4 functionality, missed in the `4.0.0` release.
- `Remove-PASGroup`
- Deletes a specified vault user group
- 11.5 functionality.

- Updated Functions
- `Get-PASPlatform`
- Update to enable query of dependent, group, rotational group platforms
- Update to include additional filters available for querying target platoforms
- 11.4 functionality, missed in the `4.0.0` release.
- Function now defaults to 11.4 target platform endpoint if no parameters are specified.
- `Get-PASUser`
- 11.5 output includes group membership details.
- group membership property may be included in output when function is executed from earlier versions, but its content will be blank.
- `New-PASSession`
- OTP can now be omitted entirely from used parameters in scenarios where the value is unknown.
- Response from RADIUS now used as message for Read-Host prompt for OTP.
- Depreciated need for use of OTPMode parameter when a prompt for the OTP is required.

- Other Fixes & Updates
- Documentation updated.
- Duplicated code for creating the query portion of a URL replaced with new helper function internal to the module.

## **4.0.0** (July 1st 2020)

### Module update to cover CyberArk 11.4 API features
Expand Down Expand Up @@ -594,4 +642,4 @@ _The 1 year since first commit anniversary edition_

## 1.0.6 (February 12 2018)

Published to [PowerShell Gallery](http://powershellgallery.com/packages/psPAS)
Published to [PowerShell Gallery](http://powershellgallery.com/packages/psPAS)
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
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 v11.4.
Contains all published methods of the API up to CyberArk v11.5.

Docs: [https://pspas.pspete.dev](https://pspas.pspete.dev)

Expand Down Expand Up @@ -850,7 +850,12 @@ Check the output of `Get-Help` for the `psPAS` functions for further details of
[`Remove-PASDirectoryMapping`][Remove-PASDirectoryMapping] |**11.1** |Deletes a Directory Mapping
[`Enable-PASCPMAutoManagement`][Enable-PASCPMAutoManagement] |**10.4** |Enables Automatic CPM Management for an account
[`Disable-PASCPMAutoManagement`][Disable-PASCPMAutoManagement] |**10.4** |Disables Automatic CPM Management for an account
[`Test-PASPSMRecording`][Test-PASPSMRecording] | **11.2** |Determine validity of PSM Session Recording
[`Test-PASPSMRecording`][Test-PASPSMRecording] |**11.2** |Determine validity of PSM Session Recording
[`Copy-PASPlatform`][Copy-PASPlatform] |**11.4** |Duplicate a platform
[`Enable-PASPlatform`][Enable-PASPlatform] |**11.4** |Enable a platform
[`Disable-PASPlatform`][Disable-PASPlatform] |**11.4** |Disable a platform
[`Remove-PASPlatform`][Remove-PASPlatform] |**11.4** |Delete a platform
[`Remove-PASGroup`][Remove-PASGroup] |**11.5** |Delete a user group

[New-PASSession]:/psPAS/Functions/Authentication/New-PASSession.ps1
[Close-PASSession]:/psPAS/Functions/Authentication/Close-PASSession.ps1
Expand Down Expand Up @@ -958,6 +963,11 @@ Check the output of `Get-Help` for the `psPAS` functions for further details of
[Get-PASPlatformSafe]:/psPAS/Functions/Platforms/Get-PASPlatformSafe.ps1
[New-PASGroup]:/psPAS/Functions/User/New-PASGroup.ps1
[Test-PASPSMRecording]:/psPAS/Functions/Monitoring/Test-PASPSMRecording.ps1
[Copy-PASPlatform]:psPAS/Functions/Platforms/Copy-PASPlatform.ps1
[Disable-PASPlatform]:psPAS/Functions/Platforms/Disable-PASPlatform.ps1
[Enable-PASPlatform]:psPAS/Functions/Platforms/Enable-PASPlatform.ps1
[Remove-PASPlatform]:psPAS/Functions/Platforms/Remove-PASPlatform.ps1
[Remove-PASGroup]:psPAS/Functions/User/Remove-PASGroup.ps1

## Installation

Expand Down
81 changes: 81 additions & 0 deletions Tests/ConvertTo-QueryString.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
Describe $($PSCommandPath -Replace ".Tests.ps1") {

BeforeAll {
#Get Current Directory
$Here = Split-Path -Parent $PSCommandPath

#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

}

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

}


AfterAll {

$Script:RequestBody = $null

}

InModuleScope $(Split-Path (Split-Path (Split-Path -Parent $PSCommandPath) -Parent) -Leaf ) {

Context "General" {

BeforeEach {

$InputObj = @{
Property1 = "Value"
Property2 = "Another Value"
}

}

It "does not throw" {

{ ConvertTo-QueryString } | Should -Not -Throw

}

It "produces no output if given no input" {

ConvertTo-QueryString | Should -BeNullOrEmpty

}

It "converts hashtable to expected query string" {

$InputObj | ConvertTo-QueryString | Should -Match "Value&Property"
$InputObj | ConvertTo-QueryString | Should -Match "Property1=Value"
$InputObj | ConvertTo-QueryString | Should -Match "Property2=Another%20Value"

}

It "converts hashtable to expected filter string" {

$InputObj | ConvertTo-QueryString -Format Filter | Should -Match "%20AND%20"
$InputObj | ConvertTo-QueryString -Format Filter | Should -Match "Property1%20eq%20Value"
$InputObj | ConvertTo-QueryString -Format Filter | Should -Match "Property2%20eq%20Another%20Value"

}

}

}

}
181 changes: 181 additions & 0 deletions Tests/Copy-PASPlatform.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
Describe $($PSCommandPath -Replace ".Tests.ps1") {

BeforeAll {
#Get Current Directory
$Here = Split-Path -Parent $PSCommandPath

#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

}

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

}


AfterAll {

$Script:RequestBody = $null

}

InModuleScope $(Split-Path (Split-Path (Split-Path -Parent $PSCommandPath) -Parent) -Leaf ) {

Context "Mandatory Parameters" {

$Parameters = @{Parameter = 'TargetPlatform' },
@{Parameter = 'DependentPlatform' },
@{Parameter = 'GroupPlatform' },
@{Parameter = 'RotationalGroup' },
@{Parameter = 'ID' },
@{Parameter = 'name' }

It "specifies parameter <Parameter> as mandatory" -TestCases $Parameters {

param($Parameter)

(Get-Command Copy-PASPlatform).Parameters["$Parameter"].Attributes.Mandatory | Should -Be $true

}

}

Context "Input" {

BeforeEach {
Mock Invoke-PASRestMethod -MockWith {
[PSCustomObject]@{"Prop1" = "Val1"; "Prop2" = "Val2" }
}

$InputObj = [pscustomobject]@{
"name" = "SomeName"
"ID" = 1234
}

$response = $InputObj | Copy-PASPlatform -TargetPlatform

}

It "sends request" {

Assert-MockCalled Invoke-PASRestMethod -Times 1 -Exactly -Scope It

}

It "sends request to expected endpoint - TargetPlatform" {

Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {

$URI -eq "$($Script:BaseURI)/API/Platforms/targets/1234/duplicate"

} -Times 1 -Exactly -Scope It

}

It "sends request to expected endpoint - DependentPlatform" {
$response = $InputObj | Copy-PASPlatform -DependentPlatform
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {

$URI -eq "$($Script:BaseURI)/API/Platforms/dependents/1234/duplicate"

} -Times 1 -Exactly -Scope It

}

It "sends request to expected endpoint - RotationalGroup" {

$response = $InputObj | Copy-PASPlatform -RotationalGroup
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {

$URI -eq "$($Script:BaseURI)/API/Platforms/rotationalGroups/1234/duplicate"

} -Times 1 -Exactly -Scope It

}

It "sends request to expected endpoint - GroupPlatform" {

$response = $InputObj | Copy-PASPlatform -GroupPlatform
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {

$URI -eq "$($Script:BaseURI)/API/Platforms/groups/1234/duplicate"

} -Times 1 -Exactly -Scope It

}

It "uses expected method" {

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

}

It "sends request with expected body" {

Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {

$Script:RequestBody = $Body | ConvertFrom-Json

($Script:RequestBody) -ne $null

} -Times 1 -Exactly -Scope It

}

It "has a request body with expected number of properties" {

($Script:RequestBody | Get-Member -MemberType NoteProperty).length | Should -Be 1

}

It "throws error if version requirement not met" {
$Script:ExternalVersion = "11.0"
{ $InputObj | Copy-PASPlatform -GroupPlatform } | Should -Throw
$Script:ExternalVersion = "0.0"
}

}

Context "Output" {

BeforeEach {

$Script:ExternalVersion = "11.4"
Mock Invoke-PASRestMethod -MockWith {
[PSCustomObject]@{"Prop1" = "Val1"; "Prop2" = "Val2" }
}

$InputObj = [pscustomobject]@{
"name" = "SomeName"
"ID" = 1234
}

$response = $InputObj | Copy-PASPlatform -TargetPlatform

}

it "provides output" {

$response | Should -Not -BeNullOrEmpty

}

}

}

}
Loading

0 comments on commit 07eee91

Please sign in to comment.