25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
4.1KB

  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. # /self-test lives on the separate test-app/ site now (see docs/ARCHITECTURE.md
  26. # and tests/run-self-test.sh, which is what actually exercises it) - this
  27. # script tests the production app only. Confirm the diagnostics endpoint is
  28. # genuinely NOT exposed here, since that separation is the point.
  29. try {
  30. $selfTestResp = Invoke-WebRequest -Uri "$BaseUrl/self-test" -UseBasicParsing
  31. Report $false "GET /self-test not exposed on production" "got $($selfTestResp.StatusCode)"
  32. } catch [System.Net.WebException] {
  33. $webResp = $_.Exception.Response
  34. if ($webResp) {
  35. $code = [int]$webResp.StatusCode
  36. Report ($code -eq 404) "GET /self-test not exposed on production" "got $code"
  37. } else {
  38. Report $false "GET /self-test not exposed on production" $_.Exception.Message
  39. }
  40. } catch {
  41. Report $false "GET /self-test not exposed on production" $_.Exception.Message
  42. }
  43. # A caller can request Default.asp directly and supply the internal route
  44. # query string, bypassing URL Rewrite. The per-app route-set argument must
  45. # still prevent production from activating the test controller.
  46. try {
  47. $directSelfTestResp = Invoke-WebRequest -Uri "$BaseUrl/Default.asp?route=/self-test" -UseBasicParsing
  48. Report $false "direct Default.asp cannot cross into test routes" "got $($directSelfTestResp.StatusCode)"
  49. } catch [System.Net.WebException] {
  50. $webResp = $_.Exception.Response
  51. if ($webResp) {
  52. $code = [int]$webResp.StatusCode
  53. Report ($code -eq 404) "direct Default.asp cannot cross into test routes" "got $code"
  54. } else {
  55. Report $false "direct Default.asp cannot cross into test routes" $_.Exception.Message
  56. }
  57. } catch {
  58. Report $false "direct Default.asp cannot cross into test routes" $_.Exception.Message
  59. }
  60. if ($TestBaseUrl) {
  61. try {
  62. $directHelloResp = Invoke-WebRequest -Uri "$TestBaseUrl/Default.asp?route=/hello" -UseBasicParsing
  63. Report $false "test app cannot cross into production routes" "got $($directHelloResp.StatusCode)"
  64. } catch [System.Net.WebException] {
  65. $webResp = $_.Exception.Response
  66. if ($webResp) {
  67. $code = [int]$webResp.StatusCode
  68. Report ($code -eq 404) "test app cannot cross into production routes" "got $code"
  69. } else {
  70. Report $false "test app cannot cross into production routes" $_.Exception.Message
  71. }
  72. } catch {
  73. Report $false "test app cannot cross into production routes" $_.Exception.Message
  74. }
  75. }
  76. # Framework/ is a sibling of the "public" webroot, not a rule-denied
  77. # subfolder within it - this checks it's genuinely unreachable, not just
  78. # filtered.
  79. try {
  80. $wscResp = Invoke-WebRequest -Uri "$BaseUrl/Framework/Application.wsc" -UseBasicParsing
  81. Report $false "GET /Framework/Application.wsc unreachable" "got $($wscResp.StatusCode)"
  82. } catch [System.Net.WebException] {
  83. $webResp = $_.Exception.Response
  84. if ($webResp) {
  85. $code = [int]$webResp.StatusCode
  86. Report ($code -eq 404) "GET /Framework/Application.wsc unreachable" "got $code"
  87. } else {
  88. Report $false "GET /Framework/Application.wsc unreachable" $_.Exception.Message
  89. }
  90. } catch {
  91. Report $false "GET /Framework/Application.wsc unreachable" $_.Exception.Message
  92. }
  93. Write-Output "---"
  94. if ($script:failures -eq 0) {
  95. Write-Output "RESULT: ALL PASS"
  96. exit 0
  97. } else {
  98. Write-Output "RESULT: $($script:failures) FAILURE(S)"
  99. exit 1
  100. }

Powered by TurnKey Linux.