test: prune redundant and implementation-coupled coverage

This commit is contained in:
morluto committed 2026-11-17 18:48:24 -05:00
1 parent 14b15ba8a5
commit 48e27e19b7
191 files changed
+2757 -5418

No files matched your search

+12 -55
View File
@@ -3,10 +3,6 @@ import { expect, it } from "vitest";
import { z } from "zod";
import {
BASE64_QUARTET_LENGTH_PATTERN,
INVALID_BASE64_CHARACTER_PATTERN,
INVALID_BASE64_PADDING_PATTERN,
INVALID_CANONICAL_BASE64_PAD_BITS_PATTERN,
IDENTIFIER_PATTERN,
STABLE_IDENTIFIER_PATTERN,
canonicalBase64Schema,
@@ -89,61 +85,21 @@ it("preserves canonical and permissive padded base64 validation", () => {
}
});
it("advertises every portable base64 constraint and keeps large inputs stack-safe", () => {
const jsonSchema = z.toJSONSchema(canonicalBase64Schema, {
target: "draft-2020-12",
});
expect(jsonSchema).toMatchObject({
allOf: expect.arrayContaining([
{ pattern: BASE64_QUARTET_LENGTH_PATTERN.source },
{ not: { pattern: INVALID_BASE64_CHARACTER_PATTERN.source } },
{ not: { pattern: INVALID_BASE64_PADDING_PATTERN.source } },
{ not: { pattern: INVALID_CANONICAL_BASE64_PAD_BITS_PATTERN.source } },
]),
});
const body = Buffer.alloc(24 * 1024 * 1024 - 3, 0x81);
const encoded = body.toString("base64");
for (const flag of ["", "u", "v"]) {
expect(
new RegExp(BASE64_QUARTET_LENGTH_PATTERN.source, flag).test(encoded),
flag,
).toBe(true);
expect(
new RegExp(INVALID_BASE64_CHARACTER_PATTERN.source, flag).test(encoded),
flag,
).toBe(false);
expect(
new RegExp(INVALID_BASE64_PADDING_PATTERN.source, flag).test(encoded),
flag,
).toBe(false);
expect(
new RegExp(INVALID_CANONICAL_BASE64_PAD_BITS_PATTERN.source, flag).test(
encoded,
),
flag,
).toBe(false);
expect(
new RegExp(INVALID_BASE64_CHARACTER_PATTERN.source, flag).test(
`${encoded.slice(0, -1)}!`,
),
flag,
).toBe(true);
expect(
new RegExp(INVALID_CANONICAL_BASE64_PAD_BITS_PATTERN.source, flag).test(
`${encoded.slice(0, -3)}R==`,
),
flag,
).toBe(true);
}
expect(isCanonicalBase64(encoded)).toBe(true);
});
it("validates complete projected canonical schemas at the encoded-input budget", () => {
it("validates the projected base64 schema in Unicode and Unicode-set modes at the encoded-input budget", () => {
const projected = z.toJSONSchema(canonicalBase64Schema, {
target: "draft-2020-12",
});
const validate = new Ajv2020({ strict: true }).compile(projected);
const unicodeSetsRegExp = Object.assign(
(pattern: string) => new RegExp(pattern, "v"),
{ code: '(pattern => new RegExp(pattern, "v"))' },
);
const validateUnicodeSets = new Ajv2020({
strict: true,
// The default pass validates the schema. Here only the projected patterns use v.
validateSchema: false,
code: { regExp: unicodeSetsRegExp },
}).compile(projected);
const encoded = Buffer.alloc(24 * 1024 * 1024 - 3, 0x81).toString("base64");
for (const { value, expected } of [
{ value: encoded, expected: true },
@@ -153,6 +109,7 @@ it("validates complete projected canonical schemas at the encoded-input budget",
]) {
expect(canonicalBase64Schema.safeParse(value).success).toBe(expected);
expect(validate(value)).toBe(expected);
expect(validateUnicodeSets(value)).toBe(expected);
}
});