mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 14:48:28 +00:00
refactor(test): snapshot skills install state dir env
This commit is contained in:
@@ -4,6 +4,7 @@ import path from "node:path";
|
|||||||
import JSZip from "jszip";
|
import JSZip from "jszip";
|
||||||
import * as tar from "tar";
|
import * as tar from "tar";
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import { captureEnv } from "../test-utils/env.js";
|
||||||
import { setTempStateDir, writeDownloadSkill } from "./skills-install.download-test-utils.js";
|
import { setTempStateDir, writeDownloadSkill } from "./skills-install.download-test-utils.js";
|
||||||
import { installSkill } from "./skills-install.js";
|
import { installSkill } from "./skills-install.js";
|
||||||
|
|
||||||
@@ -11,15 +12,7 @@ const runCommandWithTimeoutMock = vi.fn();
|
|||||||
const scanDirectoryWithSummaryMock = vi.fn();
|
const scanDirectoryWithSummaryMock = vi.fn();
|
||||||
const fetchWithSsrFGuardMock = vi.fn();
|
const fetchWithSsrFGuardMock = vi.fn();
|
||||||
|
|
||||||
const originalOpenClawStateDir = process.env.OPENCLAW_STATE_DIR;
|
let envSnapshot: ReturnType<typeof captureEnv>;
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
if (originalOpenClawStateDir === undefined) {
|
|
||||||
delete process.env.OPENCLAW_STATE_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.OPENCLAW_STATE_DIR = originalOpenClawStateDir;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
vi.mock("../process/exec.js", () => ({
|
vi.mock("../process/exec.js", () => ({
|
||||||
runCommandWithTimeout: (...args: unknown[]) => runCommandWithTimeoutMock(...args),
|
runCommandWithTimeout: (...args: unknown[]) => runCommandWithTimeoutMock(...args),
|
||||||
@@ -81,6 +74,7 @@ async function installZipDownloadSkill(params: {
|
|||||||
|
|
||||||
describe("installSkill download extraction safety", () => {
|
describe("installSkill download extraction safety", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
envSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]);
|
||||||
runCommandWithTimeoutMock.mockReset();
|
runCommandWithTimeoutMock.mockReset();
|
||||||
scanDirectoryWithSummaryMock.mockReset();
|
scanDirectoryWithSummaryMock.mockReset();
|
||||||
fetchWithSsrFGuardMock.mockReset();
|
fetchWithSsrFGuardMock.mockReset();
|
||||||
@@ -93,6 +87,10 @@ describe("installSkill download extraction safety", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
envSnapshot.restore();
|
||||||
|
});
|
||||||
|
|
||||||
it("rejects zip slip traversal", async () => {
|
it("rejects zip slip traversal", async () => {
|
||||||
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-skills-install-"));
|
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-skills-install-"));
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user