Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Still work to do
- Loading branch information
Showing
2 changed files
with
74 additions
and
105 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,74 @@ | ||
BeforeDiscovery { | ||
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf | ||
. ([IO.Path]::Combine([string]$PSScriptRoot, '..', 'constants.ps1')) | ||
} | ||
Describe "$commandName verify parameters" { | ||
BeforeDiscovery { | ||
[object[]]$knownParameters = 'TssSession', 'Id', | ||
<# Restricted params #> | ||
'Comment', 'ForceCheckIn', 'TicketNumber', 'TicketSystemId', | ||
|
||
<# CheckIn #> | ||
'CheckIn', | ||
|
||
<# General settings #> | ||
'Active', 'EnableInheritSecretPolicy', 'FolderId', 'GenerateSshKeys', 'HeartbeatEnabled', 'SecretPolicy', 'Site','IsOutOfSync', 'SecretName', | ||
|
||
<# Other params for PUT /secrets/{id} endpoint #> | ||
'AutoChangeEnabled', 'AutoChangeNextPassword', 'EnableInheritPermission' | ||
|
||
[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 | ||
} | ||
} | ||
} | ||
Describe "$commandName functions" { | ||
Context "Checking" { | ||
BeforeAll { | ||
$session = [pscustomobject]@{ | ||
ApiVersion = 'api/v1' | ||
Take = 50 | ||
SecretServer = 'http://alpha' | ||
ApiUrl = 'http://alpha/api/v1' | ||
AccessToken = 'AgJf5YLChrisPine312UcBrM1s1KB2BGZ5Ufc4qLZ' | ||
RefreshToken = '9oacYeah0YqgBNg0L7VinDiesel6-Z9ITE51Humus' | ||
TokenType = 'bearer' | ||
ExpiresIn = 1200 | ||
} | ||
Mock -Verifiable -CommandName Invoke-RestMethod -ParameterFilter { $Uri -match '/version' } -MockWith { | ||
return [pscustomobject]@{ | ||
model = [pscustomobject]@{ | ||
version = '10.9.000033' | ||
} | ||
} | ||
} | ||
|
||
$secretActiveId = 43 | ||
Mock -Verifiable -CommandName Invoke-RestMethod -ParameterFilter { $Uri -match "/secrets/$secretActiveId/general"; $Method -eq 'PATCH' } -MockWith { | ||
return [pscustomobject]@{ | ||
id = $secretActiveId | ||
active = [pscustomobject]@{ | ||
value = $false | ||
} | ||
} | ||
} | ||
$objectActive = Set-Secret -TssSession $session -Id $secretActiveId -Active:$false | ||
Assert-VerifiableMock | ||
} | ||
It "Should be empty for all checks" { | ||
$objectActive | Should -BeNullOrEmpty | ||
$objectAutoChangeEnabled | Should -BeNullOrEmptyexit | ||
} | ||
It "Should have called Invoke-RestMethod 4 times" { | ||
Assert-MockCalled -CommandName Invoke-RestMethod -Times 4 -Scope Describe | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.