49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
detectKind,
|
|
fileExtension,
|
|
inventoryIdentity,
|
|
} from "../../src/privacy";
|
|
import { jpegFixture, pngFixture, webpFixture } from "../fixtures/images";
|
|
|
|
describe("file identity", () => {
|
|
it("detects supported containers from bytes", () => {
|
|
expect(detectKind(jpegFixture())).toBe("jpeg");
|
|
expect(detectKind(pngFixture())).toBe("png");
|
|
expect(detectKind(webpFixture())).toBe("webp");
|
|
expect(detectKind(Uint8Array.from([0x25, 0x50, 0x44, 0x46, 0x2d]))).toBe(
|
|
"pdf",
|
|
);
|
|
});
|
|
|
|
it("normalizes leaf extensions without trusting paths", () => {
|
|
expect(fileExtension("folder\\PHOTO.JPEG")).toBe("jpeg");
|
|
expect(fileExtension(".hidden")).toBe("");
|
|
expect(fileExtension("no-extension")).toBe("");
|
|
});
|
|
|
|
it("reports claimed and extension mismatches", () => {
|
|
const identity = inventoryIdentity(
|
|
"portrait.jpg",
|
|
"image/jpeg",
|
|
pngFixture(),
|
|
);
|
|
expect(identity).toMatchObject({
|
|
detectedKind: "png",
|
|
detectedType: "image/png",
|
|
typeMatch: "mismatch",
|
|
});
|
|
});
|
|
|
|
it("does not infer an unknown payload from its extension", () => {
|
|
const identity = inventoryIdentity(
|
|
"claim.png",
|
|
"image/png",
|
|
Uint8Array.from([1, 2, 3]),
|
|
);
|
|
expect(identity.detectedKind).toBe("unknown");
|
|
expect(identity.typeMatch).toBe("unknown");
|
|
});
|
|
});
|