Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

136 wiersze
4.5KB

  1. <?xml version="1.0"?>
  2. <?component error="true" debug="false"?>
  3. <component>
  4. <registration
  5. description="WscMvc SelfTestController"
  6. progid="WscMvc.SelfTestController"
  7. version="1.00"
  8. classid="{D2634944-4646-4C55-956E-4C05E7E10904}">
  9. </registration>
  10. <public>
  11. <method name="RunSelfTest">
  12. <parameter name="logDir"/>
  13. <parameter name="body"/>
  14. </method>
  15. </public>
  16. <script language="VBScript">
  17. <![CDATA[
  18. Option Explicit
  19. ' HTTP+JSON test harness, callable as GET /self-test from any CLI (curl,
  20. ' Invoke-WebRequest, etc.) - no cscript/PowerShell/WSH access to the VM
  21. ' required. Runs the same checks as tests/Test-Components.vbs, in-process,
  22. ' against the live registered components. Intentionally returns raw
  23. ' Err.Description in failure details: unlike Default.asp's own error
  24. ' handling (which must never leak internals to an arbitrary client), this
  25. ' route IS the diagnostics surface, so its whole job is to say what broke.
  26. ' This is a dev/test-milestone tool, not a production data endpoint -
  27. ' revisit whether it should be gated/removed during M6 hardening.
  28. Sub RunSelfTest(logDir, body)
  29. Dim checks, allPass
  30. checks = ""
  31. allPass = True
  32. ' --- RequestContext basic contract ---
  33. Dim ctx1, ctx1Ok, ctx1Detail
  34. ctx1Ok = False
  35. ctx1Detail = ""
  36. On Error Resume Next
  37. Set ctx1 = CreateObject("WscMvc.RequestContext")
  38. If Err.Number = 0 Then ctx1.Initialize "/self-test-a", "GET", logDir
  39. If Err.Number <> 0 Then
  40. ctx1Detail = Err.Description
  41. Err.Clear
  42. ElseIf ctx1.Path <> "/self-test-a" Then
  43. ctx1Detail = "Path roundtrip mismatch: got [" & ctx1.Path & "]"
  44. ElseIf ctx1.HttpMethod <> "GET" Then
  45. ctx1Detail = "HttpMethod roundtrip mismatch: got [" & ctx1.HttpMethod & "]"
  46. ElseIf Len(ctx1.CorrelationId) = 0 Then
  47. ctx1Detail = "CorrelationId was empty"
  48. ElseIf ctx1.ElapsedMs() < 0 Then
  49. ctx1Detail = "ElapsedMs was negative"
  50. Else
  51. ctx1Ok = True
  52. End If
  53. On Error Goto 0
  54. checks = AppendCheck(checks, "request_context_contract", ctx1Ok, ctx1Detail)
  55. allPass = allPass And ctx1Ok
  56. ' --- Two contexts must not collide on correlation id ---
  57. Dim ctx2, distinctOk, distinctDetail
  58. distinctOk = False
  59. distinctDetail = ""
  60. On Error Resume Next
  61. Set ctx2 = CreateObject("WscMvc.RequestContext")
  62. ctx2.Initialize "/self-test-b", "GET", logDir
  63. If Err.Number <> 0 Then
  64. distinctDetail = Err.Description
  65. Err.Clear
  66. ElseIf ctx1.CorrelationId = ctx2.CorrelationId Then
  67. distinctDetail = "Both contexts produced the same CorrelationId: " & ctx1.CorrelationId
  68. Else
  69. distinctOk = True
  70. End If
  71. On Error Goto 0
  72. checks = AppendCheck(checks, "correlation_id_uniqueness", distinctOk, distinctDetail)
  73. allPass = allPass And distinctOk
  74. ' --- Shared Application must isolate route sets. The test app must not
  75. ' activate or test production's HomeController. ---
  76. Dim app, ctxUnknown, unkStatus, unkType, unkBody, unkOk, unkDetail
  77. unkOk = False
  78. unkDetail = ""
  79. On Error Resume Next
  80. Set app = CreateObject("WscMvc.Application")
  81. Set ctxUnknown = CreateObject("WscMvc.RequestContext")
  82. ctxUnknown.Initialize "/hello", "GET", logDir
  83. unkStatus = "" : unkType = "" : unkBody = ""
  84. app.Run ctxUnknown, "tests", unkStatus, unkType, unkBody
  85. If Err.Number <> 0 Then
  86. unkDetail = Err.Description
  87. Err.Clear
  88. ElseIf unkStatus <> "404 Not Found" Then
  89. unkDetail = "Expected 404 Not Found, got [" & unkStatus & "]"
  90. Else
  91. unkOk = True
  92. End If
  93. On Error Goto 0
  94. checks = AppendCheck(checks, "test_app_rejects_production_route", unkOk, unkDetail)
  95. allPass = allPass And unkOk
  96. Set ctx1 = Nothing
  97. Set ctx2 = Nothing
  98. Set ctxUnknown = Nothing
  99. Set app = Nothing
  100. body = "{""ok"":" & LCase(CStr(allPass)) & ",""checks"":[" & checks & "]}"
  101. End Sub
  102. Function AppendCheck(checksSoFar, name, pass, detail)
  103. Dim entry
  104. entry = "{""name"":""" & JsonEscape(name) & """,""pass"":" & LCase(CStr(pass)) & _
  105. ",""detail"":""" & JsonEscape(detail) & """}"
  106. If Len(checksSoFar) = 0 Then
  107. AppendCheck = entry
  108. Else
  109. AppendCheck = checksSoFar & "," & entry
  110. End If
  111. End Function
  112. Function JsonEscape(s)
  113. Dim result
  114. result = s
  115. result = Replace(result, "\", "\\")
  116. result = Replace(result, """", "\""")
  117. result = Replace(result, vbCrLf, "\n")
  118. result = Replace(result, vbCr, "\n")
  119. result = Replace(result, vbLf, "\n")
  120. result = Replace(result, vbTab, "\t")
  121. JsonEscape = result
  122. End Function
  123. ]]>
  124. </script>
  125. </component>

Powered by TurnKey Linux.