Skip to content

Commit 5e92ace

Browse files
committed
fix: update CORS E2E tests to use configured origin
Tests were sending Origin headers (localhost:3000, example.com) that don't match the CORS_ORIGINS allowlist. Updated to use http://localhost:8787 and assert the echoed origin instead of wildcard '*'.
1 parent 0a2b3d6 commit 5e92ace

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

tests/e2e/07-api.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,18 @@ test.describe('API Endpoints', () => {
5555
});
5656

5757
test('should handle CORS for API endpoints', async ({ request }) => {
58+
// Use the origin configured in CORS_ORIGINS (wrangler.toml)
5859
const response = await request.get('/api', {
5960
headers: {
60-
'Origin': 'http://localhost:3000'
61+
'Origin': 'http://localhost:8787'
6162
}
6263
});
63-
64+
6465
expect(response.ok()).toBeTruthy();
65-
66-
// Check for CORS headers
66+
67+
// Check for CORS headers — should echo back the allowed origin
6768
const corsHeader = response.headers()['access-control-allow-origin'];
68-
expect(corsHeader).toBeDefined();
69+
expect(corsHeader).toBe('http://localhost:8787');
6970
});
7071

7172
test('should handle content negotiation', async ({ request }) => {

tests/e2e/08-collections-api.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,16 @@ test.describe('Collections API', () => {
7878
});
7979

8080
test('should handle CORS headers', async ({ request }) => {
81+
// Use the origin configured in CORS_ORIGINS (wrangler.toml)
8182
const response = await request.get('/api/collections', {
8283
headers: {
83-
'Origin': 'https://example.com'
84+
'Origin': 'http://localhost:8787'
8485
}
8586
});
86-
87+
8788
expect(response.ok()).toBeTruthy();
88-
expect(response.headers()['access-control-allow-origin']).toBe('*');
89+
// CORS now echoes back the allowed origin instead of wildcard
90+
expect(response.headers()['access-control-allow-origin']).toBe('http://localhost:8787');
8991
});
9092

9193
test('should have consistent timestamp format', async ({ request }) => {

tests/e2e/smoke.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,18 @@ test.describe('Smoke Tests - Critical Path', () => {
248248
});
249249

250250
test('CORS headers are present on API endpoints', async ({ request }) => {
251+
// Use the origin configured in CORS_ORIGINS (wrangler.toml)
251252
const response = await request.get('/api', {
252253
headers: {
253-
'Origin': 'http://localhost:3000'
254+
'Origin': 'http://localhost:8787'
254255
}
255256
});
256257

257258
expect(response.ok()).toBeTruthy();
258259

259-
// Verify CORS header is present
260+
// Verify CORS header echoes back the allowed origin
260261
const corsHeader = response.headers()['access-control-allow-origin'];
261-
expect(corsHeader).toBeDefined();
262-
expect(corsHeader).toBeTruthy();
262+
expect(corsHeader).toBe('http://localhost:8787');
263263
});
264264

265265
test('API returns correct content-type headers', async ({ request }) => {

0 commit comments

Comments
 (0)