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.

73 line
2.6KB

  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. # /self-test lives on the separate test-app/ site now (see docs/ARCHITECTURE.md
  25. # and tests/run-self-test.sh, which is what actually exercises it) - this
  26. # script tests the production app only. Confirm the diagnostics endpoint is
  27. # genuinely NOT exposed here, since that separation is the point.
  28. try {
  29. $selfTestResp = Invoke-WebRequest -Uri "$BaseUrl/self-test" -UseBasicParsing
  30. Report $false "GET /self-test not exposed on production" "got $($selfTestResp.StatusCode)"
  31. } catch [System.Net.WebException] {
  32. $webResp = $_.Exception.Response
  33. if ($webResp) {
  34. $code = [int]$webResp.StatusCode
  35. Report ($code -eq 404) "GET /self-test not exposed on production" "got $code"
  36. } else {
  37. Report $false "GET /self-test not exposed on production" $_.Exception.Message
  38. }
  39. } catch {
  40. Report $false "GET /self-test not exposed on production" $_.Exception.Message
  41. }
  42. # Framework/ is a sibling of the "public" webroot, not a rule-denied
  43. # subfolder within it - this checks it's genuinely unreachable, not just
  44. # filtered.
  45. try {
  46. $wscResp = Invoke-WebRequest -Uri "$BaseUrl/Framework/Application.wsc" -UseBasicParsing
  47. Report $false "GET /Framework/Application.wsc unreachable" "got $($wscResp.StatusCode)"
  48. } catch [System.Net.WebException] {
  49. $webResp = $_.Exception.Response
  50. if ($webResp) {
  51. $code = [int]$webResp.StatusCode
  52. Report ($code -eq 404) "GET /Framework/Application.wsc unreachable" "got $code"
  53. } else {
  54. Report $false "GET /Framework/Application.wsc unreachable" $_.Exception.Message
  55. }
  56. } catch {
  57. Report $false "GET /Framework/Application.wsc unreachable" $_.Exception.Message
  58. }
  59. Write-Output "---"
  60. if ($script:failures -eq 0) {
  61. Write-Output "RESULT: ALL PASS"
  62. exit 0
  63. } else {
  64. Write-Output "RESULT: $($script:failures) FAILURE(S)"
  65. exit 1
  66. }

Powered by TurnKey Linux.