import { describe, expect, it } from "vitest"; import { getClientIp, NoopIpIntelligenceProvider } from "../src/index"; describe("client IP extraction", () => { it("ignores spoofable forwarding headers unless a trusted proxy is configured", () => { const headers = new Headers({ "x-forwarded-for": "203.0.113.1" }); expect(getClientIp(headers, false)).toBeNull(); }); it("uses the first valid address supplied by a trusted proxy", () => { const headers = new Headers({ "x-forwarded-for": "203.0.113.1, 10.0.0.2" }); expect(getClientIp(headers, true)).toBe("203.0.113.1"); }); it("rejects malformed proxy values", () => { expect(getClientIp(new Headers({ "x-forwarded-for": "not-an-ip" }), true)).toBeNull(); }); }); describe("VPN intelligence", () => { it("explicitly reports unknown when no provider is configured", async () => { await expect(new NoopIpIntelligenceProvider().classify("203.0.113.1")).resolves.toEqual({ classification: "unknown", provider: null, }); }); });