Skip to content

Commit 878971d

Browse files
committed
add CORS live tests
1 parent 4bc4af0 commit 878971d

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/live/cors.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { describe, expect, test } from "vitest";
2+
import { getBaseEndpoint } from "./utils.js";
3+
4+
const baseEndpoint = getBaseEndpoint();
5+
6+
describe("CORS tests", async () => {
7+
test("Events: Known URL is allowed in CORS", async () => {
8+
const response = await fetch(`${baseEndpoint}/api/v1/events`, {
9+
headers: {
10+
Origin: "https://acmuiuc.pages.dev",
11+
},
12+
});
13+
expect(response.status).toBe(200);
14+
expect(response.headers.get("access-control-allow-origin")).toStrictEqual(
15+
"https://acmuiuc.pages.dev",
16+
);
17+
});
18+
test("Events: Unknown URL is not allowed in CORS", async () => {
19+
const response = await fetch(`${baseEndpoint}/api/v1/events`, {
20+
headers: {
21+
Origin: "https://google.com",
22+
},
23+
});
24+
expect(response.status).toBe(200);
25+
expect(response.headers).not.toHaveProperty("access-control-allow-origin");
26+
});
27+
test("Membership: Known URL is allowed in CORS", async () => {
28+
const response = await fetch(`${baseEndpoint}/api/v1/membership/zzzzzz`, {
29+
headers: {
30+
Origin: "https://acmuiuc.pages.dev",
31+
},
32+
});
33+
expect(response.status).toBe(200);
34+
expect(response.headers.get("access-control-allow-origin")).toStrictEqual(
35+
"https://acmuiuc.pages.dev",
36+
);
37+
});
38+
test("Membership: Unknown URL is not allowed in CORS", async () => {
39+
const response = await fetch(`${baseEndpoint}/api/v1/membership/zzzzzz`, {
40+
headers: {
41+
Origin: "https://google.com",
42+
},
43+
});
44+
expect(response.status).toBe(200);
45+
expect(response.headers).not.toHaveProperty("access-control-allow-origin");
46+
});
47+
});

0 commit comments

Comments
 (0)