SecretManagement.Chromium.Extension/Tests/Test-SecretVault.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
32
33
34
35
36
#requires -modules @{ModuleName="Pester"; ModuleVersion="5.1.0"}
Describe 'Test-SecretVault' {
    BeforeEach {
        . $PSScriptRoot/Shared.ps1
        PrepareTestEnvironment
    }
    AfterEach {
        TeardownTestEnvironment
    }

    It 'Successfully Tests Mock Database' {
        SecretManagement.Chromium.Extension\Test-SecretVault @DefaultVaultParams | 
            Should -Be $true
    }

    It 'Fails for wrong path' -Tag 'File' {
        $vaultParams = New-DeepCopyObject $defaultVaultParams
        $vaultParams.AdditionalParameters.DataPath = 'C:\fake'
        {SecretManagement.Chromium.Extension\Test-SecretVault @VaultParams} |
            Should -Throw '*because it does not exist.'
    }

    It 'Fails for invalid database file' -Tag 'Chromium' {
        $vaultParams = New-DeepCopyObject $defaultVaultParams
        #Create a random empty file
        $vaultParams.AdditionalParameters.DataPath = New-Item -ItemType File -Path "$TestDrive/InvalidDatabaseFile"
        
        {SecretManagement.Chromium.Extension\Test-SecretVault @VaultParams} |
            Should -Throw '*is not a valid Chromium password database (Logins table not found)'
    }

    It 'Closes the vault safely' -Tag 'File','Chromium' {
        SecretManagement.Chromium.Extension\Test-SecretVault @DefaultVaultParams
        Remove-Item $DefaultVaultParams.AdditionalParameters.DataPath -ErrorAction Stop
    }
}