Last active
September 25, 2019 06:03
-
-
Save DanielSmon/adb0dd3c0c9c269662c2c53e227bd5f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Test-Redirect($uri, $expectedStatusCode, $expectedRedirect) { | |
try { | |
$result = Invoke-WebRequest -MaximumRedirection 0 -Uri $uri -SkipHeaderValidation | |
Write-Host -ForegroundColor Red "Failed " -NoNewline | |
Write-Host $uri -NoNewline | |
Write-Host " Expected:" $expectedStatusCode $expectedRedirect " " -NoNewline | |
Write-Host "Received:" $result.StatusCode -BackgroundColor Yellow | |
} catch { | |
$_Exception | |
$location = $_.Exception.Response.Headers.Location | |
$statusCode = $_.Exception.Response.StatusCode | |
if($location -eq $expectedRedirect -and $statusCode -eq $expectedStatusCode) | |
{ | |
Write-Host -ForegroundColor Green "Passed " -NoNewline | |
Write-Host $uri -NoNewline | |
Write-Host " Redirects with" $statusCode.value__ "to" $location " " | |
} else { | |
Write-Host -ForegroundColor Red "Failed " -NoNewline | |
Write-Host $uri -NoNewline | |
Write-Host " Expected:" $expectedStatusCode $expectedRedirect " " -NoNewline | |
Write-Host "Received:" $statusCode.value__ $location -BackgroundColor Yellow | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment