Skip to content

Commit 24add73

Browse files
committed
Add CORS testing script - Script to verify CORS headers in Bridge responses - Tests both GET and OPTIONS requests - Shows which CORS headers are present or missing
1 parent 94579c7 commit 24add73

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

‎test-cors.ps1‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Test CORS Headers in Bridge Response
2+
Write-Host "Testing CORS configuration..." -ForegroundColor Cyan
3+
Write-Host ""
4+
5+
# Test 1: Simple GET request
6+
Write-Host "1. Testing GET /health..." -ForegroundColor Yellow
7+
try {
8+
$response = Invoke-WebRequest -Uri "http://localhost:8080/health" -Method GET -UseBasicParsing
9+
Write-Host " Status: $($response.StatusCode) OK" -ForegroundColor Green
10+
Write-Host ""
11+
Write-Host " CORS Headers found:" -ForegroundColor Cyan
12+
13+
$corsHeaders = @()
14+
if ($response.Headers['Access-Control-Allow-Origin']) {
15+
$corsHeaders += "✓ Access-Control-Allow-Origin: $($response.Headers['Access-Control-Allow-Origin'])"
16+
} else {
17+
$corsHeaders += "✗ Access-Control-Allow-Origin: MISSING"
18+
}
19+
20+
if ($response.Headers['Access-Control-Allow-Methods']) {
21+
$corsHeaders += "✓ Access-Control-Allow-Methods: $($response.Headers['Access-Control-Allow-Methods'])"
22+
} else {
23+
$corsHeaders += "✗ Access-Control-Allow-Methods: MISSING"
24+
}
25+
26+
if ($response.Headers['Access-Control-Allow-Headers']) {
27+
$corsHeaders += "✓ Access-Control-Allow-Headers: $($response.Headers['Access-Control-Allow-Headers'])"
28+
} else {
29+
$corsHeaders += "✗ Access-Control-Allow-Headers: MISSING"
30+
}
31+
32+
$corsHeaders | ForEach-Object { Write-Host " $_" -ForegroundColor $(if ($_ -like "✓*") { "Green" } else { "Red" }) }
33+
34+
Write-Host ""
35+
Write-Host " All Headers:" -ForegroundColor Cyan
36+
$response.Headers.GetEnumerator() | Sort-Object Key | ForEach-Object {
37+
Write-Host " $($_.Key): $($_.Value)" -ForegroundColor Gray
38+
}
39+
40+
} catch {
41+
Write-Host " ERROR: Bridge is not running or not accessible" -ForegroundColor Red
42+
Write-Host " Error: $_" -ForegroundColor Red
43+
Write-Host ""
44+
Write-Host " Start Bridge with: .\run-backend.ps1" -ForegroundColor Yellow
45+
exit 1
46+
}
47+
48+
Write-Host ""
49+
Write-Host "2. Testing OPTIONS request (CORS preflight)..." -ForegroundColor Yellow
50+
try {
51+
$optionsResponse = Invoke-WebRequest -Uri "http://localhost:8080/health" -Method OPTIONS `
52+
-Headers @{
53+
"Origin" = "http://localhost:5173"
54+
"Access-Control-Request-Method" = "GET"
55+
"Access-Control-Request-Headers" = "Content-Type"
56+
} -UseBasicParsing
57+
58+
Write-Host " Status: $($optionsResponse.StatusCode) OK" -ForegroundColor Green
59+
Write-Host ""
60+
Write-Host " Preflight CORS Headers:" -ForegroundColor Cyan
61+
62+
if ($optionsResponse.Headers['Access-Control-Allow-Origin']) {
63+
Write-Host " ✓ Access-Control-Allow-Origin: $($optionsResponse.Headers['Access-Control-Allow-Origin'])" -ForegroundColor Green
64+
} else {
65+
Write-Host " ✗ Access-Control-Allow-Origin: MISSING" -ForegroundColor Red
66+
}
67+
68+
if ($optionsResponse.Headers['Access-Control-Allow-Methods']) {
69+
Write-Host " ✓ Access-Control-Allow-Methods: $($optionsResponse.Headers['Access-Control-Allow-Methods'])" -ForegroundColor Green
70+
} else {
71+
Write-Host " ✗ Access-Control-Allow-Methods: MISSING" -ForegroundColor Red
72+
}
73+
74+
if ($optionsResponse.Headers['Access-Control-Max-Age']) {
75+
Write-Host " ✓ Access-Control-Max-Age: $($optionsResponse.Headers['Access-Control-Max-Age'])" -ForegroundColor Green
76+
}
77+
78+
} catch {
79+
Write-Host " ERROR: OPTIONS request failed" -ForegroundColor Red
80+
Write-Host " Error: $_" -ForegroundColor Red
81+
}
82+
83+
Write-Host ""
84+
Write-Host "Summary:" -ForegroundColor Cyan
85+
Write-Host "If you see '✓' for all CORS headers, configuration is correct!" -ForegroundColor Green
86+
Write-Host "If you see '✗' for any header, Bridge needs to be rebuilt." -ForegroundColor Yellow
87+

0 commit comments

Comments
 (0)