Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/api/pdf-page-tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,68 @@ describe("PageTree", () => {
});
});

describe("load() - indirect Kids", () => {
it("resolves a /Kids array stored as an indirect object", async () => {
// Some producers (e.g. "Dr. Tax Office") write the Kids array as its
// own indirect object: /Kids 4 0 R instead of /Kids [ ... ].
const page1Ref = PdfRef.of(3, 0);
const page2Ref = PdfRef.of(4, 0);
const kidsRef = PdfRef.of(2, 0);
const rootRef = PdfRef.of(1, 0);

const root = new PdfDict();
root.set("Type", PdfName.Pages);
root.set("Kids", kidsRef);
root.set("Count", PdfNumber.of(2));

const objects = new Map<string, PdfObject>([
["1:0", root],
["2:0", new PdfArray([page1Ref, page2Ref])],
["3:0", createPage()],
["4:0", createPage()],
]);

const tree = PDFPageTree.load(rootRef, createResolver(objects));

expect(tree.getPageCount()).toBe(2);
expect(tree.getPage(0)).toBe(page1Ref);
expect(tree.getPage(1)).toBe(page2Ref);
});

it("resolves indirect /Kids on intermediate nodes", async () => {
const page1Ref = PdfRef.of(5, 0);
const page2Ref = PdfRef.of(6, 0);
const intermediateKidsRef = PdfRef.of(4, 0);
const intermediateRef = PdfRef.of(3, 0);
const rootKidsRef = PdfRef.of(2, 0);
const rootRef = PdfRef.of(1, 0);

const root = new PdfDict();
root.set("Type", PdfName.Pages);
root.set("Kids", rootKidsRef);
root.set("Count", PdfNumber.of(2));

const intermediate = new PdfDict();
intermediate.set("Type", PdfName.Pages);
intermediate.set("Kids", intermediateKidsRef);
intermediate.set("Count", PdfNumber.of(2));

const objects = new Map<string, PdfObject>([
["1:0", root],
["2:0", new PdfArray([intermediateRef])],
["3:0", intermediate],
["4:0", new PdfArray([page1Ref, page2Ref])],
["5:0", createPage()],
["6:0", createPage()],
]);

const tree = PDFPageTree.load(rootRef, createResolver(objects));

expect(tree.getPageCount()).toBe(2);
expect(tree.getPages()).toEqual([page1Ref, page2Ref]);
});
});

describe("load() - nested tree", () => {
it("loads a two-level tree", async () => {
// Structure:
Expand Down
4 changes: 3 additions & 1 deletion src/api/pdf-page-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ export class PDFPageTree {

loadedPages.set(key, node);
} else if (type === "Pages") {
const kids = node.getArray("Kids");
// Kids may be an indirect reference to the array (e.g. /Kids 4 0 R),
// so resolve through getObject rather than reading the raw value.
const kids = node.getArray("Kids", getObject);

if (kids) {
for (let i = 0; i < kids.length; i++) {
Expand Down
4 changes: 2 additions & 2 deletions src/integration/signatures/lta-finalization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { HttpTimestampAuthority } from "#src/signatures/timestamp";
import { loadFixture, saveTestOutput } from "#src/test-utils";
import { describe, expect, it } from "vitest";

import { loadTestSigner, TEST_TSA_URL } from "./test-helpers";
import { loadTestSigner, NETWORK_TEST_TIMEOUT, TEST_TSA_URL } from "./test-helpers";

describe("LTA finalization integration", () => {
describe("LTA finalization integration", { timeout: NETWORK_TEST_TIMEOUT }, () => {
const tsa = new HttpTimestampAuthority(TEST_TSA_URL);

describe("addValidationData()", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/integration/signatures/signing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { HttpTimestampAuthority } from "#src/signatures/timestamp";
import { loadFixture, saveTestOutput } from "#src/test-utils";
import { describe, expect, it } from "vitest";

import { loadTestSigner, P12_FILES, TEST_TSA_URL } from "./test-helpers";
import { loadTestSigner, NETWORK_TEST_TIMEOUT, P12_FILES, TEST_TSA_URL } from "./test-helpers";

describe("signing integration", () => {
describe("signing integration", { timeout: NETWORK_TEST_TIMEOUT }, () => {
describe("B-B signing (basic)", () => {
it("signs a simple PDF document", async () => {
const pdfBytes = await loadFixture("basic", "rot0.pdf");
Expand Down
8 changes: 8 additions & 0 deletions src/integration/signatures/test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import { loadFixture } from "#src/test-utils";
/** Public RFC 3161 timestamp authority used by integration tests. */
export const TEST_TSA_URL = "https://freetsa.org/tsr";

/**
* Per-test timeout for suites that hit the live TSA and fetch OCSP/CRL data.
*
* These tests do real network round-trips plus RSA/CMS work, and when the
* full suite runs in parallel they can easily exceed the global 15s default.
*/
export const NETWORK_TEST_TIMEOUT = 60_000;

/** Test P12 files with different encryption formats */
export const P12_FILES = {
/** AES-256-CBC (modern default) */
Expand Down
4 changes: 2 additions & 2 deletions src/integration/signatures/timestamping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { HttpTimestampAuthority } from "#src/signatures/timestamp";
import { loadFixture, saveTestOutput } from "#src/test-utils";
import { describe, expect, it } from "vitest";

import { loadTestSigner, TEST_TSA_URL } from "./test-helpers";
import { loadTestSigner, NETWORK_TEST_TIMEOUT, TEST_TSA_URL } from "./test-helpers";

describe("timestamping integration", () => {
describe("timestamping integration", { timeout: NETWORK_TEST_TIMEOUT }, () => {
const tsa = new HttpTimestampAuthority(TEST_TSA_URL);

describe("standalone document timestamp", () => {
Expand Down
Loading