|
| 1 | +$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) |
| 2 | +Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'Misc' -ChildPath 'xBitlockerCommon.psm1')) -Force |
| 3 | + |
| 4 | +# Begin Testing |
| 5 | +try |
| 6 | +{ |
| 7 | + InModuleScope "xBitlockerCommon" { |
| 8 | + |
| 9 | + function Get-BitlockerVolume |
| 10 | + { |
| 11 | + param |
| 12 | + ( |
| 13 | + [Parameter()] |
| 14 | + [System.String] |
| 15 | + $MountPoint |
| 16 | + ) |
| 17 | + } |
| 18 | + |
| 19 | + Describe "xBitlockerCommon\TestBitlocker" { |
| 20 | + |
| 21 | + Context 'When OS Volume is not Encrypted and No Key Protectors Assigned' { |
| 22 | + Mock ` |
| 23 | + -CommandName Get-BitlockerVolume ` |
| 24 | + -ModuleName 'xBitlockerCommon' ` |
| 25 | + -MockWith { |
| 26 | + # Decrypted with no Key Protectors |
| 27 | + return @{ |
| 28 | + VolumeType = 'OperatingSystem' |
| 29 | + MountPoint = $MountPoint |
| 30 | + CapacityGB = 500 |
| 31 | + VolumeStatus = 'FullyDecrypted' |
| 32 | + EncryptionPercentage = 0 |
| 33 | + KeyProtector = @() |
| 34 | + AutoUnlockEnabled = $null |
| 35 | + ProtectionStatus = 'Off' |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + It 'Should Fail The Test (TPM and RecoveryPassword Protectors)' { |
| 40 | + TestBitlocker -MountPoint 'C:' -PrimaryProtector 'TPMProtector' -RecoveryPasswordProtector $true | Should -Be $false |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + Context 'When OS Volume is Encrypted using TPM and Recovery Password Protectors' { |
| 45 | + Mock ` |
| 46 | + -CommandName Get-BitlockerVolume ` |
| 47 | + -ModuleName 'xBitlockerCommon' ` |
| 48 | + -MockWith { |
| 49 | + # Encrypted with TPM and Recovery Password Key Protectors |
| 50 | + return @{ |
| 51 | + VolumeType = 'OperatingSystem' |
| 52 | + MountPoint = $MountPoint |
| 53 | + CapacityGB = 500 |
| 54 | + VolumeStatus = 'FullyEncrypted' |
| 55 | + EncryptionPercentage = 100 |
| 56 | + KeyProtector = @( |
| 57 | + @{ |
| 58 | + KeyProtectorType = 'Tpm' |
| 59 | + }, |
| 60 | + @{ |
| 61 | + KeyProtectorType = 'RecoveryPassword' |
| 62 | + } |
| 63 | + ) |
| 64 | + AutoUnlockEnabled = $null |
| 65 | + ProtectionStatus = 'On' |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + It 'Should Pass The Test (TPM and RecoveryPassword Protectors)' { |
| 70 | + TestBitlocker -MountPoint 'C:' -PrimaryProtector 'TPMProtector' -RecoveryPasswordProtector $true -verbose | Should -Be $true |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + Context 'When OS Volume is Decrypted, but has TPM and Recovery Password Protectors assigned' { |
| 75 | + Mock ` |
| 76 | + -CommandName Get-BitlockerVolume ` |
| 77 | + -ModuleName 'xBitlockerCommon' ` |
| 78 | + -MockWith { |
| 79 | + # Encrypted with TPM and Recovery Password Key Protectors |
| 80 | + return @{ |
| 81 | + VolumeType = 'OperatingSystem' |
| 82 | + MountPoint = $MountPoint |
| 83 | + CapacityGB = 500 |
| 84 | + VolumeStatus = 'FullyDecrypted' |
| 85 | + EncryptionPercentage = 0 |
| 86 | + KeyProtector = @( |
| 87 | + @{ |
| 88 | + KeyProtectorType = 'Tpm' |
| 89 | + }, |
| 90 | + @{ |
| 91 | + KeyProtectorType = 'RecoveryPassword' |
| 92 | + } |
| 93 | + ) |
| 94 | + AutoUnlockEnabled = $null |
| 95 | + ProtectionStatus = 'Off' |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + It 'Should Fail The Test (TPM and RecoveryPassword Protectors)' { |
| 100 | + TestBitlocker -MountPoint 'C:' -PrimaryProtector 'TPMProtector' -RecoveryPasswordProtector $true | Should -Be $false |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | +} |
| 106 | +finally |
| 107 | +{ |
| 108 | +} |
0 commit comments