cc-libs/tools/trap-sandbox/test/auth.test.ts

23 lines
784 B
TypeScript

import assert from "node:assert/strict";
import { test } from "node:test";
import { resolveAccount } from "../src/auth.js";
test("auth disabled when password unset/empty -> always local", () => {
assert.equal(resolveAccount(undefined, undefined), "local");
assert.equal(resolveAccount("anything", undefined), "local");
assert.equal(resolveAccount(undefined, ""), "local");
assert.equal(resolveAccount("anything", ""), "local");
});
test("password set: exact match -> local", () => {
assert.equal(resolveAccount("s3cr3t", "s3cr3t"), "local");
});
test("password set: mismatch -> null", () => {
assert.equal(resolveAccount("wrong", "s3cr3t"), null);
});
test("password set: missing secret -> null", () => {
assert.equal(resolveAccount(undefined, "s3cr3t"), null);
});