test: tighten secure token and system mark coverage

This commit is contained in:
Peter Steinberger 2026-03-13 19:17:24 +00:00
parent 9270c03665
commit 4f78d8542d
2 changed files with 14 additions and 0 deletions

View File

@ -40,4 +40,13 @@ describe("secure-random", () => {
expect(cryptoMocks.randomBytes).toHaveBeenCalledWith(18);
expect(token18).toBe(Buffer.alloc(18, 0xab).toString("base64url"));
});
it("supports zero-byte tokens without rewriting the requested size", () => {
cryptoMocks.randomBytes.mockClear();
const token = generateSecureToken(0);
expect(cryptoMocks.randomBytes).toHaveBeenCalledWith(0);
expect(token).toBe("");
});
});

View File

@ -13,6 +13,7 @@ describe("system-message", () => {
it.each([
{ input: `${SYSTEM_MARK} already prefixed`, expected: true },
{ input: ` ${SYSTEM_MARK} hello`, expected: true },
{ input: SYSTEM_MARK, expected: true },
{ input: "", expected: false },
{ input: "hello", expected: false },
])("detects marks for %j", ({ input, expected }) => {
@ -24,4 +25,8 @@ describe("system-message", () => {
`${SYSTEM_MARK} already prefixed`,
);
});
it("preserves mark-only messages after trimming", () => {
expect(prefixSystemMessage(` ${SYSTEM_MARK} `)).toBe(SYSTEM_MARK);
});
});