import fs from "node:fs/promises"; import path from "node:path"; import { afterAll, beforeAll, describe, expect, it, vi } from "vitest"; import type { OpenClawConfig } from "../config/config.js"; import { collectWorkspaceSkillSymlinkEscapeFindings } from "./audit-extra.async.js"; import { AsyncTempCaseFactory } from "./test-temp-cases.js";
// Simulate realpath failing for the skill file path — this mirrors what // happens when a slow/hanging NFS or SMB mount causes the 2 s deadline in // realpathWithTimeout to fire. The .catch(() => null) inside the helper // converts any rejection to null, which is the same signal produced by a // genuine timeout. All other paths resolve to their string value so the BFS // and workspace-root detection work normally. const realpathSpy = vi
.spyOn(fs, "realpath")
.mockImplementation(async (p: unknown): Promise<string> => { if (String(p).endsWith("SKILL.md")) { thrownew Error("simulated realpath timeout");
} return String(p);
});
try { const findings = await collectWorkspaceSkillSymlinkEscapeFindings({
cfg: { agents: { defaults: { workspace: workspaceDir } } } satisfies OpenClawConfig,
}); const escapeFinding = findings.find((f) => f.checkId === "skills.workspace.symlink_escape");
expect(escapeFinding).toBeDefined();
expect(escapeFinding?.severity).toBe("warn"); // The finding must call out that realpath was unverifiable, not that it // resolved to a path outside the workspace.
expect(escapeFinding?.detail).toContain("realpath timed out");
} finally {
realpathSpy.mockRestore();
}
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.