@@ -33,7 +33,7 @@ Describe "Protect-CFCell" {
3333 Get-Service " Termservice" | Set-Service - StartupType " Automatic"
3434 netstat / p tcp / a | findstr " :3389 " | Should -Not - BeNullOrEmpty
3535
36- Protect-CFCell - IaaS " ignored "
36+ Protect-CFCell - IaaS " not-vsphere "
3737
3838 Get-ItemProperty - Path " HKLM:\System\CurrentControlSet\Control\Terminal Server" | select - exp fDenyTSConnections | Should - Be 1
3939 netstat / p tcp / a | findstr " :3389 " | Should - BeNullOrEmpty
@@ -44,7 +44,7 @@ Describe "Protect-CFCell" {
4444 It " disables the services" {
4545 Get-Service | Where-Object {$_.Name -eq " WinRM" } | Set-Service - StartupType Automatic
4646 Get-Service | Where-Object {$_.Name -eq " W3Svc" } | Set-Service - StartupType Automatic
47- Protect-CFCell - IaaS " ignored "
47+ Protect-CFCell - IaaS " not-vsphere "
4848 (Get-Service | Where-Object {$_.Name -eq " WinRM" } ).StartType| Should - Be " Disabled"
4949 $w3svcStartType = (Get-Service | Where-Object {$_.Name -eq " W3Svc" } ).StartType
5050 " Disabled" , $null -contains $w3svcStartType | Should - Be $true
@@ -55,43 +55,53 @@ Describe "Protect-CFCell" {
5555 get-firewall " public" | Should - Be " public,Allow,Allow"
5656 get-firewall " private" | Should - Be " private,Allow,Allow"
5757 get-firewall " domain" | Should - Be " domain,Allow,Allow"
58- Protect-CFCell - IaaS " ignored "
58+ Protect-CFCell - IaaS " not-vsphere "
5959 get-firewall " public" | Should - Be " public,Block,Allow"
6060 get-firewall " private" | Should - Be " private,Block,Allow"
6161 get-firewall " domain" | Should - Be " domain,Block,Allow"
6262 }
6363
64- It " sets all Windows Defender `disable` settings to true" {
65- Mock - ModuleName BOSH.CFCell Get-Command {
66- [hashtable ]@ {
67- ParameterSets = [hashtable ]@ {
68- Parameters = @ (
69- @ {Name = " DisableBehaviorMonitoring" },
70- @ {Name = " OtherThing" }
71- )
64+ It " does not call 'Disable-WindowsDefenderFeatures'" {
65+ Mock - ModuleName BOSH.CFCell Disable-WindowsDefenderFeatures { }
66+
67+ { Protect-CFCell - IaaS " not-vsphere" } | Should -Not - Throw
68+
69+ Should -Not - Invoke - ModuleName BOSH.CFCell - CommandName Disable-WindowsDefenderFeatures
70+ }
71+
72+ Context " when -IaaS is 'vsphere'" {
73+ It " sets all Windows Defender `disable` settings to true" {
74+ Mock - ModuleName BOSH.CFCell Get-Command {
75+ [hashtable ]@ {
76+ ParameterSets = [hashtable ]@ {
77+ Parameters = @ (
78+ @ { Name = " DisableBehaviorMonitoring" },
79+ @ { Name = " OtherThing" }
80+ )
81+ }
7282 }
7383 }
74- }
75- Mock - ModuleName BOSH.CFCell Set-MpPreference { }
84+ Mock - ModuleName BOSH.CFCell Set-MpPreference { }
7685
77- Protect-CFCell - IaaS " ignored "
86+ Protect-CFCell - IaaS " vsphere "
7887
79- Assert-MockCalled Write-Log - Exactly 1 - Scope It - ModuleName BOSH.CFCell - ParameterFilter { $Message -eq " Disabling Windows Defender Features" }
88+ Assert-MockCalled Write-Log - Exactly 1 - Scope It - ModuleName BOSH.CFCell - ParameterFilter { $Message -eq " Disabling Windows Defender Features" }
8089
81- Assert-MockCalled Set-MpPreference - Exactly 1 - Scope It - ParameterFilter { $DisableBehaviorMonitoring -eq $true } - ModuleName BOSH.CFCell
82- Assert-MockCalled Set-MpPreference - Exactly 0 - Scope It - ParameterFilter { $OtherThing -eq $true } - ModuleName BOSH.CFCell
90+ Assert-MockCalled Set-MpPreference - Exactly 1 - Scope It - ParameterFilter { $DisableBehaviorMonitoring -eq $true } - ModuleName BOSH.CFCell
91+ Assert-MockCalled Set-MpPreference - Exactly 0 - Scope It - ParameterFilter { $OtherThing -eq $true } - ModuleName BOSH.CFCell
8392
84- Assert-MockCalled Write-Log - Exactly 1 - Scope It - ModuleName BOSH.CFCell - ParameterFilter { $Message -eq " Setting Defender preference DisableBehaviorMonitoring to True" }
85- }
93+ Assert-MockCalled Write-Log - Exactly 1 - Scope It - ModuleName BOSH.CFCell - ParameterFilter { $Message -eq " Setting Defender preference DisableBehaviorMonitoring to True" }
94+ }
8695
87- It " does not attempt to change Windows Defender settings if Windows Defender is not installed" {
88- Mock - ModuleName BOSH.CFCell Get-Command { $false }
89- Mock - ModuleName BOSH.CFCell Set-MpPreference { }
96+ It " does not attempt to change Windows Defender settings if Windows Defender is not installed" {
97+ Mock - ModuleName BOSH.CFCell Get-Command { $false }
98+ Mock - ModuleName BOSH.CFCell Set-MpPreference { }
9099
91- Protect-CFCell - IaaS " ignored "
100+ Protect-CFCell - IaaS " vsphere "
92101
93- Assert-MockCalled Write-Log - Exactly 1 - Scope It - ModuleName BOSH.CFCell - ParameterFilter { $Message -eq " Set-MpPreference command not found, assuming Windows Defender is not installed" }
94- Assert-MockCalled Set-MpPreference - Scope It - Exactly 0 - ModuleName BOSH.CFCell
102+ Assert-MockCalled Write-Log - Exactly 1 - Scope It - ModuleName BOSH.CFCell - ParameterFilter { $Message -eq " Set-MpPreference command not found, assuming Windows Defender is not installed" }
103+ Assert-MockCalled Set-MpPreference - Scope It - Exactly 0 - ModuleName BOSH.CFCell
104+ }
95105 }
96106}
97107
0 commit comments