@@ -7,11 +7,15 @@ import {
|
||||
familyForFormat,
|
||||
formatBytes,
|
||||
formatLabel,
|
||||
validateOfficePackagePrefix,
|
||||
} from "../../src/office/formats";
|
||||
|
||||
describe("office format handling", () => {
|
||||
it.each([
|
||||
["REPORT.DOCX", "docx"],
|
||||
["REPORT.DOCM", "docx"],
|
||||
["template.xltx", "xlsx"],
|
||||
["show.ppsm", "pptx"],
|
||||
["notes.odt", "odt"],
|
||||
["budget.xlsx", "xlsx"],
|
||||
["budget.ODS", "ods"],
|
||||
@@ -21,6 +25,24 @@ describe("office format handling", () => {
|
||||
expect(detectOfficeFormat({ name, size: 42 })).toBe(expected);
|
||||
});
|
||||
|
||||
it("rejects renamed compound-binary, RTF and non-package signatures", () => {
|
||||
expect(() =>
|
||||
validateOfficePackagePrefix(
|
||||
Uint8Array.from([0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1]),
|
||||
"docx",
|
||||
),
|
||||
).toThrow(/OLE Compound File/u);
|
||||
expect(() =>
|
||||
validateOfficePackagePrefix(new TextEncoder().encode("{\\rtf1"), "docx"),
|
||||
).toThrow(/Rich Text Format/u);
|
||||
expect(() =>
|
||||
validateOfficePackagePrefix(new TextEncoder().encode("not zip!"), "xlsx"),
|
||||
).toThrow(/ZIP-based/u);
|
||||
expect(() =>
|
||||
validateOfficePackagePrefix(Uint8Array.from([0x50, 0x4b, 3, 4]), "pptx"),
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it("rejects empty, oversized, unsupported and legacy inputs explicitly", () => {
|
||||
const cases = [
|
||||
[{ name: "empty.docx", size: 0 }, "empty-file"],
|
||||
|
||||
Reference in New Issue
Block a user