69 lines
3.1 KiB
JavaScript
69 lines
3.1 KiB
JavaScript
"use strict";
|
|
|
|
// adpanel:reserved-server-name — focused tests for the reserved server name
|
|
// "all". userHasAccessToServer (index.js) treats a user_access row equal to
|
|
// "all" as a grant-everything wildcard (both sides lowercased), and
|
|
// sanitizeServerToken accepts "all" (any case) as a server name — so a server
|
|
// literally named "all" would turn any per-server grant of it into a
|
|
// panel-wide grant. serverNameGuardOutcome (services/server-create.js) is the
|
|
// ONE creation choke point shared by the panel route, the node proxy and the
|
|
// dashboard-assistant tool, and must refuse the name.
|
|
//
|
|
// Contract note: every entry point hands the guard the ALREADY
|
|
// sanitizeServerToken'd name, and that sanitizer trims but does NOT
|
|
// lowercase — so "ALL"/"All" are the sanitized forms that can actually reach
|
|
// the guard (" all " cannot: it trims to "all" before the guard sees it).
|
|
// The guard still lowercases defensively, which is what these cases pin.
|
|
|
|
const test = require("node:test");
|
|
const assert = require("node:assert");
|
|
const {
|
|
serverNameGuardOutcome,
|
|
renderServerCreateOutcome,
|
|
} = require("../services/server-create");
|
|
|
|
test("serverNameGuardOutcome: normal names still pass", () => {
|
|
assert.strictEqual(serverNameGuardOutcome("survival"), null);
|
|
// A name CONTAINING "all" is not reserved: userHasAccessToServer matches
|
|
// the wildcard with an exact array-element includes, never a substring
|
|
// match, so a server named "ballistic" cannot widen any grant.
|
|
assert.strictEqual(serverNameGuardOutcome("ballistic"), null);
|
|
});
|
|
|
|
test("serverNameGuardOutcome: the user_access wildcard token 'all' is refused in any case", () => {
|
|
assert.deepStrictEqual(serverNameGuardOutcome("all"), { ok: false, code: "invalid_name_reserved" });
|
|
assert.deepStrictEqual(serverNameGuardOutcome("ALL"), { ok: false, code: "invalid_name_reserved" });
|
|
assert.deepStrictEqual(serverNameGuardOutcome("All"), { ok: false, code: "invalid_name_reserved" });
|
|
});
|
|
|
|
test("renderServerCreateOutcome: invalid_name_reserved keeps each variant's name-guard body shape", () => {
|
|
// Panel: "invalid name" token + detail (mirrors invalid_name_storage_mismatch).
|
|
assert.deepStrictEqual(
|
|
renderServerCreateOutcome({ ok: false, code: "invalid_name_reserved" }, "panel"),
|
|
{
|
|
status: 400,
|
|
body: { error: "invalid name", detail: "\"all\" is a reserved server name - choose a different name" },
|
|
}
|
|
);
|
|
// Proxy: invalid_name token + detail (mirrors invalid_name_storage_mismatch).
|
|
assert.deepStrictEqual(
|
|
renderServerCreateOutcome({ ok: false, code: "invalid_name_reserved" }, "proxy"),
|
|
{
|
|
status: 400,
|
|
body: { error: "invalid_name", detail: "\"all\" is a reserved server name - choose a different name" },
|
|
}
|
|
);
|
|
// Tool: prose envelope with the name-guard code "invalid_name" (mirrors
|
|
// invalid_name_storage_mismatch).
|
|
assert.deepStrictEqual(
|
|
renderServerCreateOutcome({ ok: false, code: "invalid_name_reserved" }, "tool"),
|
|
{
|
|
envelope: {
|
|
ok: false,
|
|
error: "\"all\" is a reserved server name - choose a different name.",
|
|
code: "invalid_name",
|
|
},
|
|
}
|
|
);
|
|
});
|