mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 13:41:17 -05:00
49b4edfe77
Share padded decoding across CDP response shapes and cache fingerprints, and count binary WebSocket bytes without allocating a decoded buffer. Preserve HAR canonical pad bits and validate before allocation. Replace repeated alphabet quartets in canonical schemas with separate alphabet, padding and fixed-width length assertions. Cover near-32MiB encodings under ordinary, Unicode and Unicode-set modes, plus complete 4MiB CLI and MCP retained-evidence export workflows. Fixes #5253
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { expect, it } from "vitest";
|
|
|
|
import { decodePaddedBase64, paddedBase64ByteLength } from "./paddedBase64.js";
|
|
|
|
it("preserves padded syntax, including empty bodies and nonzero pad bits", () => {
|
|
for (const [encoded, decoded] of [
|
|
["", ""],
|
|
["AA==", "00"],
|
|
["AB==", "00"],
|
|
["AAA=", "0000"],
|
|
["AAB=", "0000"],
|
|
["////", "ffffff"],
|
|
] as const) {
|
|
expect(decodePaddedBase64(encoded)?.toString("hex")).toBe(decoded);
|
|
expect(paddedBase64ByteLength(encoded)).toBe(decoded.length / 2);
|
|
}
|
|
for (const malformed of [
|
|
"A",
|
|
"AA",
|
|
"AAA",
|
|
"=AAA",
|
|
"A===",
|
|
"====",
|
|
"AA==A",
|
|
"AA-_",
|
|
"AA==\n",
|
|
"AA==\r",
|
|
"AA== ",
|
|
"A A=",
|
|
"AA==",
|
|
]) {
|
|
expect(paddedBase64ByteLength(malformed), malformed).toBeUndefined();
|
|
expect(decodePaddedBase64(malformed), malformed).toBeUndefined();
|
|
}
|
|
});
|
|
|
|
it("validates large bodies and malformed suffixes without a regexp stack overflow", () => {
|
|
const body = Buffer.alloc(24 * 1024 * 1024 - 3, 0x81);
|
|
const encoded = body.toString("base64");
|
|
expect(paddedBase64ByteLength(encoded)).toBe(body.length);
|
|
expect(decodePaddedBase64(encoded)?.equals(body)).toBe(true);
|
|
const malformed = `${encoded.slice(0, -1)}!`;
|
|
expect(paddedBase64ByteLength(malformed)).toBeUndefined();
|
|
});
|