Skip to content

Commit

Permalink
Added Firewall Test (#9)
Browse files Browse the repository at this point in the history
* Added Firewall Test

* Small Tweaks and things I missed
  • Loading branch information
beaudryj authored and cdhunt committed May 27, 2016
1 parent af3b62c commit 353bbe6
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Public/Firewall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<#
.SYNOPSIS
Firewall Settings
.DESCRIPTION
Used To Determine if Firewall is Running Desired Settings
.PARAMETER Target
The name of the Firewall DisplayName to be Tested
.PARAMETER Property
The name of the Property of the Firewall Object to be Tested
.PARAMETER Should
A Script Block defining a Pester Assertion.
.EXAMPLE
Firewall putty.exe Enabled { Should be "$True" }
.EXAMPLE
Firewall putty.exe Action { Should be 'Allow' }
.EXAMPLE
Firewall putty.exe Private { Should be 'Public' }
.NOTES
Assertions: Be
#>
function Firewall{
[CmdletBinding()]
param(
[Parameter(Mandatory, Position=1)]
[Alias('Name')]
[string]$Target,

[Parameter(Position=2)]
[ValidateSet("Name","DisplayName","Description","DisplayGroup","Group","Enabled","Profile","Direction","Action","EdgeTraversalPolicy","LooseSourceMapping","LocalOnlyMapping","PrimaryStatus","Status","EnforcementStatus","PolicyStoreSource","PolicyStoreSourceType")]
[string]$Property,

[Parameter(Mandatory, Position=3)]
[scriptblock]$Should
)

$expression = {Get-NetFirewallRule -DisplayName '$Target' -ErrorAction SilentlyContinue }

$params = Get-PoshspecParam -TestName Firewall -TestExpression $expression @PSBoundParameters

Invoke-PoshspecExpression @params
}
5 changes: 5 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Version 2.1.1
* Added Functions for
* Firewall

# Version 2.1.0
* Broke Down PSM1 to Many Different Functions in their own files [No change in functionality]
* Added Functions for
* CheckSite
* CheckAppPool
* WebSite
* SoftwareProduct


# Version 1.2.2
* Merged PR including 5 new functions
Expand Down
13 changes: 13 additions & 0 deletions Tests/poshspec.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,19 @@ Describe 'Test Functions' {
$results.Expression | Should Be "Test-Path -Path `"IIS:\AppPools\TestSite`" -ErrorAction SilentlyContinue | Should be `$true"
}
}

Context 'Firewall' {
$results = Firewall putty.exe Action { Should be 'Allow' }

It "Should return the correct test Name" {
$results.Name | Should Be "Firewall property 'Action' for 'putty.exe' Should be 'Allow'"
}

It "Should return the correct test Expression" {
$results.Expression | Should Be "Get-NetFirewallRule -DisplayName 'putty.exe' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty 'Action' | Should be 'Allow'"
}
}


Context 'SoftwareProduct' {

Expand Down
7 changes: 7 additions & 0 deletions poshspecdemo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ Describe 'WebSite' {
CheckAppPool TestSite { Should be $True }
AppPoolState TestSite { Should be Started }
}

Describe 'Firewall' {
Firewall putty.exe Enabled { Should be "$True" }
Firewall putty.exe Action { Should be 'Allow' }
Firewall putty.exe Profile { Should be 'Private' }
}

0 comments on commit 353bbe6

Please sign in to comment.