Skip to content

Commit

Permalink
Set-Secret - Tests rework
Browse files Browse the repository at this point in the history
Still work to do
  • Loading branch information
wsmelton committed Apr 4, 2021
1 parent bc849aa commit cb39262
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 105 deletions.
74 changes: 74 additions & 0 deletions tests/secrets/Set-Secret.Tests.ps1
@@ -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
}
}
}
105 changes: 0 additions & 105 deletions tests/secrets/Set-TssSecret.Tests.ps1

This file was deleted.

0 comments on commit cb39262

Please sign in to comment.