Skip to content

Commit

Permalink
Merge pull request dsccommunity#41 from mhendric/AddIntegrationTests
Browse files Browse the repository at this point in the history
Add Integration Tests for All Resource Modules
  • Loading branch information
mhendric authored Nov 21, 2018
2 parents 2f4f036 + bad0420 commit 2b06229
Show file tree
Hide file tree
Showing 12 changed files with 478 additions and 279 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Moved change log to CHANGELOG.md file
- Fixed Markdown validation warnings in README.md
- Added .MetaTestOptIn.json file to root of module
- Add Integration Tests for module resources

## 1.2.0.0

Expand Down
2 changes: 1 addition & 1 deletion Misc/xBitlockerCommon.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function EnableBitlocker
throw "A TpmProtector must be used if Pin is used."
}

Add-MissingBitLockerKeyProtector @PSBoundParameters -Verbose:$VerbosePreference
Add-MissingBitLockerKeyProtector @PSBoundParameters

#Now enable Bitlocker with the primary key protector
if ($blv.VolumeStatus -eq "FullyDecrypted")
Expand Down
165 changes: 0 additions & 165 deletions Test/Test-xBitlocker.ps1

This file was deleted.

114 changes: 114 additions & 0 deletions Tests/Integration/MSFT_xBLAutoBitlocker.Integration.tests.ps1
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
}
43 changes: 43 additions & 0 deletions Tests/Integration/MSFT_xBLAutoBitlocker.config.ps1
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
}
}
}
Loading

0 comments on commit 2b06229

Please sign in to comment.