Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

161 řádky
5.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. ' --- Application.Run happy path ---
  75. Dim app, ctxHello, helloStatus, helloType, helloBody, helloOk, helloDetail
  76. helloOk = False
  77. helloDetail = ""
  78. On Error Resume Next
  79. Set app = CreateObject("WscMvc.Application")
  80. Set ctxHello = CreateObject("WscMvc.RequestContext")
  81. ctxHello.Initialize "/hello", "GET", logDir
  82. helloStatus = "" : helloType = "" : helloBody = ""
  83. app.Run ctxHello, helloStatus, helloType, helloBody
  84. If Err.Number <> 0 Then
  85. helloDetail = Err.Description
  86. Err.Clear
  87. ElseIf helloStatus <> "200 OK" Then
  88. helloDetail = "Expected 200 OK, got [" & helloStatus & "]"
  89. ElseIf helloType <> "text/html; charset=utf-8" Then
  90. helloDetail = "Unexpected content type [" & helloType & "]"
  91. ElseIf helloBody <> "Hello from WSC-MVC!" Then
  92. helloDetail = "Unexpected body [" & helloBody & "]"
  93. Else
  94. helloOk = True
  95. End If
  96. On Error Goto 0
  97. checks = AppendCheck(checks, "application_run_hello", helloOk, helloDetail)
  98. allPass = allPass And helloOk
  99. ' --- Application.Run unknown route (expected 404, not an error) ---
  100. Dim ctxUnknown, unkStatus, unkType, unkBody, unkOk, unkDetail
  101. unkOk = False
  102. unkDetail = ""
  103. On Error Resume Next
  104. Set ctxUnknown = CreateObject("WscMvc.RequestContext")
  105. ctxUnknown.Initialize "/self-test-does-not-exist", "GET", logDir
  106. unkStatus = "" : unkType = "" : unkBody = ""
  107. app.Run ctxUnknown, unkStatus, unkType, unkBody
  108. If Err.Number <> 0 Then
  109. unkDetail = Err.Description
  110. Err.Clear
  111. ElseIf unkStatus <> "404 Not Found" Then
  112. unkDetail = "Expected 404 Not Found, got [" & unkStatus & "]"
  113. Else
  114. unkOk = True
  115. End If
  116. On Error Goto 0
  117. checks = AppendCheck(checks, "application_run_unknown_route", unkOk, unkDetail)
  118. allPass = allPass And unkOk
  119. Set ctx1 = Nothing
  120. Set ctx2 = Nothing
  121. Set ctxHello = Nothing
  122. Set ctxUnknown = Nothing
  123. Set app = Nothing
  124. body = "{""ok"":" & LCase(CStr(allPass)) & ",""checks"":[" & checks & "]}"
  125. End Sub
  126. Function AppendCheck(checksSoFar, name, pass, detail)
  127. Dim entry
  128. entry = "{""name"":""" & JsonEscape(name) & """,""pass"":" & LCase(CStr(pass)) & _
  129. ",""detail"":""" & JsonEscape(detail) & """}"
  130. If Len(checksSoFar) = 0 Then
  131. AppendCheck = entry
  132. Else
  133. AppendCheck = checksSoFar & "," & entry
  134. End If
  135. End Function
  136. Function JsonEscape(s)
  137. Dim result
  138. result = s
  139. result = Replace(result, "\", "\\")
  140. result = Replace(result, """", "\""")
  141. result = Replace(result, vbCrLf, "\n")
  142. result = Replace(result, vbCr, "\n")
  143. result = Replace(result, vbLf, "\n")
  144. result = Replace(result, vbTab, "\t")
  145. JsonEscape = result
  146. End Function
  147. ]]>
  148. </script>
  149. </component>

Powered by TurnKey Linux.