Files
OmniRoute/tests/unit/lib/machineToken.test.ts
diegosouzapw 1887483c0f feat(cli): add HMAC-SHA256 machine token for localhost CLI auth
Generates a deterministic HMAC-SHA256(key=rawMachineId, msg=salt) token
in src/lib/machineToken.ts. The management authz policy now accepts this
token via x-omniroute-cli-token when Host is loopback, letting the local
CLI process call management APIs without requiring a user login session.
`omniroute config token` prints the token for manual use.
2026-05-14 23:00:00 -03:00

23 lines
797 B
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { getMachineTokenSync } from "../../../src/lib/machineToken.ts";
test("getMachineTokenSync returns a 32-character hex string", () => {
const token = getMachineTokenSync();
assert.match(token, /^[0-9a-f]{32}$/, "token must be 32 lowercase hex chars");
});
test("getMachineTokenSync is deterministic", () => {
assert.equal(getMachineTokenSync(), getMachineTokenSync());
});
test("getMachineTokenSync produces different values for different salts", () => {
const t1 = getMachineTokenSync("salt-a");
const t2 = getMachineTokenSync("salt-b");
assert.notEqual(t1, t2);
});
test("getMachineTokenSync with empty string salt does not throw", () => {
assert.doesNotThrow(() => getMachineTokenSync(""));
});