forked from Lilly-Protocol/lily-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.test.ts
More file actions
41 lines (32 loc) · 1.14 KB
/
Copy pathenv.test.ts
File metadata and controls
41 lines (32 loc) · 1.14 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
import { describe, expect, it } from "vitest";
import { trustProxySchema } from "../../src/config/env";
describe("TRUST_PROXY validation", () => {
it('accepts "false" and transforms to boolean false', () => {
const result = trustProxySchema.parse("false");
expect(result).toBe(false);
});
it('rejects "true" (unsafe in production)', () => {
expect(() => trustProxySchema.parse("true")).toThrow();
});
it("accepts numeric string hop counts", () => {
const result = trustProxySchema.parse("1");
expect(result).toBe(1);
});
it("accepts zero as valid hop count", () => {
const result = trustProxySchema.parse("0");
expect(result).toBe(0);
});
it("rejects negative numbers", () => {
expect(() => trustProxySchema.parse("-1")).toThrow();
});
it("rejects non-numeric strings", () => {
expect(() => trustProxySchema.parse("yes")).toThrow();
});
it("rejects floating point numbers", () => {
expect(() => trustProxySchema.parse("1.5")).toThrow();
});
it("defaults to false when not provided", () => {
const result = trustProxySchema.parse(undefined);
expect(result).toBe(false);
});
});