Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from pspete/feature_session-info
Add Session Functions
- Loading branch information
Showing
13 changed files
with
299 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#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 { | ||
|
||
Mock Get-PASLoggedOnUser -MockWith { | ||
[PSCustomObject]@{"Username" = "SomeUser"; "Prop2" = "Val2" } | ||
} | ||
|
||
$response = Get-PASSession | ||
|
||
Context "Standard Operation" { | ||
|
||
it "provides output" { | ||
|
||
$response | Should not BeNullOrEmpty | ||
|
||
} | ||
|
||
It "has output with expected number of properties" { | ||
|
||
($response | Get-Member -MemberType NoteProperty).length | Should Be 4 | ||
|
||
} | ||
|
||
it "outputs object with expected typename" { | ||
|
||
$response | get-member | select-object -expandproperty typename -Unique | Should Be psPAS.CyberArk.Vault.Session | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#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 | ||
|
||
} | ||
|
||
AfterAll { | ||
|
||
$Script:RequestBody = $null | ||
|
||
} | ||
|
||
Describe $FunctionName { | ||
|
||
InModuleScope $ModuleName { | ||
|
||
Context "Standard Operation" { | ||
|
||
BeforeEach { | ||
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession | ||
$session.Headers["Test"] = "SomeValue" | ||
|
||
$InputObject = [PSCustomObject]@{ | ||
PSTypeName = 'psPAS.CyberArk.Vault.Session' | ||
User = "SomeUser" | ||
BaseURI = "SomeURL" | ||
ExternalVersion = "6.6" | ||
WebSession = $session | ||
} | ||
|
||
} | ||
|
||
it "invokes set-variable the expected number of times" { | ||
Mock Set-Variable -MockWith { } | ||
Use-PASSession -Session $InputObject | ||
Assert-MockCalled Set-Variable -Times 3 -Exactly -Scope It | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
function Get-PASSession { | ||
<# | ||
.SYNOPSIS | ||
Returns information related to the authenticated session | ||
.DESCRIPTION | ||
For the current session, returns data from the module scope: | ||
- Username relating to the session. | ||
- BaseURI: URL value used for sending requests to the API. | ||
- ExternalVersion: PAS version information. | ||
- Websession: Contains Authorization Header, Cookie & Certificate data related to the current session. | ||
The session information can be saved a variable accessible outside of the module scope for use in requests outside of psPAS. | ||
.EXAMPLE | ||
Show current session related information | ||
Get-PASSession | ||
.EXAMPLE | ||
Save current session related information | ||
$session = Get-PASSession | ||
.EXAMPLE | ||
Use session information for Invoke-RestMethod command | ||
$session = Get-PASSession | ||
Invoke-RestMethod | ||
Invoke-RestMethod -Method GET -Uri "$session.BaseURI/SomePath" -WebSession $session.WebSession | ||
#> | ||
[CmdletBinding()] | ||
param( ) | ||
|
||
BEGIN { }#begin | ||
|
||
PROCESS { | ||
|
||
[PSCustomObject]@{ | ||
User = Get-PASLoggedOnUser -ErrorAction Stop | Select-Object -ExpandProperty Username | ||
BaseURI = $Script:BaseURI | ||
ExternalVersion = $Script:ExternalVersion | ||
WebSession = $Script:WebSession | ||
} | Add-ObjectDetail -typename psPAS.CyberArk.Vault.Session | ||
|
||
}#process | ||
|
||
END { }#end | ||
|
||
} |
Oops, something went wrong.