mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
feat(dashboard): unify secure staff administration
Provide a single /dashboard entry point for owner and staff tools, with Discord OAuth sign-in for approved owner accounts and active staff. Add owner-managed dashboard access grants, staff server health and update visibility, filtering, moderation improvements, item controls, and per-animal clothing restrictions. Replace staff-triggered password and 2FA resets with email-verified account recovery. Persist validated recovery addresses, use short-lived hashed recovery tokens, expose recovery flows in registration and account pages, and keep mail delivery disabled until its webhook configuration is present. Cover dashboard aliases, recovery restrictions, Discord access, monitoring, item locks, wear rules, and staff behavior with regression tests.
This commit is contained in:
1 parent
4997315239
commit
7dee29010a
27 files changed
+2303
-346
No files matched your search
+91
-1
@@ -88,6 +88,28 @@ const pack = async id => Object.values(decode(zlib.inflateRawSync(Buffer.from(aw
|
||||
const strings = async () => decode(zlib.inflateRawSync(Buffer.from(await (await fetch(`${BASE}/${cdn.hashedPath("defPacks/10230")}`)).arrayBuffer())));
|
||||
const byId = (rows, id) => rows.find(row => String(row.id) === String(id));
|
||||
|
||||
// Ask for the same full clothing list the item editor does, then find one
|
||||
// inventory entry in its five-field rows. Keeping this on the real protocol
|
||||
// lets the rule tests cover both server state and what an open game receives.
|
||||
const ownInventory = async (client, roomId, username, perUserAvId = 1) => {
|
||||
client.xt("il", roomId, username, perUserAvId, 1);
|
||||
for (;;) {
|
||||
const list = await client.untilXt("il");
|
||||
if (list[2] === "0" && list[5] === username) {
|
||||
return list;
|
||||
}
|
||||
}
|
||||
};
|
||||
const inventoryPiece = (list, defId) => {
|
||||
for (let index = 0; index < Number(list[8]); index++) {
|
||||
const at = 9 + index * 5;
|
||||
if (Number(list[at]) === Number(defId)) {
|
||||
return {inv: Number(list[at + 1]), equipped: list[at + 3]};
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
// "xdi" [.., .., kind, rows as JSON], the next one of `kind`.
|
||||
const untilDefs = async (client, kind) => {
|
||||
for (;;) {
|
||||
@@ -412,6 +434,56 @@ const first = async () => {
|
||||
assert.strictEqual(wornAs.mine.find(entry => entry.kind === "clothing" && entry.id === hatEntry.id).artMode, "texture");
|
||||
assert.match((await maker("look", "clothing", hatEntry.id, "melted")).said, /sticker or texture/);
|
||||
|
||||
// --- animal wear rules: a live custom item keeps its xdi-only name and
|
||||
// picture, existing use is removed, and neither packet nor saved-outfit
|
||||
// routes may put it back on the animal that staff blocked.
|
||||
const partyHat = wornAs.mine.find(sameItem);
|
||||
assert.ok(partyHat && partyHat.art, "the custom clothing to restrict is missing its picture");
|
||||
const partyPiece = inventoryPiece(await ownInventory(pat.client, pat.roomId, "Pat"), partyHat.id);
|
||||
assert.ok(partyPiece, "Pat does not own Party Hat");
|
||||
pat.client.xt("iu", pat.roomId, 1, 0, partyPiece.inv);
|
||||
assert.strictEqual((await pat.client.untilXt("iu"))[2], "1");
|
||||
let changedWear = await pat.client.untilXt("il");
|
||||
assert.deepStrictEqual(changedWear.slice(2), ["3", "1", "1", "Pat", "0", "1", "0", String(partyPiece.inv), String(partyHat.id)]);
|
||||
say(pat.client, pat.roomId, "!outfit save partyhat");
|
||||
assert.strictEqual(await nextBox(pat.client), "Outfit partyhat saved (1 items).");
|
||||
// A no-op item-editor request records what was worn for !outfit undo,
|
||||
// without taking Party Hat off before the dashboard removes it.
|
||||
pat.client.xt("iu", pat.roomId, 0, 0);
|
||||
await pat.client.untilXt("iu");
|
||||
await pat.client.untilXt("il");
|
||||
assert.strictEqual(byId(await pack(1000), partyHat.id).avatarUseFlags, "9007199254740991");
|
||||
assert.strictEqual((await admin("/admin/api/items/wear-rules", {id: partyHat.id, blockedTypes: ["1"]})).status, 400);
|
||||
assert.strictEqual((await admin("/admin/api/items/wear-rules", {id: bodyPart.id, blockedTypes: [1]})).status, 400);
|
||||
const partyRule = await admin("/admin/api/items/wear-rules", {id: partyHat.id, blockedTypes: [1]});
|
||||
assert.match(partyRule.data.ok, /cannot be worn/);
|
||||
// The owner receives a fresh full list immediately, with the old equipped
|
||||
// bit actually gone rather than merely hidden in the renderer.
|
||||
const afterRule = await pat.client.untilXt("il");
|
||||
assert.strictEqual(afterRule[2], "0");
|
||||
assert.strictEqual(inventoryPiece(afterRule, partyHat.id).equipped, "0");
|
||||
const partyUpdate = byId(await untilDefs(pat.client, "clothing"), partyHat.id);
|
||||
assert.deepStrictEqual([partyUpdate.avatarUseFlags, partyUpdate.name, partyUpdate.art, partyUpdate.artMode],
|
||||
["9007199254740990", "Party Hat", partyHat.art, "texture"]);
|
||||
assert.strictEqual(byId(await pack(1000), partyHat.id).avatarUseFlags, "9007199254740990"); // cached pack was invalidated
|
||||
say(pat.client, pat.roomId, "!outfit undo");
|
||||
changedWear = await pat.client.untilXt("il");
|
||||
assert.strictEqual(changedWear[7], "0");
|
||||
assert.ok(!changedWear.includes(String(partyHat.id)));
|
||||
assert.match(await nextBox(pat.client), /Back to what you wore before/);
|
||||
say(pat.client, pat.roomId, "!outfit wear partyhat");
|
||||
changedWear = await pat.client.untilXt("il");
|
||||
assert.strictEqual(changedWear[7], "0");
|
||||
assert.ok(!changedWear.includes(String(partyHat.id)));
|
||||
assert.match(await nextBox(pat.client), /Wearing partyhat/);
|
||||
// A crafted/stale editor packet still succeeds as a request but cannot add
|
||||
// a blocked inventory entry to the response or persisted outfit.
|
||||
pat.client.xt("iu", pat.roomId, 1, 0, partyPiece.inv);
|
||||
assert.strictEqual((await pat.client.untilXt("iu"))[2], "1");
|
||||
changedWear = await pat.client.untilXt("il");
|
||||
assert.strictEqual(changedWear[7], "0");
|
||||
assert.ok(!changedWear.includes(String(partyHat.id)));
|
||||
|
||||
// deleting: their own only, and gone from everyone
|
||||
assert.match((await maker("delete", "clothing", 50001)).said, /not one of your items/);
|
||||
for (const entry of full.mine) {
|
||||
@@ -420,6 +492,8 @@ const first = async () => {
|
||||
assert.deepStrictEqual((await maker("info")).mine, []);
|
||||
assert.strictEqual((await fetch(`${BASE}/itemart/clothing/${hatEntry.id}.png`)).status, 404);
|
||||
assert.strictEqual((await dev("/mod/api/items")).data.items.length, 3);
|
||||
assert.ok(!(await admin(`/admin/api/items/wear-rules?q=${hatEntry.id}`)).data.rules.some(rule => rule.id === hatEntry.id),
|
||||
"deleting custom clothing should remove its wear rule");
|
||||
|
||||
// --- the admin's switches: what players make waits for a moderator first,
|
||||
// out of the game till then; or the Item Maker is off
|
||||
@@ -465,6 +539,20 @@ const first = async () => {
|
||||
assert.strictEqual((await admin("/admin/api/item-switches", {enabled: true})).status, 200);
|
||||
assert.match((await maker("delete", "clothing", waitingHat.id)).said, /^Deleted /);
|
||||
|
||||
// A developer can create items but is not silently granted the moderation
|
||||
// control. Once made a moderator, the existing panel session is checked
|
||||
// against the new role and can create a rule that survives the restart.
|
||||
assert.strictEqual((await dev("/mod/api/items/wear-rules")).status, 403);
|
||||
assert.strictEqual((await dev("/mod/api/items/wear-rules", {id: 50000, blockedTypes: [1]})).status, 403);
|
||||
assert.match((await admin("/admin/api/account", {username: "Dev", action: "role", role: "moderator"})).data.ok, /moderator/);
|
||||
const moderatorMe = (await dev("/mod/api/me")).data;
|
||||
assert.ok(moderatorMe.permissions.includes("items.restrict") && !moderatorMe.permissions.includes("items.create"));
|
||||
const crownRule = await dev("/mod/api/items/wear-rules", {id: 50000, blockedTypes: [1]});
|
||||
assert.match(crownRule.data.ok, /cannot be worn/);
|
||||
const moderatorRules = (await dev("/mod/api/items/wear-rules?q=Gold%20Crown")).data;
|
||||
assert.deepStrictEqual(moderatorRules.results.find(entry => entry.id === 50000).blockedTypes, [1]);
|
||||
assert.strictEqual(byId(await pack(1000), 50000).avatarUseFlags, "9007199254740990");
|
||||
|
||||
// written down under the maker's name
|
||||
const log = (await admin("/admin/api/moderators")).data.log.map(entry => `${entry.by} ${entry.action} ${entry.detail}`);
|
||||
for (const line of ["Dev item made clothing 50000 Test Crown", "Dev item made den 50000 Test Chair", "Dev item changed clothing 50000 Gold Crown",
|
||||
@@ -472,7 +560,7 @@ const first = async () => {
|
||||
"Dev item taken den 50000 x1", "Dev item deleted clothing 50002"]) {
|
||||
assert.ok(log.includes(line), `missing from the log: ${line}\n${log.join("\n")}`);
|
||||
}
|
||||
made = {base};
|
||||
made = {base, restrictedId: 50000};
|
||||
for (const {client} of [pat, devGame, hal]) {
|
||||
client.socket.destroy();
|
||||
}
|
||||
@@ -488,6 +576,8 @@ const second = async () => {
|
||||
assert.deepStrictEqual(atLogin.clothing.map(entry => `${entry.id} ${entry.name}`), ["50000 Gold Crown", "50001 Quick Hat"]);
|
||||
assert.deepStrictEqual(atLogin.den.map(entry => entry.name), ["Test Chair"]);
|
||||
assert.strictEqual(byId(await pack(1000), 50001).layerDefId, made.base.layerDefId);
|
||||
assert.strictEqual(byId(atLogin.clothing, made.restrictedId).avatarUseFlags, "9007199254740990");
|
||||
assert.strictEqual(byId(await pack(1000), made.restrictedId).avatarUseFlags, "9007199254740990");
|
||||
assert.strictEqual((await strings())[9100001], "Quick Hat");
|
||||
const shop = await shopList(lou.client, lou.roomId, ODD_CLOTHING_SHOP);
|
||||
assert.ok(shop.includes("50001") && !shop.includes("50000"));
|
||||
|
||||
+19
-8
@@ -464,8 +464,19 @@ const run = async () => {
|
||||
});
|
||||
return {status: response.status, data: await response.json(), cookie: (response.headers.get("set-cookie") || "").split(";")[0]};
|
||||
};
|
||||
assert.match(await (await fetch(`${BASE}/admin`)).text(), /Server admin/);
|
||||
assert.deepStrictEqual((await panel("state")).data, {needsSetup: true, needsSetupCode: false, signedIn: false});
|
||||
const oldAdmin = await fetch(`${BASE}/admin`, {redirect: "manual"});
|
||||
assert.strictEqual(oldAdmin.status, 302);
|
||||
assert.strictEqual(oldAdmin.headers.get("location"), "/dashboard/admin");
|
||||
const oldMod = await fetch(`${BASE}/mod`, {redirect: "manual"});
|
||||
assert.strictEqual(oldMod.status, 302);
|
||||
assert.strictEqual(oldMod.headers.get("location"), "/dashboard/staff");
|
||||
assert.match(await (await fetch(`${BASE}/dashboard`)).text(), /Burrow dashboard/);
|
||||
const dashboardSlash = await fetch(`${BASE}/dashboard/`, {redirect: "manual"});
|
||||
assert.strictEqual(dashboardSlash.status, 302);
|
||||
assert.strictEqual(dashboardSlash.headers.get("location"), "/dashboard");
|
||||
assert.match(await (await fetch(`${BASE}/dashboard/admin`)).text(), /Server admin/);
|
||||
assert.match(await (await fetch(`${BASE}/dashboard/staff`)).text(), /Moderators/);
|
||||
assert.deepStrictEqual((await panel("state")).data, {needsSetup: true, needsSetupCode: false, signedIn: false, discordLogin: false});
|
||||
assert.strictEqual((await panel("overview")).status, 401);
|
||||
assert.strictEqual((await panel("login", {password: "anything"})).status, 401);
|
||||
assert.strictEqual((await panel("setup", {password: "short"})).status, 400);
|
||||
@@ -544,14 +555,14 @@ const run = async () => {
|
||||
assert.strictEqual((await panel("account", {username: "Robert", action: "rename", newName: "ROBERT"}, admin)).status, 200);
|
||||
assert.strictEqual((await panel("account", {username: "robert", action: "rename", newName: "Bob"}, admin)).status, 200);
|
||||
|
||||
// A new password for a player: the old one and old tokens stop working.
|
||||
// Staff cannot take over an account by setting its password; recovery is
|
||||
// email-only from the account recovery page.
|
||||
assert.strictEqual((await panel("account", {username: "foo", action: "password", password: "short"}, admin)).status, 400);
|
||||
assert.strictEqual((await panel("account", {username: "foo", action: "password", password: "New-password-4"}, admin)).status, 200);
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {username: "foo", password: "KettlePass04"})).status, 401);
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {refresh_token: foo.refresh_token})).status, 401);
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {username: "foo", password: "New-password-4"})).status, 200);
|
||||
assert.strictEqual((await panel("account", {username: "foo", action: "password", password: "New-password-4"}, admin)).status, 400);
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {username: "foo", password: "KettlePass04"})).status, 200);
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {refresh_token: foo.refresh_token})).status, 200);
|
||||
assert.strictEqual((await panel("account", {username: "foo", action: "delete"}, admin)).status, 200);
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {username: "foo", password: "New-password-4"})).status, 401);
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {username: "foo", password: "KettlePass04"})).status, 401);
|
||||
|
||||
// changing the admin password signs every other session out.
|
||||
assert.strictEqual((await panel("password", {current: "nope", password: "admin-password-2"}, admin)).status, 403);
|
||||
|
||||
+29
-1
@@ -82,7 +82,7 @@ const arrive = async (username, password, room, totp, onLogin = async () => {})
|
||||
await client.untilXt("rp");
|
||||
}
|
||||
client.xt("au", rj[4], 1, 400, 400, 14, 1);
|
||||
return {client, login, roomId: rj[4], room: rj[3]};
|
||||
return {client, login, roomId: rj[4], room: rj[3], token: auth.auth_token};
|
||||
};
|
||||
|
||||
// the next moderator popup ("fd") of this kind, skipping earlier ones (a
|
||||
@@ -240,9 +240,36 @@ const run = async () => {
|
||||
assert.strictEqual((await halPage("/mod/api/login", {username: "Hal", password: people.Hal, code: codeAt(secrets.Hal, usedStep.Hal)})).status, 200);
|
||||
const halMe = (await halPage("/mod/api/me")).data;
|
||||
assert.strictEqual(halMe.role, "helper");
|
||||
assert.ok(halMe.permissions.includes("server.view"));
|
||||
assert.ok(!halMe.permissions.includes("player.ban"));
|
||||
const health = await halPage("/mod/api/server");
|
||||
assert.strictEqual(health.status, 200);
|
||||
assert.ok(Number.isInteger(health.data.players));
|
||||
assert.ok(Number.isInteger(health.data.sockets.openConnections));
|
||||
assert.strictEqual(typeof health.data.update.needsPublish, "boolean");
|
||||
assert.ok(Array.isArray(health.data.update.changed));
|
||||
assert.strictEqual((await halPage("/mod/api/act", {username: "Pip", action: "ban", hours: 1, reason: "x"})).data.error, "Your role cannot do that.");
|
||||
assert.match((await halPage("/mod/api/act", {username: "Mira", action: "silence", hours: 1})).data.error, /your rank or above/);
|
||||
// the Players page's list, narrowed to who is online, staff, banned or
|
||||
// silenced (Ann was put out above); an unknown narrowing is everyone
|
||||
const listed = async only => (await modPage(`/mod/api/players?only=${only}`)).data.players.map(player => player.username).sort();
|
||||
assert.deepStrictEqual(await listed("staff"), ["Hal", "Mira"]);
|
||||
const online = await listed("online");
|
||||
assert.ok(["Hal", "Mira", "Pip"].every(name => online.includes(name)), online.join(", "));
|
||||
assert.deepStrictEqual(await listed("banned"), []);
|
||||
assert.deepStrictEqual(await listed("everything"), ["Ann", "Hal", "Mira", "Pip"]);
|
||||
// the Masterpieces page: those waiting, and the last approved (by anyone,
|
||||
// or only by this moderator), to take one back from
|
||||
const paintings = (await modPage("/mod/api/masterpieces?mine=1")).data;
|
||||
assert.deepStrictEqual([paintings.waiting, paintings.approved, paintings.recent], [[], [], []]);
|
||||
// signed in through the game (a client the moderator is playing in hands
|
||||
// over its login token): staff in the game now, from the game's address
|
||||
const viaGame = webSession();
|
||||
assert.strictEqual((await viaGame("/mod/api/game-login", {token: mira.token})).status, 200);
|
||||
assert.strictEqual((await viaGame("/mod/api/me")).data.username, "Mira");
|
||||
// a player's token, or none that is good, opens nothing
|
||||
assert.strictEqual((await webSession()("/mod/api/game-login", {token: pip.token})).status, 401);
|
||||
assert.strictEqual((await webSession()("/mod/api/game-login", {token: "0".repeat(64)})).status, 401);
|
||||
// searching by address (against ban evasion) is for the roles that ban addresses
|
||||
assert.strictEqual((await halPage("/mod/api/players?by=address&q=127.0.0.")).status, 403);
|
||||
assert.ok(Array.isArray((await modPage("/mod/api/players?by=address&q=127.0.0.")).data.players));
|
||||
@@ -305,6 +332,7 @@ const run = async () => {
|
||||
const annAway = (await modPage("/mod/api/player?username=Ann")).data;
|
||||
assert.strictEqual(annAway.warnings, 4);
|
||||
assert.strictEqual(annAway.warningList[0].seen, false);
|
||||
assert.deepStrictEqual(await listed("silenced"), ["Ann"]);
|
||||
const annBack = await arrive("Ann", people.Ann, SAREPIA);
|
||||
assert.deepStrictEqual((await untilPopup(annBack.client, "fw")).slice(2, 4), ["fw", "1"]); // the bullying one
|
||||
assert.strictEqual((await modPage("/mod/api/player?username=Ann")).data.warningList[0].seen, true);
|
||||
|
||||
Reference in new issue
Block a user