SecretManagement.Chromium.Extension/Tests/Get-Secret.Tests.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#requires -modules @{ModuleName="Pester"; ModuleVersion="5.1.0"}
Describe 'Get-Secret' {
    BeforeEach {
        . $PSScriptRoot/Shared.ps1
        PrepareTestEnvironment
        Register-SecretVault @registerVaultParams
    }
    AfterEach {
        TeardownTestEnvironment
        $testVault | Microsoft.Powershell.SecretManagement\Unregister-SecretVault -ErrorAction SilentlyContinue
    }

    It 'Fetches Secret By Name' {
        $fetchedSecret = SecretManagement.Chromium.Extension\Get-Secret @defaultVaultParams -Name 'pester2|https://twitter.com/' 
        $fetchedSecret | Should -BeOfType 'PSCredential'
        $fetchedSecret.GetNetworkCredential().Password | Should -Be 'pasterpassword'
        $fetchedSecret.UserName | Should -Be 'pester2'
    }
    It 'Returns null on invalid name' {
        SecretManagement.Chromium.Extension\Get-Secret @defaultVaultParams -Name 'PESTERMISSINGNAME' | 
            Should -BeNullOrEmpty
    }
    It 'Fails on ambiguous match' {
        {SecretManagement.Chromium.Extension\Get-Secret @defaultVaultParams -Name '*twitter*'} |
            Should -Throw 'Your secret search is ambiguous*'
    }
    It 'Fails on null Name' {
        {SecretManagement.Chromium.Extension\Get-Secret @defaultVaultParams -Name $null} |
            Should -Throw 'You must specify a specific secret*'
    }
}