-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lets you test the config and checks to match SS host
- Loading branch information
Showing
2 changed files
with
118 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
function Test-SdkClient { | ||
<# | ||
.SYNOPSIS | ||
Test the SDK Client configuration based on the ConfigPath | ||
.DESCRIPTION | ||
Test the SDK Client configuration based on the ConfigPath. | ||
Based on status message returned: | ||
- "Connected to endpoint <Secret Server URL>" = true | ||
- "Not connected" = false | ||
.EXAMPLE | ||
Test-TssSdkClient -SecretServer 'http://alpha.local/SecretServer' -RuleName tss_module -ConfigPath $env:HOME | ||
On Ubuntu 20.04 client, will test SDK Client configuration and return true if connected | ||
.EXAMPLE | ||
Test-TssSdkClient -SecretServer 'http://alpha.local/SecretServer' -RuleName tss_module -ConfigPath c:\thycotic -Force | ||
Tests SDK Client configuration and return true if connected | ||
.LINK | ||
https://thycotic-ps.github.io/thycotic.secretserver/commands/Test-TssSdkClient | ||
.LINK | ||
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/Test-SdkClient.ps1 | ||
.NOTES | ||
Secret Server docs cover configuring Application Account and SDK Client rule | ||
https://docs.thycotic.com/ss/10.9.0/api-scripting/sdk-cli/index.md#task_1__configuring_secret_server | ||
#> | ||
[cmdletbinding()] | ||
param( | ||
# Secret Server | ||
[Parameter(Mandatory)] | ||
[string] | ||
$SecretServer, | ||
|
||
# Config path for the key/config files, no folder names with spaces allowed | ||
[Parameter(Mandatory)] | ||
[ValidateScript( { Test-Path $_ -PathType Container })] | ||
[ValidateScript( { $_ -notmatch '\s' })] | ||
[string] | ||
$ConfigPath | ||
) | ||
begin { | ||
$tssParams = $PSBoundParameters | ||
$tssExe = [IO.Path]::Combine([string]$PSModuleRoot, 'bin', 'tss.exe') | ||
|
||
if ($IsLinux) { | ||
Write-Verbose 'SDK Client, tss utility, has some dependencies required on certain Linux distributions, more details: https://docs.thycotic.com/ss/10.9.0/api-scripting/sdk-cli#task_2__installing_the_sdk_client' | ||
} | ||
} | ||
process { | ||
Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)" | ||
|
||
$tssArgs = [ordered]@{} | ||
$tssArgs.ConfigDirectory = "--key-directory $ConfigPath --config-directory $ConfigPath" | ||
|
||
$tssStatusArgs = "status $($tssArgs['ConfigDirectory'])" | ||
Write-Verbose "arguments for tss status: $tssStatusArgs" | ||
try { | ||
$tssInitInfo = New-Object System.Diagnostics.ProcessStartInfo | ||
$tssInitInfo.FileName = $tssExe | ||
$tssInitInfo.Arguments = $tssStatusArgs | ||
$tssInitInfo.RedirectStandardError = $true | ||
$tssInitInfo.RedirectStandardOutput = $true | ||
$tssInitInfo.UseShellExecute = $false | ||
$tssProcess = New-Object System.Diagnostics.Process | ||
$tssProcess.StartInfo = $tssInitInfo | ||
$tssProcess.Start() | Out-Null | ||
$tssProcess.WaitForExit() | ||
$tssStatusOutput = $tssProcess.StandardOutput.ReadToEnd() | ||
$tssStatusOutput += $tssProcess.StandardError.ReadToEnd() | ||
|
||
Write-Verbose "SDK Client raw output: $tssStatusOutput" | ||
if ($tssStatusOutput -eq "Connected to endpoint") { | ||
if ($tssStatusOutput -match $SecretServer) { | ||
return $true | ||
} else { | ||
return $false | ||
} | ||
} | ||
if ($tssInitOutput -eq 'Not connected') { | ||
return $false | ||
} | ||
} catch { | ||
Write-Warning "Issue checking status of SDK Client (tss) for [$SecretServer]" | ||
Write-Error $_ | ||
$err = $_ | ||
. $ErrorHandling $err | ||
} | ||
} | ||
} |
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,24 @@ | ||
BeforeDiscovery { | ||
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf | ||
} | ||
Describe "$commandName verify parameters" { | ||
BeforeDiscovery { | ||
[object[]]$knownParameters = 'SecretServer', 'ConfigPath' | ||
[object[]]$currentParams = ([Management.Automation.CommandMetaData]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function')).Parameters.Keys | ||
[object[]]$commandDetails = [System.Management.Automation.CommandInfo]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function') | ||
$unknownParameters = Compare-Object -ReferenceObject $knownParameters -DifferenceObject $currentParams -PassThru | ||
} | ||
Context "Verify parameters" -Foreach @{currentParams = $currentParams } { | ||
It "$commandName should contain <_> parameter" -TestCases $knownParameters { | ||
$_ -in $currentParams | Should -Be $true | ||
} | ||
It "$commandName should not contain parameter: <_>" -TestCases $unknownParameters { | ||
$_ | Should -BeNullOrEmpty | ||
} | ||
} | ||
Context "Command specific details" { | ||
It "$commandName should set OutputType to System.Boolean" -TestCases $commandDetails { | ||
$_.OutputType.Name | Should -Be 'System.Boolean' | ||
} | ||
} | ||
} |