Skip to content

Commit 353bbe6

Browse files
beaudryjcdhunt
authored andcommitted
Added Firewall Test (#9)
* Added Firewall Test * Small Tweaks and things I missed
1 parent af3b62c commit 353bbe6

4 files changed

Lines changed: 66 additions & 0 deletions

File tree

Public/Firewall.ps1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<#
2+
.SYNOPSIS
3+
Firewall Settings
4+
.DESCRIPTION
5+
Used To Determine if Firewall is Running Desired Settings
6+
.PARAMETER Target
7+
The name of the Firewall DisplayName to be Tested
8+
.PARAMETER Property
9+
The name of the Property of the Firewall Object to be Tested
10+
.PARAMETER Should
11+
A Script Block defining a Pester Assertion.
12+
.EXAMPLE
13+
Firewall putty.exe Enabled { Should be "$True" }
14+
.EXAMPLE
15+
Firewall putty.exe Action { Should be 'Allow' }
16+
.EXAMPLE
17+
Firewall putty.exe Private { Should be 'Public' }
18+
.NOTES
19+
Assertions: Be
20+
#>
21+
function Firewall{
22+
[CmdletBinding()]
23+
param(
24+
[Parameter(Mandatory, Position=1)]
25+
[Alias('Name')]
26+
[string]$Target,
27+
28+
[Parameter(Position=2)]
29+
[ValidateSet("Name","DisplayName","Description","DisplayGroup","Group","Enabled","Profile","Direction","Action","EdgeTraversalPolicy","LooseSourceMapping","LocalOnlyMapping","PrimaryStatus","Status","EnforcementStatus","PolicyStoreSource","PolicyStoreSourceType")]
30+
[string]$Property,
31+
32+
[Parameter(Mandatory, Position=3)]
33+
[scriptblock]$Should
34+
)
35+
36+
$expression = {Get-NetFirewallRule -DisplayName '$Target' -ErrorAction SilentlyContinue }
37+
38+
$params = Get-PoshspecParam -TestName Firewall -TestExpression $expression @PSBoundParameters
39+
40+
Invoke-PoshspecExpression @params
41+
}

ReleaseNotes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
# Version 2.1.1
2+
* Added Functions for
3+
* Firewall
4+
15
# Version 2.1.0
26
* Broke Down PSM1 to Many Different Functions in their own files [No change in functionality]
37
* Added Functions for
48
* CheckSite
59
* CheckAppPool
610
* WebSite
711
* SoftwareProduct
12+
813

914
# Version 1.2.2
1015
* Merged PR including 5 new functions

Tests/poshspec.Tests.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,19 @@ Describe 'Test Functions' {
313313
$results.Expression | Should Be "Test-Path -Path `"IIS:\AppPools\TestSite`" -ErrorAction SilentlyContinue | Should be `$true"
314314
}
315315
}
316+
317+
Context 'Firewall' {
318+
$results = Firewall putty.exe Action { Should be 'Allow' }
319+
320+
It "Should return the correct test Name" {
321+
$results.Name | Should Be "Firewall property 'Action' for 'putty.exe' Should be 'Allow'"
322+
}
323+
324+
It "Should return the correct test Expression" {
325+
$results.Expression | Should Be "Get-NetFirewallRule -DisplayName 'putty.exe' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty 'Action' | Should be 'Allow'"
326+
}
327+
}
328+
316329

317330
Context 'SoftwareProduct' {
318331

poshspecdemo.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,10 @@ Describe 'WebSite' {
4040
CheckAppPool TestSite { Should be $True }
4141
AppPoolState TestSite { Should be Started }
4242
}
43+
44+
Describe 'Firewall' {
45+
Firewall putty.exe Enabled { Should be "$True" }
46+
Firewall putty.exe Action { Should be 'Allow' }
47+
Firewall putty.exe Profile { Should be 'Private' }
48+
}
49+

0 commit comments

Comments
 (0)