23 lines
1.5 KiB
TypeScript
23 lines
1.5 KiB
TypeScript
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();
|
|
});
|