25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

117 satır
4.5KB

  1. [CmdletBinding()]
  2. param(
  3. [Parameter(Mandatory = $true)]
  4. [string]$BaseUrl,
  5. [string]$TestBaseUrl
  6. )
  7. $script:failures = 0
  8. function Report {
  9. param($ok, $label, $detail)
  10. if ($ok) {
  11. Write-Output "PASS: $label"
  12. } else {
  13. Write-Output "FAIL: $label ($detail)"
  14. $script:failures++
  15. }
  16. }
  17. try {
  18. $resp = Invoke-WebRequest -Uri "$BaseUrl/hello" -UseBasicParsing
  19. Report ($resp.StatusCode -eq 200) "GET /hello status 200" "got $($resp.StatusCode)"
  20. Report ($resp.Headers['Content-Type'] -eq 'text/html; charset=utf-8') "GET /hello content-type" "got $($resp.Headers['Content-Type'])"
  21. Report ($resp.Content -eq 'Hello from WSC-MVC!') "GET /hello body" "got '$($resp.Content)'"
  22. } catch {
  23. Report $false "GET /hello request" $_.Exception.Message
  24. }
  25. try {
  26. $rootResp = Invoke-WebRequest -Uri "$BaseUrl/" -UseBasicParsing
  27. Report ($rootResp.StatusCode -eq 200) "GET / status 200" "got $($rootResp.StatusCode)"
  28. Report ($rootResp.Content -eq 'Hello from WSC-MVC!') "GET / maps to /hello" "got '$($rootResp.Content)'"
  29. } catch {
  30. Report $false "GET / request" $_.Exception.Message
  31. }
  32. # /self-test lives on the separate test-app/ site now (see docs/ARCHITECTURE.md
  33. # and tests/run-self-test.sh, which is what actually exercises it) - this
  34. # script tests the production app only. Confirm the diagnostics endpoint is
  35. # genuinely NOT exposed here, since that separation is the point.
  36. try {
  37. $selfTestResp = Invoke-WebRequest -Uri "$BaseUrl/self-test" -UseBasicParsing
  38. Report $false "GET /self-test not exposed on production" "got $($selfTestResp.StatusCode)"
  39. } catch [System.Net.WebException] {
  40. $webResp = $_.Exception.Response
  41. if ($webResp) {
  42. $code = [int]$webResp.StatusCode
  43. Report ($code -eq 404) "GET /self-test not exposed on production" "got $code"
  44. } else {
  45. Report $false "GET /self-test not exposed on production" $_.Exception.Message
  46. }
  47. } catch {
  48. Report $false "GET /self-test not exposed on production" $_.Exception.Message
  49. }
  50. # A caller can request Default.asp directly and supply the internal route
  51. # query string, bypassing URL Rewrite. The per-app route-set argument must
  52. # still prevent production from activating the test controller.
  53. try {
  54. $directSelfTestResp = Invoke-WebRequest -Uri "$BaseUrl/Default.asp?route=/self-test" -UseBasicParsing
  55. Report $false "direct Default.asp cannot cross into test routes" "got $($directSelfTestResp.StatusCode)"
  56. } catch [System.Net.WebException] {
  57. $webResp = $_.Exception.Response
  58. if ($webResp) {
  59. $code = [int]$webResp.StatusCode
  60. Report ($code -eq 404) "direct Default.asp cannot cross into test routes" "got $code"
  61. } else {
  62. Report $false "direct Default.asp cannot cross into test routes" $_.Exception.Message
  63. }
  64. } catch {
  65. Report $false "direct Default.asp cannot cross into test routes" $_.Exception.Message
  66. }
  67. if ($TestBaseUrl) {
  68. try {
  69. $directHelloResp = Invoke-WebRequest -Uri "$TestBaseUrl/Default.asp?route=/hello" -UseBasicParsing
  70. Report $false "test app cannot cross into production routes" "got $($directHelloResp.StatusCode)"
  71. } catch [System.Net.WebException] {
  72. $webResp = $_.Exception.Response
  73. if ($webResp) {
  74. $code = [int]$webResp.StatusCode
  75. Report ($code -eq 404) "test app cannot cross into production routes" "got $code"
  76. } else {
  77. Report $false "test app cannot cross into production routes" $_.Exception.Message
  78. }
  79. } catch {
  80. Report $false "test app cannot cross into production routes" $_.Exception.Message
  81. }
  82. }
  83. # Framework/ is a sibling of the "public" webroot, not a rule-denied
  84. # subfolder within it - this checks it's genuinely unreachable, not just
  85. # filtered.
  86. try {
  87. $wscResp = Invoke-WebRequest -Uri "$BaseUrl/Framework/Application.wsc" -UseBasicParsing
  88. Report $false "GET /Framework/Application.wsc unreachable" "got $($wscResp.StatusCode)"
  89. } catch [System.Net.WebException] {
  90. $webResp = $_.Exception.Response
  91. if ($webResp) {
  92. $code = [int]$webResp.StatusCode
  93. Report ($code -eq 404) "GET /Framework/Application.wsc unreachable" "got $code"
  94. } else {
  95. Report $false "GET /Framework/Application.wsc unreachable" $_.Exception.Message
  96. }
  97. } catch {
  98. Report $false "GET /Framework/Application.wsc unreachable" $_.Exception.Message
  99. }
  100. Write-Output "---"
  101. if ($script:failures -eq 0) {
  102. Write-Output "RESULT: ALL PASS"
  103. exit 0
  104. } else {
  105. Write-Output "RESULT: $($script:failures) FAILURE(S)"
  106. exit 1
  107. }

Powered by TurnKey Linux.