forked from dsccommunity/xBitlocker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dsccommunity#41 from mhendric/AddIntegrationTests
Add Integration Tests for All Resource Modules
- Loading branch information
Showing
12 changed files
with
478 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
114 changes: 114 additions & 0 deletions
114
Tests/Integration/MSFT_xBLAutoBitlocker.Integration.tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
$script:dscModuleName = 'xBitlocker' | ||
$script:dscResourceFriendlyName = 'xBLAutoBitlocker' | ||
$script:dcsResourceName = "MSFT_$($script:dscResourceFriendlyName)" | ||
|
||
#region HEADER | ||
# Integration Test Template Version: 1.3.1 | ||
[String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) | ||
if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` | ||
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) | ||
{ | ||
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) | ||
} | ||
|
||
Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force | ||
$TestEnvironment = Initialize-TestEnvironment ` | ||
-DSCModuleName $script:dscModuleName ` | ||
-DSCResourceName $script:dcsResourceName ` | ||
-TestType Integration | ||
|
||
# Import xBitlocker Test Helper Module | ||
Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'Tests' -ChildPath (Join-Path -Path 'TestHelpers' -ChildPath 'xBitlockerTestHelper.psm1'))) -Force | ||
#endregion | ||
|
||
# Make sure required features are installed before running tests | ||
if (!(Test-RequiredFeaturesInstalled)) | ||
{ | ||
return | ||
} | ||
|
||
# Make sure there are available Data disks to test AutoBitlocker on | ||
$fixedDriveBlvs = Get-BitLockerVolume | Where-Object -FilterScript {$_.VolumeType -eq 'Data'} | ||
|
||
if ($null -eq $fixedDriveBlvs) | ||
{ | ||
Write-Warning -Message 'One or more Bitlocker volumes of type Data must be available. Skipping Integration tests.' | ||
return | ||
} | ||
|
||
# Disable Bitlocker on the Fixed drives before performing any tests | ||
foreach ($fixedDriveBlv in $fixedDriveBlvs) | ||
{ | ||
if ($fixedDriveBlv.KeyProtector.Count -gt 0 -or $fixedDriveBlv.ProtectionStatus -ne 'Off') | ||
{ | ||
Disable-BitLocker -MountPoint $fixedDriveBlv.MountPoint | ||
} | ||
} | ||
|
||
# Using try/finally to always cleanup. | ||
try | ||
{ | ||
#region Integration Tests | ||
$configurationFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dcsResourceName).config.ps1" | ||
. $configurationFile | ||
|
||
Describe "$($script:dcsResourceName)_Integration" { | ||
$configurationName = "$($script:dcsResourceName)_EnablePasswordProtectorOnDataDrives_Config" | ||
|
||
Context ('When using configuration {0}' -f $configurationName) { | ||
It 'Should compile and apply the MOF without throwing' { | ||
{ | ||
$configurationParameters = @{ | ||
OutputPath = $TestDrive | ||
ConfigurationData = $ConfigurationData | ||
} | ||
|
||
& $configurationName @configurationParameters | ||
|
||
$startDscConfigurationParameters = @{ | ||
Path = $TestDrive | ||
ComputerName = 'localhost' | ||
Wait = $true | ||
Verbose = $true | ||
Force = $true | ||
ErrorAction = 'Stop' | ||
} | ||
|
||
Start-DscConfiguration @startDscConfigurationParameters | ||
} | Should -Not -Throw | ||
} | ||
|
||
It 'Should be able to call Get-DscConfiguration without throwing' { | ||
{ | ||
$script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop | ||
} | Should -Not -Throw | ||
} | ||
|
||
It 'Should have set the resource and all the parameters should match' { | ||
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { | ||
$_.ConfigurationName -eq $configurationName ` | ||
-and $_.ResourceId -eq "[$($script:dscResourceFriendlyName)]Integration_Test" | ||
} | ||
|
||
$fixedDriveBlvs = Get-BitLockerVolume | Where-Object -FilterScript {$_.VolumeType -eq 'Data'} | ||
|
||
foreach ($fixedDriveBlv in $fixedDriveBlvs) | ||
{ | ||
$fixedDriveBlv.KeyProtector.Count | Should -BeGreaterThan 0 | ||
} | ||
} | ||
|
||
It 'Should return $true when Test-DscConfiguration is run' { | ||
Test-DscConfiguration -Verbose | Should -Be $true | ||
} | ||
} | ||
} | ||
#endregion | ||
|
||
} | ||
finally | ||
{ | ||
#region FOOTER | ||
Restore-TestEnvironment -TestEnvironment $TestEnvironment | ||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')] | ||
param() | ||
|
||
#region HEADER | ||
# Integration Test Config Template Version: 1.2.0 | ||
#endregion | ||
|
||
$configFile = [System.IO.Path]::ChangeExtension($MyInvocation.MyCommand.Path, 'json') | ||
if (Test-Path -Path $configFile) | ||
{ | ||
$ConfigurationData = Get-Content -Path $configFile | ConvertFrom-Json | ||
} | ||
else | ||
{ | ||
$ConfigurationData = @{ | ||
AllNodes = @( | ||
@{ | ||
NodeName = 'localhost' | ||
PsDscAllowPlainTextPassword = $true | ||
} | ||
) | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Enables Bitlocker on Fixed drives using a PasswordProtector | ||
#> | ||
Configuration MSFT_xBLAutoBitlocker_EnablePasswordProtectorOnDataDrives_Config | ||
{ | ||
Import-DscResource -ModuleName 'xBitlocker' | ||
|
||
Node $AllNodes.NodeName | ||
{ | ||
xBLAutoBitlocker Integration_Test | ||
{ | ||
DriveType = 'Fixed' | ||
PrimaryProtector = 'PasswordProtector' | ||
Password = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'AutoBitlocker', (ConvertTo-SecureString 'Password1' -AsPlainText -Force) | ||
UsedSpaceOnly = $true | ||
} | ||
} | ||
} |
Oops, something went wrong.