|
| 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