forked from Lilly-Protocol/lily-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrust-proxy-validation.test.ts
More file actions
59 lines (50 loc) · 1.78 KB
/
Copy pathtrust-proxy-validation.test.ts
File metadata and controls
59 lines (50 loc) · 1.78 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
48
49
50
51
52
53
54
55
56
57
58
59
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
describe("TRUST_PROXY configuration validation (issue #80)", () => {
const originalEnv = process.env;
beforeEach(() => {
vi.resetModules();
process.env = { ...originalEnv };
});
afterEach(() => {
process.env = originalEnv;
vi.restoreAllMocks();
});
it("should accept 'false' and transform to boolean false", async () => {
process.env.TRUST_PROXY = "false";
process.env.NODE_ENV = "test";
const { env } = await import("../src/config/env");
expect(env.TRUST_PROXY).toBe(false);
});
it("should accept numeric hop counts as strings", async () => {
process.env.TRUST_PROXY = "1";
process.env.NODE_ENV = "test";
const { env } = await import("../src/config/env");
expect(env.TRUST_PROXY).toBe(1);
});
it("should accept 'loopback' as a valid value", async () => {
process.env.TRUST_PROXY = "loopback";
process.env.NODE_ENV = "test";
const { env } = await import("../src/config/env");
expect(env.TRUST_PROXY).toBe("loopback");
});
it("should reject 'true' as unsafe", async () => {
process.env.TRUST_PROXY = "true";
process.env.NODE_ENV = "test";
await expect(import("../src/config/env")).rejects.toThrow(
"Invalid environment configuration",
);
});
it("should reject arbitrary string values", async () => {
process.env.TRUST_PROXY = "yolo";
process.env.NODE_ENV = "test";
await expect(import("../src/config/env")).rejects.toThrow(
"Invalid environment configuration",
);
});
it("should default to false when unset", async () => {
delete process.env.TRUST_PROXY;
process.env.NODE_ENV = "test";
const { env } = await import("../src/config/env");
expect(env.TRUST_PROXY).toBe(false);
});
});