From 05d0178dbdbca36b911c53374ca7c87addafe664 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Jun 2025 13:54:25 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Enhance=20Get-Context?= =?UTF-8?q?=20tests=20for=20ID=20handling=20and=20output=20validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Context.Tests.ps1 | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/Context.Tests.ps1 b/tests/Context.Tests.ps1 index daa798f0..bcae0bc2 100644 --- a/tests/Context.Tests.ps1 +++ b/tests/Context.Tests.ps1 @@ -179,6 +179,40 @@ Describe 'Context' { { Get-Context -ID $null -Vault 'VaultA' } | Should -Not -Throw Get-Context -ID $null -Vault 'VaultA' | Should -BeNullOrEmpty } + It 'Get-Context -ID array - Should return only specified contexts in VaultA' { + $ids = @('TestID1', 'TestID2') + $results = Get-Context -ID $ids -Vault 'VaultA' + $results | Should -Not -BeNullOrEmpty + $results.Count | Should -Be 2 + $results.ID | Should -Contain 'TestID1' + $results.ID | Should -Contain 'TestID2' + $results.ID | Should -Not -Contain 'TestID3' + } + It 'Get-Context -ID single - Should not have output leakage (returns only one context)' { + $id = 'TestID1' + $results = Get-Context -ID $id -Vault 'VaultA' + $results | Should -Not -BeNullOrEmpty + $results.Count | Should -Be 1 + $results.ID | Should -Be $id + } + It 'Get-Context -ID single (nonexistent) - Should not have output leakage (returns nothing)' { + $id = 'NonExistentContext' + $results = Get-Context -ID $id -Vault 'VaultA' + $results | Should -BeNullOrEmpty + } + It 'Get-Context -ID array with one valid and one invalid - Should not have output leakage (returns only valid)' { + $ids = @('TestID1', 'NonExistentContext') + $results = Get-Context -ID $ids -Vault 'VaultA' + $results | Should -Not -BeNullOrEmpty + $results.Count | Should -Be 1 + $results.ID | Should -Be 'TestID1' + } + It 'Get-Context -ID with whitespace or null - Should not have output leakage (returns nothing)' { + $results = Get-Context -ID ' ' -Vault 'VaultA' + $results | Should -BeNullOrEmpty + $results = Get-Context -ID $null -Vault 'VaultA' + $results | Should -BeNullOrEmpty + } } Context 'Remove-Context' { @@ -304,5 +338,15 @@ Describe 'Context' { $result = Get-ContextInfo -ID 'NonExistentContext' -Vault 'VaultA' $result | Should -BeNullOrEmpty } + + It 'Should return only specified contexts for multiple IDs in VaultA' { + $ids = @('TestID1', 'TestID2') + $results = Get-ContextInfo -ID $ids -Vault 'VaultA' + $results | Should -Not -BeNullOrEmpty + $results.Count | Should -Be 2 + $results.ID | Should -Contain 'TestID1' + $results.ID | Should -Contain 'TestID2' + $results.ID | Should -Not -Contain 'TestID3' + } } }