-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expand file tree
/
Copy pathhttp.test.ts
More file actions
47 lines (40 loc) · 1.72 KB
/
Copy pathhttp.test.ts
File metadata and controls
47 lines (40 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { expect, it } from "@effect/vitest";
import { describe } from "vite-plus/test";
import { assetResponseHeaders, isLoopbackHostname, resolveDevRedirectUrl } from "./http.ts";
describe("http dev routing", () => {
it("treats localhost and loopback addresses as local", () => {
expect(isLoopbackHostname("127.0.0.1")).toBe(true);
expect(isLoopbackHostname("localhost")).toBe(true);
expect(isLoopbackHostname("::1")).toBe(true);
expect(isLoopbackHostname("[::1]")).toBe(true);
});
it("does not treat LAN addresses as local", () => {
expect(isLoopbackHostname("192.168.86.35")).toBe(false);
expect(isLoopbackHostname("10.0.0.24")).toBe(false);
expect(isLoopbackHostname("example.local")).toBe(false);
});
it("preserves path and query when redirecting to the dev server", () => {
const devUrl = new URL("http://127.0.0.1:5173/");
const requestUrl = new URL("http://127.0.0.1:3774/pair?token=test-token");
expect(resolveDevRedirectUrl(devUrl, requestUrl)).toBe(
"http://127.0.0.1:5173/pair?token=test-token",
);
});
});
describe("assetResponseHeaders", () => {
it("sandboxes SVG assets", () => {
expect(assetResponseHeaders("/attachments/user-image.svg")).toMatchObject({
"Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox",
"X-Content-Type-Options": "nosniff",
});
expect(assetResponseHeaders("/attachments/user-image.SVG")).toHaveProperty(
"Content-Security-Policy",
);
});
it("does not apply document policy to raster images", () => {
expect(assetResponseHeaders("/attachments/user-image.png")).toEqual({
"Cache-Control": "private, max-age=3600",
"X-Content-Type-Options": "nosniff",
});
});
});