mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 00:40:22 +00:00
fix(plugins): harden discovery trust checks
This commit is contained in:
@@ -489,4 +489,76 @@ describe("loadOpenClawPlugins", () => {
|
||||
expect(loaded?.origin).toBe("config");
|
||||
expect(overridden?.origin).toBe("bundled");
|
||||
});
|
||||
|
||||
it("warns when plugins.allow is empty and non-bundled plugins are discoverable", () => {
|
||||
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = "/nonexistent/bundled/plugins";
|
||||
const plugin = writePlugin({
|
||||
id: "warn-open-allow",
|
||||
body: `export default { id: "warn-open-allow", register() {} };`,
|
||||
});
|
||||
const warnings: string[] = [];
|
||||
loadOpenClawPlugins({
|
||||
cache: false,
|
||||
logger: {
|
||||
info: () => {},
|
||||
warn: (msg) => warnings.push(msg),
|
||||
error: () => {},
|
||||
},
|
||||
config: {
|
||||
plugins: {
|
||||
load: { paths: [plugin.file] },
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(
|
||||
warnings.some((msg) => msg.includes("plugins.allow is empty") && msg.includes(plugin.id)),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("warns when loaded non-bundled plugin has no install/load-path provenance", () => {
|
||||
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = "/nonexistent/bundled/plugins";
|
||||
const prevStateDir = process.env.OPENCLAW_STATE_DIR;
|
||||
const stateDir = makeTempDir();
|
||||
process.env.OPENCLAW_STATE_DIR = stateDir;
|
||||
try {
|
||||
const globalDir = path.join(stateDir, "extensions", "rogue");
|
||||
fs.mkdirSync(globalDir, { recursive: true });
|
||||
writePlugin({
|
||||
id: "rogue",
|
||||
body: `export default { id: "rogue", register() {} };`,
|
||||
dir: globalDir,
|
||||
filename: "index.js",
|
||||
});
|
||||
|
||||
const warnings: string[] = [];
|
||||
const registry = loadOpenClawPlugins({
|
||||
cache: false,
|
||||
logger: {
|
||||
info: () => {},
|
||||
warn: (msg) => warnings.push(msg),
|
||||
error: () => {},
|
||||
},
|
||||
config: {
|
||||
plugins: {
|
||||
allow: ["rogue"],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const rogue = registry.plugins.find((entry) => entry.id === "rogue");
|
||||
expect(rogue?.status).toBe("loaded");
|
||||
expect(
|
||||
warnings.some(
|
||||
(msg) =>
|
||||
msg.includes("rogue") && msg.includes("loaded without install/load-path provenance"),
|
||||
),
|
||||
).toBe(true);
|
||||
} finally {
|
||||
if (prevStateDir === undefined) {
|
||||
delete process.env.OPENCLAW_STATE_DIR;
|
||||
} else {
|
||||
process.env.OPENCLAW_STATE_DIR = prevStateDir;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user