Skip to content

Commit 6892e71

Browse files
committed
Fixes issue where Switch parameters are passed to Enable-Bitlocker even if the corresponding DSC resource parameter was set to False - Post Review #1
1 parent 23384dd commit 6892e71

File tree

7 files changed

+98
-60
lines changed

7 files changed

+98
-60
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Rename functions with improper Verb-Noun constructs
1919
- Add comment based help to any functions without it
2020
- Update Schema.mof Description fields
21+
- Fixes issue where Switch parameters are passed to Enable-Bitlocker even if
22+
the corresponding DSC resource parameter was set to False (Issue #12)
2123

2224
## 1.2.0.0
2325

Misc/xBitlockerCommon.psm1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,22 +208,22 @@ function Enable-BitlockerInternal
208208

209209
if ($PSBoundParameters.ContainsKey("HardwareEncryption"))
210210
{
211-
$params.Add("HardwareEncryption", $true)
211+
$params.Add("HardwareEncryption", $HardwareEncryption)
212212
}
213213

214214
if ($PSBoundParameters.ContainsKey("Service"))
215215
{
216-
$params.Add("Service", $true)
216+
$params.Add("Service", $Service)
217217
}
218218

219219
if ($PSBoundParameters.ContainsKey("SkipHardwareTest"))
220220
{
221-
$params.Add("SkipHardwareTest", $true)
221+
$params.Add("SkipHardwareTest", $SkipHardwareTest)
222222
}
223223

224224
if ($PSBoundParameters.ContainsKey("UsedSpaceOnly"))
225225
{
226-
$params.Add("UsedSpaceOnly", $true)
226+
$params.Add("UsedSpaceOnly", $UsedSpaceOnly)
227227
}
228228

229229
#Now add the primary protector

Tests/Integration/MSFT_xBLAutoBitlocker.Integration.tests.ps1

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ try
8585
}
8686

8787
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-
9388
$fixedDriveBlvs = Get-BitLockerVolume | Where-Object -FilterScript {$_.VolumeType -eq 'Data'}
9489

9590
foreach ($fixedDriveBlv in $fixedDriveBlvs)

Tests/Integration/MSFT_xBLBitlocker.Integration.tests.ps1

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,6 @@ if (!(Test-RequiredFeaturesInstalled))
3333
return
3434
}
3535

