|
| 1 | +$script:dscModuleName = 'xBitlocker' |
| 2 | +$script:dscResourceFriendlyName = 'xBLAutoBitlocker' |
| 3 | +$script:dcsResourceName = "MSFT_$($script:dscResourceFriendlyName)" |
| 4 | + |
| 5 | +#region HEADER |
| 6 | +# Integration Test Template Version: 1.3.1 |
| 7 | +[String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) |
| 8 | +if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` |
| 9 | + (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) |
| 10 | +{ |
| 11 | + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) |
| 12 | +} |
| 13 | + |
| 14 | +Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force |
| 15 | +$TestEnvironment = Initialize-TestEnvironment ` |
| 16 | + -DSCModuleName $script:dscModuleName ` |
| 17 | + -DSCResourceName $script:dcsResourceName ` |
| 18 | + -TestType Integration |
| 19 | + |
| 20 | +# Import xBitlocker Test Helper Module |
| 21 | +Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'Tests' -ChildPath (Join-Path -Path 'TestHelpers' -ChildPath 'xBitlockerTestHelper.psm1'))) -Force |
| 22 | +#endregion |
| 23 | + |
| 24 | +# Make sure required features are installed before running tests |
| 25 | +if (!(Test-RequiredFeaturesInstalled)) |
| 26 | +{ |
| 27 | + return |
| 28 | +} |
| 29 | + |
| 30 | +# Make sure there are available Data disks to test AutoBitlocker on |
| 31 | +$fixedDriveBlvs = Get-BitLockerVolume | Where-Object -FilterScript {$_.VolumeType -eq 'Data'} |
| 32 | + |
| 33 | +if ($null -eq $fixedDriveBlvs) |
| 34 | +{ |
| 35 | + Write-Warning -Message 'One or more Bitlocker volumes of type Data must be available. Skipping Integration tests.' |
| 36 | + return |
| 37 | +} |
| 38 | + |
| 39 | +# Disable Bitlocker on the Fixed drives before performing any tests |
| 40 | +foreach ($fixedDriveBlv in $fixedDriveBlvs) |
| 41 | +{ |
| 42 | + if ($fixedDriveBlv.KeyProtector.Count -gt 0 -or $fixedDriveBlv.ProtectionStatus -ne 'Off') |
| 43 | + { |
| 44 | + Disable-BitLocker -MountPoint $fixedDriveBlv.MountPoint |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +# Using try/finally to always cleanup. |
| 49 | +try |
| 50 | +{ |
| 51 | + #region Integration Tests |
| 52 | + $configurationFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dcsResourceName).config.ps1" |
| 53 | + . $configurationFile |
| 54 | + |
| 55 | + Describe "$($script:dcsResourceName)_Integration" { |
| 56 | + $configurationName = "$($script:dcsResourceName)_EnablePasswordProtectorOnDataDrives_Config" |
| 57 | + |
| 58 | + Context ('When using configuration {0}' -f $configurationName) { |
| 59 | + It 'Should compile and apply the MOF without throwing' { |
| 60 | + { |
| 61 | + $configurationParameters = @{ |
| 62 | + OutputPath = $TestDrive |
| 63 | + ConfigurationData = $ConfigurationData |
| 64 | + } |
| 65 | + |
| 66 | + & $configurationName @configurationParameters |
| 67 | + |
| 68 | + $startDscConfigurationParameters = @{ |
| 69 | + Path = $TestDrive |
| 70 | + ComputerName = 'localhost' |
| 71 | + Wait = $true |
| 72 | + Verbose = $true |
| 73 | + Force = $true |
| 74 | + ErrorAction = 'Stop' |
| 75 | + } |
| 76 | + |
| 77 | + Start-DscConfiguration @startDscConfigurationParameters |
| 78 | + } | Should -Not -Throw |
| 79 | + } |
| 80 | + |
| 81 | + It 'Should be able to call Get-DscConfiguration without throwing' { |
| 82 | + { |
| 83 | + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop |
| 84 | + } | Should -Not -Throw |
| 85 | + } |
| 86 | + |
| 87 | + It 'Should have set the resource and all the parameters should match' { |
| 88 | + $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { |
| 89 | + $_.ConfigurationName -eq $configurationName ` |
| 90 | + -and $_.ResourceId -eq "[$($script:dscResourceFriendlyName)]Integration_Test" |
| 91 | + } |
| 92 | + |
| 93 | + $fixedDriveBlvs = Get-BitLockerVolume | Where-Object -FilterScript {$_.VolumeType -eq 'Data'} |
| 94 | + |
| 95 | + foreach ($fixedDriveBlv in $fixedDriveBlvs) |
| 96 | + { |
| 97 | + $fixedDriveBlv.KeyProtector.Count | Should -BeGreaterThan 0 |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + It 'Should return $true when Test-DscConfiguration is run' { |
| 102 | + Test-DscConfiguration -Verbose | Should -Be $true |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + #endregion |
| 107 | + |
| 108 | +} |
| 109 | +finally |
| 110 | +{ |
| 111 | + #region FOOTER |
| 112 | + Restore-TestEnvironment -TestEnvironment $TestEnvironment |
| 113 | + #endregion |
| 114 | +} |
0 commit comments