Port presets: Network services and Tailscale
Two more ready-made presets, added once to installs that already have presets. Later batches now each have their own flag (LATER_BATCHES), so the next one is a list entry rather than new seeding code. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
94288afcbd
commit
b8ce337dfb
4 files changed
+58
-21
No files matched your search
@@ -150,18 +150,20 @@ describe("the routes", () => {
|
||||
|
||||
test("the ready-made presets are there the first time, for everyone", async () => {
|
||||
const list = (await json<{ presets: Preset[] }>(await call("viewer", "GET", "/port-presets"))).presets;
|
||||
assert.deepEqual(list.map((p) => p.name), ["Databases", "Debian / Ubuntu", "File sharing", "Homelab tools", "Remote access", "Web", "Windows client", "Windows server"]);
|
||||
assert.deepEqual(list.map((p) => p.name), ["Databases", "Debian / Ubuntu", "File sharing", "Homelab tools", "Network services", "Remote access", "Tailscale", "Web", "Windows client", "Windows server"]);
|
||||
const remote = list.find((p) => p.name === "Remote access")!;
|
||||
assert.deepEqual(remote.ports.map((p) => [p.port, p.label]), [[22, "SSH"], [3389, "RDP"], [5900, "VNC"], [5985, "WinRM (HTTP)"], [5986, "WinRM (HTTPS)"]]);
|
||||
assert.ok(list.find((p) => p.name === "Databases")!.ports.some((p) => p.port === 5432 && p.label === "PostgreSQL"));
|
||||
});
|
||||
|
||||
test("the operating-system presets name what a Windows client, a Windows server and a Debian or Ubuntu machine have open, and no port is called two things", async () => {
|
||||
test("the operating-system, network and Tailscale presets name what a Windows client, a Windows server and a Debian or Ubuntu machine have open, what the network runs, and Tailscale — and no port is called two things", async () => {
|
||||
const list = (await json<{ presets: Preset[] }>(await call("viewer", "GET", "/port-presets"))).presets;
|
||||
const has = (name: string, protocol: string, port: number, label: string) => list.find((p) => p.name === name)!.ports.some((p) => p.protocol === protocol && p.port === port && p.label === label);
|
||||
assert.ok(has("Windows client", "tcp", 445, "SMB") && has("Windows client", "tcp", 49664, "RPC (dynamic)") && has("Windows client", "udp", 5353, "mDNS"));
|
||||
assert.ok(has("Windows server", "tcp", 389, "LDAP") && has("Windows server", "tcp", 9389, "AD Web Services") && has("Windows server", "udp", 67, "DHCP server"));
|
||||
assert.ok(has("Debian / Ubuntu", "tcp", 22, "SSH") && has("Debian / Ubuntu", "udp", 41641, "Tailscale"));
|
||||
assert.ok(has("Network services", "udp", 161, "SNMP") && has("Network services", "udp", 51820, "WireGuard") && has("Network services", "tcp", 8291, "MikroTik Winbox"));
|
||||
assert.ok(has("Tailscale", "udp", 41641, "Tailscale") && has("Tailscale", "udp", 3478, "STUN") && has("Tailscale", "tcp", 8443, "HTTPS (alternate)"));
|
||||
for (const p of list) assert.ok(p.ports.length <= pp.MAX_PRESET_PORTS, p.name);
|
||||
// Whichever preset names a port first (by name) is the one heard, so every preset that names the same port must say the same thing.
|
||||
const said = new Map<string, string>();
|
||||
@@ -339,29 +341,39 @@ describe("the routes", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("the operating-system presets on a list that is already in use", () => {
|
||||
describe("the presets that came later, on a list that is already in use", () => {
|
||||
const names = async () => (await pp.listPresets()).map((p) => p.name).sort();
|
||||
const forget = async (...which: string[]) => {
|
||||
const { settings } = await import("../src/db/schema.js");
|
||||
for (const w of which) await db.delete(settings).where(eq(settings.key, `_internal:${w}`));
|
||||
};
|
||||
|
||||
test("they are added once, beside what is there: a preset of the same name is left as it is, a deleted one is not put back, and an emptied list stays empty", async () => {
|
||||
const { settings } = await import("../src/db/schema.js");
|
||||
const forgetOsFlag = () => db.delete(settings).where(eq(settings.key, "_internal:portPresetsOsSeeded"));
|
||||
// The list as an install from before them has it: five presets (one changed) and a flag for those five only.
|
||||
// The list as an install from before them has it: two presets (one of them changed, and its name in another case) and a flag for the first five only.
|
||||
await db.delete(portPresets);
|
||||
const now = new Date().toISOString();
|
||||
await db.insert(portPresets).values([
|
||||
{ name: "Remote access", ports: JSON.stringify([{ port: 22, protocol: "tcp", label: "SSH" }]), createdAt: now, updatedAt: now },
|
||||
{ name: "windows CLIENT", ports: JSON.stringify([{ port: 1, protocol: "tcp", label: "Mine" }]), createdAt: now, updatedAt: now },
|
||||
]);
|
||||
await forgetOsFlag();
|
||||
assert.deepEqual(await names(), ["Debian / Ubuntu", "Remote access", "Windows server", "windows CLIENT"], "the missing ones came, the one with the same name (any case) did not");
|
||||
await forget("portPresetsOsSeeded", "portPresetsNetworkSeeded");
|
||||
assert.deepEqual(await names(), ["Debian / Ubuntu", "Network services", "Remote access", "Tailscale", "Windows server", "windows CLIENT"], "the missing ones came, the one with the same name (any case) did not");
|
||||
assert.deepEqual((await pp.listPresets()).find((p) => p.name === "windows CLIENT")!.ports.map((p) => p.label), ["Mine"]);
|
||||
|
||||
for (const p of (await pp.listPresets()).filter((x) => x.name === "Debian / Ubuntu")) await db.delete(portPresets).where(eq(portPresets.id, p.id));
|
||||
assert.deepEqual(await names(), ["Remote access", "Windows server", "windows CLIENT"], "deleted, and not put back");
|
||||
assert.deepEqual(await names(), ["Network services", "Remote access", "Tailscale", "Windows server", "windows CLIENT"], "deleted, and not put back");
|
||||
|
||||
await db.delete(portPresets);
|
||||
await forgetOsFlag();
|
||||
await forget("portPresetsOsSeeded", "portPresetsNetworkSeeded");
|
||||
assert.deepEqual(await names(), [], "somebody emptied the list, so it stays empty");
|
||||
assert.deepEqual(await names(), [], "and the next look is the same");
|
||||
});
|
||||
|
||||
test("an install that already has the operating-system presets gets only the network ones, and not the ones it deleted", async () => {
|
||||
await db.delete(portPresets);
|
||||
const now = new Date().toISOString();
|
||||
await db.insert(portPresets).values({ name: "Remote access", ports: JSON.stringify([{ port: 22, protocol: "tcp", label: "SSH" }]), createdAt: now, updatedAt: now });
|
||||
await forget("portPresetsNetworkSeeded");
|
||||
assert.deepEqual(await names(), ["Network services", "Remote access", "Tailscale"]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user