mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-18 21:40:53 +00:00
55 lines
2.0 KiB
TypeScript
55 lines
2.0 KiB
TypeScript
import os from "node:os";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
isTailnetIPv4,
|
|
listTailnetAddresses,
|
|
pickPrimaryTailnetIPv4,
|
|
pickPrimaryTailnetIPv6,
|
|
} from "./tailnet.js";
|
|
|
|
describe("tailnet helpers", () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("detects tailscale ipv4 ranges", () => {
|
|
expect(isTailnetIPv4("100.64.0.1")).toBe(true);
|
|
expect(isTailnetIPv4("100.127.255.254")).toBe(true);
|
|
expect(isTailnetIPv4("100.63.255.255")).toBe(false);
|
|
expect(isTailnetIPv4("192.168.1.10")).toBe(false);
|
|
});
|
|
|
|
it("lists unique non-internal tailnet addresses only", () => {
|
|
vi.spyOn(os, "networkInterfaces").mockReturnValue({
|
|
lo0: [{ address: "127.0.0.1", family: "IPv4", internal: true, netmask: "" }],
|
|
en0: [
|
|
{ address: " 100.88.1.5 ", family: "IPv4", internal: false, netmask: "" },
|
|
{ address: "100.88.1.5", family: "IPv4", internal: false, netmask: "" },
|
|
{ address: "fd7a:115c:a1e0::1", family: "IPv6", internal: false, netmask: "" },
|
|
{ address: " ", family: "IPv6", internal: false, netmask: "" },
|
|
{ address: "fe80::1", family: "IPv6", internal: false, netmask: "" },
|
|
],
|
|
// oxlint-disable-next-line typescript/no-explicit-any
|
|
} as any);
|
|
|
|
expect(listTailnetAddresses()).toEqual({
|
|
ipv4: ["100.88.1.5"],
|
|
ipv6: ["fd7a:115c:a1e0::1"],
|
|
});
|
|
});
|
|
|
|
it("picks the first available tailnet addresses", () => {
|
|
vi.spyOn(os, "networkInterfaces").mockReturnValue({
|
|
utun1: [
|
|
{ address: "100.99.1.1", family: "IPv4", internal: false, netmask: "" },
|
|
{ address: "100.99.1.2", family: "IPv4", internal: false, netmask: "" },
|
|
{ address: "fd7a:115c:a1e0::9", family: "IPv6", internal: false, netmask: "" },
|
|
],
|
|
// oxlint-disable-next-line typescript/no-explicit-any
|
|
} as any);
|
|
|
|
expect(pickPrimaryTailnetIPv4()).toBe("100.99.1.1");
|
|
expect(pickPrimaryTailnetIPv6()).toBe("fd7a:115c:a1e0::9");
|
|
});
|
|
});
|