mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 08:32:43 +00:00
refactor(test): drop redundant env snapshots in skill download suites
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { captureEnv } from "../test-utils/env.js";
|
|
||||||
import { withTempWorkspace, writeDownloadSkill } from "./skills-install.download-test-utils.js";
|
import { withTempWorkspace, writeDownloadSkill } from "./skills-install.download-test-utils.js";
|
||||||
import { installSkill } from "./skills-install.js";
|
import { installSkill } from "./skills-install.js";
|
||||||
|
|
||||||
@@ -9,7 +8,6 @@ const mocks = {
|
|||||||
scanSummary: vi.fn(),
|
scanSummary: vi.fn(),
|
||||||
fetchGuard: vi.fn(),
|
fetchGuard: vi.fn(),
|
||||||
};
|
};
|
||||||
let envSnapshot: ReturnType<typeof captureEnv>;
|
|
||||||
|
|
||||||
function mockDownloadResponse() {
|
function mockDownloadResponse() {
|
||||||
mocks.fetchGuard.mockResolvedValue({
|
mocks.fetchGuard.mockResolvedValue({
|
||||||
@@ -91,7 +89,6 @@ vi.mock("../security/skill-scanner.js", async (importOriginal) => {
|
|||||||
|
|
||||||
describe("installSkill download extraction safety (tar.bz2)", () => {
|
describe("installSkill download extraction safety (tar.bz2)", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
envSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]);
|
|
||||||
mocks.runCommand.mockReset();
|
mocks.runCommand.mockReset();
|
||||||
mocks.scanSummary.mockReset();
|
mocks.scanSummary.mockReset();
|
||||||
mocks.fetchGuard.mockReset();
|
mocks.fetchGuard.mockReset();
|
||||||
@@ -104,10 +101,6 @@ describe("installSkill download extraction safety (tar.bz2)", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
envSnapshot.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("rejects tar.bz2 traversal before extraction", async () => {
|
it("rejects tar.bz2 traversal before extraction", async () => {
|
||||||
await withTempWorkspace(async ({ workspaceDir, stateDir }) => {
|
await withTempWorkspace(async ({ workspaceDir, stateDir }) => {
|
||||||
const url = "https://example.invalid/evil.tbz2";
|
const url = "https://example.invalid/evil.tbz2";
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ import fs from "node:fs/promises";
|
|||||||
import path from "node:path";
|
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 { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { captureEnv } from "../test-utils/env.js";
|
|
||||||
import { withTempWorkspace, writeDownloadSkill } from "./skills-install.download-test-utils.js";
|
import { withTempWorkspace, writeDownloadSkill } from "./skills-install.download-test-utils.js";
|
||||||
import { installSkill } from "./skills-install.js";
|
import { installSkill } from "./skills-install.js";
|
||||||
|
|
||||||
@@ -11,8 +10,6 @@ const runCommandWithTimeoutMock = vi.fn();
|
|||||||
const scanDirectoryWithSummaryMock = vi.fn();
|
const scanDirectoryWithSummaryMock = vi.fn();
|
||||||
const fetchWithSsrFGuardMock = vi.fn();
|
const fetchWithSsrFGuardMock = vi.fn();
|
||||||
|
|
||||||
let envSnapshot: ReturnType<typeof captureEnv>;
|
|
||||||
|
|
||||||
vi.mock("../process/exec.js", () => ({
|
vi.mock("../process/exec.js", () => ({
|
||||||
runCommandWithTimeout: (...args: unknown[]) => runCommandWithTimeoutMock(...args),
|
runCommandWithTimeout: (...args: unknown[]) => runCommandWithTimeoutMock(...args),
|
||||||
}));
|
}));
|
||||||
@@ -73,7 +70,6 @@ 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();
|
||||||
@@ -86,10 +82,6 @@ describe("installSkill download extraction safety", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
envSnapshot.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("rejects zip slip traversal", async () => {
|
it("rejects zip slip traversal", async () => {
|
||||||
await withTempWorkspace(async ({ workspaceDir, stateDir }) => {
|
await withTempWorkspace(async ({ workspaceDir, stateDir }) => {
|
||||||
const targetDir = path.join(stateDir, "tools", "zip-slip", "target");
|
const targetDir = path.join(stateDir, "tools", "zip-slip", "target");
|
||||||
|
|||||||
Reference in New Issue
Block a user