test_backend_paths.ps1 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. $ErrorActionPreference = "SilentlyContinue"
  2. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  3. # Login
  4. $body = '{"username":"admin","password":"admin123","tenantCode":"T202605253515"}'
  5. $resp = Invoke-WebRequest -Uri 'http://localhost:8006/login' -Method POST -ContentType 'application/json' -Body $body -UseBasicParsing -TimeoutSec 10
  6. $json = $resp.Content | ConvertFrom-Json
  7. $token = $json.token
  8. Write-Output "Token obtained"
  9. $headers = @{ 'Authorization' = "Bearer $token"; 'Content-Type' = 'application/json' }
  10. # Read backend mappings (deduplicated)
  11. $backendPaths = Get-Content 'd:\ylrz\saasadminui\backend_mappings.txt' | Where-Object { $_ -match '^/[a-z]' } | Sort-Object -Unique
  12. Write-Output "Total backend paths to test: $($backendPaths.Count)"
  13. # Test each backend path with /list appended (most common endpoint)
  14. $results = @{
  15. ok = [System.Collections.ArrayList]::new()
  16. notFound = [System.Collections.ArrayList]::new()
  17. serverError = [System.Collections.ArrayList]::new()
  18. forbidden = [System.Collections.ArrayList]::new()
  19. err = [System.Collections.ArrayList]::new()
  20. }
  21. $i = 0
  22. $total = $backendPaths.Count
  23. foreach ($path in $backendPaths) {
  24. $i++
  25. # Skip paths with {variable}
  26. if ($path -match '\{') { continue }
  27. # Test /list endpoint
  28. $testUrl = "http://localhost:8006${path}/list"
  29. if ($i % 50 -eq 0) {
  30. Write-Output "Progress: $i/$total (OK=$($results.ok.Count) 404=$($results.notFound.Count) 500=$($results.serverError.Count))"
  31. }
  32. try {
  33. $r = Invoke-WebRequest -Uri $testUrl -Method POST -Headers $headers -Body '{}' -UseBasicParsing -TimeoutSec 5
  34. [void]$results.ok.Add("200|$path")
  35. }
  36. catch {
  37. $errMsg = $_.Exception.Message
  38. if ($errMsg -match '404') {
  39. [void]$results.notFound.Add("404|$path")
  40. }
  41. elseif ($errMsg -match '500') {
  42. [void]$results.serverError.Add("500|$path")
  43. }
  44. elseif ($errMsg -match '403|401') {
  45. [void]$results.forbidden.Add("403|$path")
  46. }
  47. else {
  48. [void]$results.err.Add("ERR|$path")
  49. }
  50. }
  51. }
  52. Write-Output ""
  53. Write-Output "=== BACKEND PATHS TESTED WITH /list ==="
  54. Write-Output "OK: $($results.ok.Count)"
  55. Write-Output "404: $($results.notFound.Count)"
  56. Write-Output "500: $($results.serverError.Count)"
  57. Write-Output "403/401: $($results.forbidden.Count)"
  58. Write-Output "ERR: $($results.err.Count)"
  59. # Save all results grouped by first segment
  60. $output = @()
  61. $output += "=== BACKEND PATH TEST SUMMARY ==="
  62. $output += "OK: $($results.ok.Count)"
  63. $output += "404: $($results.notFound.Count)"
  64. $output += "500: $($results.serverError.Count)"
  65. $output += "403: $($results.forbidden.Count)"
  66. $output += "ERR: $($results.err.Count)"
  67. $output += ""
  68. $output += "=== 200 OK PATHS ==="
  69. $output += $results.ok | Sort-Object
  70. $output += ""
  71. $output += "=== 404 PATHS (backend doesn't have /list) ==="
  72. $output += $results.notFound | Sort-Object
  73. $output += ""
  74. $output += "=== 500 PATHS (backend error) ==="
  75. $output += $results.serverError | Sort-Object
  76. $output += ""
  77. $output += "=== 403/401 PATHS ==="
  78. $output += $results.forbidden | Sort-Object
  79. $output | Out-File -FilePath 'd:\ylrz\saasadminui\backend_path_test.txt' -Encoding utf8
  80. Write-Output "Saved to backend_path_test.txt"