Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/worker/src/jobs/file-preview-decoder-contract.test.ts
T

29 lines
1.2 KiB
TypeScript

import { describe, expect, test } from "vitest";
import {
assertPreviewOutputSize,
assertPreviewRasterMetadata,
assertPreviewSourceSize,
FILE_PREVIEW_MAX_DIMENSION,
FILE_PREVIEW_MAX_PAGES,
FILE_PREVIEW_MAX_PIXELS,
FILE_PREVIEW_MAX_SOURCE_BYTES,
} from "./file-preview-decoder-contract.js";
describe("file preview decoder limits", () => {
test("accepts a normal single-page image", () => {
expect(() => assertPreviewRasterMetadata({ width: 4_000, height: 3_000, pages: 1 })).not.toThrow();
});
test("rejects decompression-bomb dimensions, pixels and page counts", () => {
expect(() => assertPreviewRasterMetadata({ width: FILE_PREVIEW_MAX_DIMENSION + 1, height: 1 })).toThrow("dimension limit");
expect(() => assertPreviewRasterMetadata({ width: 10_000, height: Math.floor(FILE_PREVIEW_MAX_PIXELS / 10_000) + 1 })).toThrow("pixel limit");
expect(() => assertPreviewRasterMetadata({ width: 1, height: 1, pages: FILE_PREVIEW_MAX_PAGES + 1 })).toThrow("page limit");
});
test("rejects oversized source and generated output buffers", () => {
expect(() => assertPreviewSourceSize(FILE_PREVIEW_MAX_SOURCE_BYTES + 1)).toThrow("byte limit");
expect(() => assertPreviewOutputSize(11, 10, "fixture")).toThrow("output limit");
});
});