test_auth.ps1 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Compare auth vs no-auth on fs-admin
  2. $loginBody = @{
  3. tenantCode = "T202605253515"
  4. username = "admin"
  5. password = "admin123"
  6. } | ConvertTo-Json
  7. $resp = Invoke-RestMethod -Uri "http://localhost:8006/login" -Method POST -ContentType "application/json" -Body $loginBody
  8. $token = $resp.token
  9. Write-Output "=== NO AUTH ==="
  10. try {
  11. $r = Invoke-WebRequest -Uri "http://localhost:8003/his/healthTongue/list" -Method GET -UseBasicParsing -ErrorAction Stop
  12. $body = $r.Content | ConvertFrom-Json
  13. Write-Output " HTTP $($r.StatusCode) code=$($body.code) msg=$($body.msg)"
  14. } catch {
  15. Write-Output " HTTP $($_.Exception.Response.StatusCode.value__)"
  16. }
  17. Write-Output ""
  18. Write-Output "=== WITH AUTH (fs-company token) ==="
  19. try {
  20. $headers = @{ Authorization = "Bearer $token" }
  21. $r = Invoke-WebRequest -Uri "http://localhost:8003/his/healthTongue/list" -Method GET -Headers $headers -UseBasicParsing -ErrorAction Stop
  22. $body = $r.Content | ConvertFrom-Json
  23. Write-Output " HTTP $($r.StatusCode) code=$($body.code) msg=$($body.msg)"
  24. } catch {
  25. $status = $_.Exception.Response.StatusCode.value__
  26. Write-Output " HTTP $status"
  27. if ($_.Exception.Response) {
  28. $reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
  29. $reader.BaseStream.Position = 0
  30. $respBody = $reader.ReadToEnd()
  31. Write-Output " Body: $($respBody.Substring(0, [Math]::Min(200, $respBody.Length)))"
  32. }
  33. }
  34. Write-Output ""
  35. Write-Output "=== Login on fs-admin directly ==="
  36. $adminLoginBody = @{
  37. username = "admin"
  38. password = "admin123"
  39. } | ConvertTo-Json
  40. try {
  41. $adminResp = Invoke-RestMethod -Uri "http://localhost:8003/login" -Method POST -ContentType "application/json" -Body $adminLoginBody
  42. Write-Output " Login code=$($adminResp.code) msg=$($adminResp.msg)"
  43. if ($adminResp.token) {
  44. $adminToken = $adminResp.token
  45. Write-Output " Admin token obtained!"
  46. Write-Output ""
  47. Write-Output "=== WITH fs-admin TOKEN ==="
  48. $adminHeaders = @{ Authorization = "Bearer $adminToken" }
  49. try {
  50. $r2 = Invoke-WebRequest -Uri "http://localhost:8003/his/healthTongue/list" -Method GET -Headers $adminHeaders -UseBasicParsing -ErrorAction Stop
  51. $body2 = $r2.Content | ConvertFrom-Json
  52. Write-Output " HTTP $($r2.StatusCode) code=$($body2.code) msg=$($body2.msg)"
  53. } catch {
  54. Write-Output " HTTP $($_.Exception.Response.StatusCode.value__)"
  55. }
  56. }
  57. } catch {
  58. Write-Output " Login error: $($_.Exception.Message)"
  59. }