|
- [CmdletBinding()]
- param(
- [Parameter(Mandatory = $true)]
- [string]$BaseUrl
- )
-
- $script:failures = 0
-
- function Report {
- param($ok, $label, $detail)
- if ($ok) {
- Write-Output "PASS: $label"
- } else {
- Write-Output "FAIL: $label ($detail)"
- $script:failures++
- }
- }
-
- try {
- $resp = Invoke-WebRequest -Uri "$BaseUrl/hello" -UseBasicParsing
- Report ($resp.StatusCode -eq 200) "GET /hello status 200" "got $($resp.StatusCode)"
- Report ($resp.Headers['Content-Type'] -eq 'text/html; charset=utf-8') "GET /hello content-type" "got $($resp.Headers['Content-Type'])"
- Report ($resp.Content -eq 'Hello from WSC-MVC!') "GET /hello body" "got '$($resp.Content)'"
- } catch {
- Report $false "GET /hello request" $_.Exception.Message
- }
-
- # GET /self-test is the frontend-agnostic JSON harness (Controllers/SelfTestController.wsc) -
- # callable from any CLI via plain HTTP, not just PowerShell/cscript on the VM. This exercises
- # the same component-level checks as tests/Test-Components.vbs, in-process, over HTTP.
- try {
- $selfTestResp = Invoke-WebRequest -Uri "$BaseUrl/self-test" -UseBasicParsing
- Report ($selfTestResp.StatusCode -eq 200) "GET /self-test status 200" "got $($selfTestResp.StatusCode)"
- Report ($selfTestResp.Headers['Content-Type'] -eq 'application/json; charset=utf-8') "GET /self-test content-type" "got $($selfTestResp.Headers['Content-Type'])"
- $selfTestJson = $selfTestResp.Content | ConvertFrom-Json
- foreach ($check in $selfTestJson.checks) {
- Report ([bool]$check.pass) "self-test: $($check.name)" $check.detail
- }
- Report ([bool]$selfTestJson.ok) "GET /self-test overall ok" "detail in individual checks above"
- } catch {
- Report $false "GET /self-test request" $_.Exception.Message
- }
-
- # Framework/ is a sibling of the "public" webroot, not a rule-denied
- # subfolder within it - this checks it's genuinely unreachable, not just
- # filtered.
- try {
- $wscResp = Invoke-WebRequest -Uri "$BaseUrl/Framework/Application.wsc" -UseBasicParsing
- Report $false "GET /Framework/Application.wsc unreachable" "got $($wscResp.StatusCode)"
- } catch [System.Net.WebException] {
- $webResp = $_.Exception.Response
- if ($webResp) {
- $code = [int]$webResp.StatusCode
- Report ($code -eq 404) "GET /Framework/Application.wsc unreachable" "got $code"
- } else {
- Report $false "GET /Framework/Application.wsc unreachable" $_.Exception.Message
- }
- } catch {
- Report $false "GET /Framework/Application.wsc unreachable" $_.Exception.Message
- }
-
- Write-Output "---"
- if ($script:failures -eq 0) {
- Write-Output "RESULT: ALL PASS"
- exit 0
- } else {
- Write-Output "RESULT: $($script:failures) FAILURE(S)"
- exit 1
- }
|