Skip to content

Commit 2b06229

Browse files
authored
Merge pull request #41 from mhendric/AddIntegrationTests
Add Integration Tests for All Resource Modules
2 parents 2f4f036 + bad0420 commit 2b06229

12 files changed

+478
-279
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- Moved change log to CHANGELOG.md file
1515
- Fixed Markdown validation warnings in README.md
1616
- Added .MetaTestOptIn.json file to root of module
17+
- Add Integration Tests for module resources
1718

1819
## 1.2.0.0
1920

Misc/xBitlockerCommon.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function EnableBitlocker
192192
throw "A TpmProtector must be used if Pin is used."
193193
}
194194

195-
Add-MissingBitLockerKeyProtector @PSBoundParameters -Verbose:$VerbosePreference
195+
Add-MissingBitLockerKeyProtector @PSBoundParameters
196196

197197
#Now enable Bitlocker with the primary key protector
198198
if ($blv.VolumeStatus -eq "FullyDecrypted")

Test/Test-xBitlocker.ps1

Lines changed: 0 additions & 165 deletions
This file was deleted.
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
2+
param()
3+
4+
#region HEADER
5+
# Integration Test Config Template Version: 1.2.0
6+
#endregion
7+
8+
$configFile = [System.IO.Path]::ChangeExtension($MyInvocation.MyCommand.Path, 'json')
9+
if (Test-Path -Path $configFile)
10+
{
11+
$ConfigurationData = Get-Content -Path $configFile | ConvertFrom-Json
12+
}
13+
else
14+
{
15+
$ConfigurationData = @{
16+
AllNodes = @(
17+
@{
18+
NodeName = 'localhost'
19+
PsDscAllowPlainTextPassword = $true
20+
}
21+
)
22+
}
23+
}
24+
25+
<#
26+
.SYNOPSIS
27+
Enables Bitlocker on Fixed drives using a PasswordProtector
28+
#>
29+
Configuration MSFT_xBLAutoBitlocker_EnablePasswordProtectorOnDataDrives_Config
30+
{
31+
Import-DscResource -ModuleName 'xBitlocker'
32+
33+
Node $AllNodes.NodeName
34+
{
35+
xBLAutoBitlocker Integration_Test
36+
{
37+
DriveType = 'Fixed'
38+
PrimaryProtector = 'PasswordProtector'
39+
Password = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'AutoBitlocker', (ConvertTo-SecureString 'Password1' -AsPlainText -Force)
40+
UsedSpaceOnly = $true
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)