mirror of
https://github.com/CloakHQ/CloakBrowser.git
synced 2026-06-23 11:41:46 +02:00
Adds geoip=True parameter to launch(), launch_async(), and launch_context(). Resolves proxy exit IP → MaxMind GeoLite2-City lookup → timezone + locale. Downloads ~70MB DB on first use from P3TERX mirror, caches in ~/.cloakbrowser/geoip/. Optional deps: pip install cloakbrowser[geoip] / npm install mmdb-lib Explicit timezone/locale always override auto-detected values.
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { COUNTRY_LOCALE_MAP, resolveProxyIp } from "../src/geoip.js";
|
|
|
|
describe("resolveProxyIp", () => {
|
|
it("returns literal IPv4 from proxy URL", async () => {
|
|
expect(await resolveProxyIp("http://10.50.96.5:8888")).toBe("10.50.96.5");
|
|
});
|
|
|
|
it("handles proxy URL with credentials", async () => {
|
|
expect(await resolveProxyIp("http://user:pass@10.50.96.5:8888")).toBe(
|
|
"10.50.96.5"
|
|
);
|
|
});
|
|
|
|
it("resolves localhost", async () => {
|
|
const ip = await resolveProxyIp("http://localhost:8888");
|
|
expect(ip).toBeTruthy();
|
|
expect(["127.0.0.1", "::1"]).toContain(ip);
|
|
});
|
|
|
|
it("returns null for invalid URL", async () => {
|
|
expect(await resolveProxyIp("not-a-url")).toBeNull();
|
|
});
|
|
|
|
it("returns null for empty string", async () => {
|
|
expect(await resolveProxyIp("")).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("COUNTRY_LOCALE_MAP", () => {
|
|
it("contains common countries", () => {
|
|
for (const code of ["US", "GB", "DE", "FR", "JP", "BR", "IL", "RU"]) {
|
|
expect(COUNTRY_LOCALE_MAP[code]).toBeDefined();
|
|
}
|
|
});
|
|
|
|
it("values are BCP 47 language-REGION format", () => {
|
|
for (const [code, locale] of Object.entries(COUNTRY_LOCALE_MAP)) {
|
|
const parts = locale.split("-");
|
|
expect(parts).toHaveLength(2);
|
|
expect(parts[0]).toMatch(/^[a-z]{2,3}$/);
|
|
expect(parts[1]).toMatch(/^[A-Z]{2}$/);
|
|
}
|
|
});
|
|
});
|