File size: 1,807 Bytes
87dab07 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | import { describe, expect, it } from "vitest";
import { resolveAllowFromAccountId, safeAccountKey, safeChannelKey } from "./pairing-store-keys.js";
import type { PairingChannel } from "./pairing-store.types.js";
function expectInvalidPairingKey(params: {
run: () => unknown;
message: string;
leaked?: string;
}): void {
try {
params.run();
} catch (err) {
expect(err).toBeInstanceOf(Error);
const message = (err as Error).message;
expect(message).toBe(params.message);
if (params.leaked) {
expect(message).not.toContain(params.leaked);
}
return;
}
throw new Error("expected invalid pairing key error");
}
describe("pairing store keys", () => {
it("formats invalid key diagnostics without stringifying unsafe values", () => {
const circular: Record<string, unknown> = { label: "private-channel-value" };
circular.self = circular;
expectInvalidPairingKey({
run: () => safeChannelKey(circular as unknown as PairingChannel),
message: "invalid pairing channel: expected non-empty string; got object",
leaked: "private-channel-value",
});
expectInvalidPairingKey({
run: () => resolveAllowFromAccountId(10n as unknown as string),
message: "invalid pairing account id: expected non-empty string; got bigint",
leaked: "10",
});
});
it("rejects sanitized-empty keys without exposing raw input", () => {
expectInvalidPairingKey({
run: () => safeChannelKey(".." as PairingChannel),
message: "invalid pairing channel: sanitized key is empty; got string length 2",
leaked: "..",
});
expectInvalidPairingKey({
run: () => safeAccountKey("/"),
message: "invalid pairing account id: sanitized key is empty; got string length 1",
leaked: "/",
});
});
});
|