36-
# Disable Bitlocker on the OS drive before performing any tests
37-
$sysDriveBlv = Get-BitLockerVolume -MountPoint $env:SystemDrive
38-
39-
if ($sysDriveBlv.KeyProtector.Count -gt 0 -or $sysDriveBlv.ProtectionStatus -ne 'Off')
40-
{
41-
Disable-BitLocker -MountPoint $env:SystemDrive
42-
}
43-
4436
# Using try/finally to always cleanup.
4537
try
4638
{
@@ -49,48 +41,53 @@ try
4941
. $configurationFile
5042

5143
Describe "$($script:dcsResourceName)_Integration" {
52-
$configurationName = "$($script:dcsResourceName)_BasicTPMEncryptionOnSysDrive_Config"
53-
54-
Context ('When using configuration {0}' -f $configurationName) {
55-
It 'Should compile and apply the MOF without throwing' {
56-
{
57-
$configurationParameters = @{
58-
OutputPath = $TestDrive
59-
ConfigurationData = $ConfigurationData
60-
}
61-
62-
& $configurationName @configurationParameters
63-
64-
$startDscConfigurationParameters = @{
65-
Path = $TestDrive
66-
ComputerName = 'localhost'
67-
Wait = $true
68-
Verbose = $true
69-
Force = $true
70-
ErrorAction = 'Stop'
71-
}
72-
73-
Start-DscConfiguration @startDscConfigurationParameters
74-
} | Should -Not -Throw
75-
}
44+
$configurationNames = @(
45+
"$($script:dcsResourceName)_BasicTPMEncryptionOnSysDrive_Config"
46+
"$($script:dcsResourceName)_TPMEncryptionOnSysDriveWithFalseSwitchParams_Config"
47+
)
48+
49+
foreach ($configurationName in $configurationNames)
50+
{
51+
Context ('When using configuration {0}' -f $configurationName) {
52+
BeforeAll {
53+
Disable-BitLockerOnTestDrive -MountPoint $env:SystemDrive
54+
}
7655

77-
It 'Should be able to call Get-DscConfiguration without throwing' {
78-
{
79-
$script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop
80-
} | Should -Not -Throw
81-
}
56+
It 'Should compile and apply the MOF without throwing' {
57+
{
58+
$configurationParameters = @{
59+
OutputPath = $TestDrive
60+
ConfigurationData = $ConfigurationData
61+
}
62+
63+
& $configurationName @configurationParameters
64+
65+
$startDscConfigurationParameters = @{
66+
Path = $TestDrive
67+
ComputerName = 'localhost'
68+
Wait = $true
69+
Verbose = $true
70+
Force = $true
71+
ErrorAction = 'Stop'
72+
}
73+
74+
Start-DscConfiguration @startDscConfigurationParameters
75+
} | Should -Not -Throw
76+
}
8277

83-
It 'Should have set the resource and all the parameters should match' {
84-
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
85-
$_.ConfigurationName -eq $configurationName `
86-
-and $_.ResourceId -eq "[$($script:dscResourceFriendlyName)]Integration_Test"
78+
It 'Should be able to call Get-DscConfiguration without throwing' {
79+
{
80+
$script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop
81+
} | Should -Not -Throw
8782
}
8883

89-
(Get-BitlockerVolume -MountPoint $env:SystemDrive).KeyProtector[0].KeyProtectorType | Should -Be 'Tpm'
90-
}
84+
It 'Should have set the resource and all the parameters should match' {
85+
(Get-BitlockerVolume -MountPoint $env:SystemDrive).KeyProtector[0].KeyProtectorType | Should -Be 'Tpm'
86+
}
9187

92-
It 'Should return $true when Test-DscConfiguration is run' {
93-
Test-DscConfiguration -Verbose | Should -Be $true
88+
It 'Should return $true when Test-DscConfiguration is run' {
89+
Test-DscConfiguration -Verbose | Should -Be $true
90+
}
9491
}
9592
}
9693
}

Tests/Integration/MSFT_xBLBitlocker.config.ps1

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ else
2020

2121
<#
2222
.SYNOPSIS
23-
Enables Bitlocker on the Operating System drive using a TpmProtector
23+
Enables Bitlocker on the Operating System drive using a TpmProtector.
2424
#>
2525
Configuration MSFT_xBLBitlocker_BasicTPMEncryptionOnSysDrive_Config
2626
{
@@ -32,6 +32,29 @@ Configuration MSFT_xBLBitlocker_BasicTPMEncryptionOnSysDrive_Config
3232
{
3333
MountPoint = $env:SystemDrive
3434
PrimaryProtector = 'TpmProtector'
35+
UsedSpaceOnly = $true
36+
}
37+
}
38+
}
39+
40+
<#
41+
.SYNOPSIS
42+
Enables Bitlocker on the Operating System drive using a TpmProtector
43+
and passed multiple Switch parameters of Enable-Bitlocker with False
44+
values.
45+
#>
46+
Configuration MSFT_xBLBitlocker_TPMEncryptionOnSysDriveWithFalseSwitchParams_Config
47+
{
48+
Import-DscResource -ModuleName 'xBitlocker'
49+
50+
Node $AllNodes.NodeName
51+
{
52+
xBLBitlocker Integration_Test
53+
{
54+
MountPoint = $env:SystemDrive
55+
PrimaryProtector = 'TpmProtector'
56+
HardwareEncryption = $false
57+
UsedSpaceOnly = $false
3558
}
3659
}
3760
}

Tests/Integration/MSFT_xBLTpm.Integration.tests.ps1

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ try
7373
}
7474

7575
It 'Should have set the resource and all the parameters should match' {
76-
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
77-
$_.ConfigurationName -eq $configurationName `
78-
-and $_.ResourceId -eq "[$($script:dscResourceFriendlyName)]Integration_Test"
79-
}
80-
8176
(Get-Tpm).TpmReady | Should -Be $true
8277
}
8378

Tests/TestHelpers/xBitlockerTestHelper.psm1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,29 @@ function Test-HasPresentTpm
4242

4343
return $hasReadyTpm
4444
}
45+
46+
<#
47+
.SYNOPSIS
48+
Disables BitLocker on a test drive, if Enabled
49+
50+
.PARAMETER MountPoint
51+
The MountPoint to disable BitLocker on
52+
#>
53+
function Disable-BitLockerOnTestDrive
54+
{
55+
[CmdletBinding()]
56+
param
57+
(
58+
[Parameter(Mandatory = $true)]
59+
[ValidateNotNullorEmpty()]
60+
[System.String]
61+
$MountPoint
62+
)
63+
64+
$blv = Get-BitLockerVolume -MountPoint $MountPoint
65+
66+
if ($blv.KeyProtector.Count -gt 0 -or $blv.ProtectionStatus -ne 'Off')
67+
{
68+
Disable-BitLocker -MountPoint $blv
69+
}
70+
}

0 commit comments

Comments
 (0)