forked from tomtorggler/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStart-TestWebServer.Tests.ps1
34 lines (34 loc) · 1.71 KB
/
Start-TestWebServer.Tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# find current path to use when starting process
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
Describe "Testing Web Server" {
# Start another instance of powershell as the script blocks the console
# use Verb RunAs to start the new instance as admin
Start-Process powershell -Argument "$here\Start-TestWebServer.ps1 -Port 80 -CreateFirewallRule" -Verb RunAs
# Wait a sec for the instance to come up
Start-Sleep -Seconds 5
Context "Starting" {
It "Creates a firewall rule upon starting" {
(Get-NetFirewallRule -PolicyStore ActiveStore -DisplayName "Allow PS TestWS Port*") -is [Microsoft.Management.Infrastructure.CimInstance] | Should Be True
}
It "creates a listening tcp connection" {
(Get-NetTCPConnection -LocalPort 80 -State Listen) -is [Microsoft.Management.Infrastructure.CimInstance] | Should Be True
}
It "returns the requests as json object" {
$response = Invoke-RestMethod http://localhost/
$response | Select-Object -ExpandProperty UserAgent | Should Match 'WindowsPowerShell'
}
It "returns 'Bye' when sending /end" {
Invoke-RestMethod -Uri http://localhost/end | Should Match 'Bye'
}
}
Context "Stopping" {
# Wait a sec for the process to stopping
Start-Sleep -Seconds 5
It "Remove firewall rule when stopping" {
$null = Get-NetFirewallRule -PolicyStore ActiveStore -DisplayName "Allow PS TestWS Port*" | Should throw
}
It "removes the listening tcp connection" {
Get-NetTCPConnection -State Listen | Where-Object LocalPort -eq 80 | Should Be $null
}
}
}