You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.7KB

  1. [CmdletBinding()]
  2. param(
  3. [Parameter(Mandatory = $true)]
  4. [string]$BaseUrl
  5. )
  6. $script:failures = 0
  7. function Report {
  8. param($ok, $label, $detail)
  9. if ($ok) {
  10. Write-Output "PASS: $label"
  11. } else {
  12. Write-Output "FAIL: $label ($detail)"
  13. $script:failures++
  14. }
  15. }
  16. try {
  17. $resp = Invoke-WebRequest -Uri "$BaseUrl/hello" -UseBasicParsing
  18. Report ($resp.StatusCode -eq 200) "GET /hello status 200" "got $($resp.StatusCode)"
  19. Report ($resp.Headers['Content-Type'] -eq 'text/html; charset=utf-8') "GET /hello content-type" "got $($resp.Headers['Content-Type'])"
  20. Report ($resp.Content -eq 'Hello from WSC-MVC!') "GET /hello body" "got '$($resp.Content)'"
  21. } catch {
  22. Report $false "GET /hello request" $_.Exception.Message
  23. }
  24. # GET /self-test is the frontend-agnostic JSON harness (Controllers/SelfTestController.wsc) -
  25. # callable from any CLI via plain HTTP, not just PowerShell/cscript on the VM. This exercises
  26. # the same component-level checks as tests/Test-Components.vbs, in-process, over HTTP.
  27. try {
  28. $selfTestResp = Invoke-WebRequest -Uri "$BaseUrl/self-test" -UseBasicParsing
  29. Report ($selfTestResp.StatusCode -eq 200) "GET /self-test status 200" "got $($selfTestResp.StatusCode)"
  30. Report ($selfTestResp.Headers['Content-Type'] -eq 'application/json; charset=utf-8') "GET /self-test content-type" "got $($selfTestResp.Headers['Content-Type'])"
  31. $selfTestJson = $selfTestResp.Content | ConvertFrom-Json
  32. foreach ($check in $selfTestJson.checks) {
  33. Report ([bool]$check.pass) "self-test: $($check.name)" $check.detail
  34. }
  35. Report ([bool]$selfTestJson.ok) "GET /self-test overall ok" "detail in individual checks above"
  36. } catch {
  37. Report $false "GET /self-test request" $_.Exception.Message
  38. }
  39. # Framework/ is a sibling of the "public" webroot, not a rule-denied
  40. # subfolder within it - this checks it's genuinely unreachable, not just
  41. # filtered.
  42. try {
  43. $wscResp = Invoke-WebRequest -Uri "$BaseUrl/Framework/Application.wsc" -UseBasicParsing
  44. Report $false "GET /Framework/Application.wsc unreachable" "got $($wscResp.StatusCode)"
  45. } catch [System.Net.WebException] {
  46. $webResp = $_.Exception.Response
  47. if ($webResp) {
  48. $code = [int]$webResp.StatusCode
  49. Report ($code -eq 404) "GET /Framework/Application.wsc unreachable" "got $code"
  50. } else {
  51. Report $false "GET /Framework/Application.wsc unreachable" $_.Exception.Message
  52. }
  53. } catch {
  54. Report $false "GET /Framework/Application.wsc unreachable" $_.Exception.Message
  55. }
  56. Write-Output "---"
  57. if ($script:failures -eq 0) {
  58. Write-Output "RESULT: ALL PASS"
  59. exit 0
  60. } else {
  61. Write-Output "RESULT: $($script:failures) FAILURE(S)"
  62. exit 1
  63. }

Powered by TurnKey Linux.