Support Forge Server Login account management and registration prompts
This commit is contained in:
1 parent
683cdc4016
commit
d0a696f013
5 files changed
+59
-7
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
||||
vi.mock("../src/server/env", () => ({ env: { mcDataDir: "" } }));
|
||||
vi.mock("../src/server/rcon", () => ({ rcon: () => ({ exec: vi.fn() }), stripColors: (s: string) => s, RconError: class extends Error {} }));
|
||||
import { env } from "../src/server/env";
|
||||
import { authProvider, registrationCommand, parseServerLoginAccounts, easyauthSetPassword } from "../src/server/mc";
|
||||
let dir: string;
|
||||
beforeEach(() => { dir = fs.mkdtempSync(path.join(os.tmpdir(), "craftdeck-auth-")); env.mcDataDir = dir; });
|
||||
afterEach(() => fs.rmSync(dir, { recursive: true, force: true }));
|
||||
it("uses the Forge registration flow and never sends an unsupported password reset command", async () => {
|
||||
expect(authProvider()).toBe("easyauth");
|
||||
fs.mkdirSync(path.join(dir, "config")); fs.writeFileSync(path.join(dir, "config/serverlogin-common.toml"), "");
|
||||
expect(registrationCommand()).toBe("/login <password> <password>");
|
||||
await expect(easyauthSetPassword("aryan", "test-only")).rejects.toThrow("Force re-register");
|
||||
});
|
||||
it("returns names only from the documented account database and rejects unknown formats", () => {
|
||||
expect(parseServerLoginAccounts(JSON.stringify({ formatVersion: 1, users: { aryan: { lastKnownName: "aryan", salt: "private", hash: "private" } } }))).toEqual(["aryan"]);
|
||||
expect(() => parseServerLoginAccounts('{"formatVersion":2,"users":{}}')).toThrow();
|
||||
expect(() => parseServerLoginAccounts('{"formatVersion":1,"users":[]}')).toThrow();
|
||||
});
|
||||
Reference in new issue
Block a user