mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
Integrates two community contributions into release/v3.8.8 with security hardening and conflict resolution. - **Plugins framework** (#2913 — thanks @oyi77): hooks + registry unification, plugin SDK (`definePlugin`), worker-thread sandbox, per-plugin hook rate limiting, SHA-256 integrity verification, semver-gated upgrade, and execution analytics. Plugin routes are loopback-only (`isLocalOnlyPath`); `child_process` exec is opt-in via `OMNIROUTE_PLUGINS_ALLOW_EXEC` (default off). - **API key option: disable non-published models** (#3017 — thanks @androw): a per-key flag restricting the key to discovered public models (combos / `auto/*` / `qtSd/*` routing still allowed). Hardening applied during integration: migration renumber (089/090/091), `/api/plugins` LOCAL_ONLY route-guard classification (closes the plugin-RCE vector), atomic install/upgrade with path containment, `O_EXCL` tmp-file creation (TOCTOU), rate-limit-map eviction, `validatePluginConfig` on configure, `buildErrorBody` on all plugin error paths. 246/246 tests; typecheck / cycles / docs-sync clean. Co-authored-by: oyi77 <14921983+oyi77@users.noreply.github.com> Co-authored-by: Nicolas Lorin <androw95220@gmail.com>
41 lines
1.6 KiB
TypeScript
41 lines
1.6 KiB
TypeScript
import { describe, it } from "node:test";
|
|
import assert from "node:assert";
|
|
import { PluginError, PluginErrorCode, isPluginError } from "../../src/lib/plugins/errors.ts";
|
|
|
|
describe("PluginError", () => {
|
|
it("has correct code and message", () => {
|
|
const err = new PluginError(PluginErrorCode.PLUGIN_NOT_FOUND, "not found");
|
|
assert.strictEqual(err.code, "PLUGIN_NOT_FOUND");
|
|
assert.strictEqual(err.message, "not found");
|
|
assert.strictEqual(err.name, "PluginError");
|
|
});
|
|
|
|
it("stores details", () => {
|
|
const err = new PluginError(PluginErrorCode.INSTALL_FAILED, "fail", { reason: "bad" });
|
|
assert.deepStrictEqual(err.details, { reason: "bad" });
|
|
});
|
|
|
|
it("isPluginError returns true for PluginError", () => {
|
|
const err = new PluginError(PluginErrorCode.RATE_LIMITED, "rate limited");
|
|
assert.strictEqual(isPluginError(err), true);
|
|
});
|
|
|
|
it("isPluginError returns false for plain Error", () => {
|
|
assert.strictEqual(isPluginError(new Error("plain")), false);
|
|
});
|
|
|
|
it("isPluginError returns false for non-error", () => {
|
|
assert.strictEqual(isPluginError("string"), false);
|
|
});
|
|
|
|
it("all 14 error codes exist", () => {
|
|
const codes = Object.values(PluginErrorCode);
|
|
assert.strictEqual(codes.length, 14);
|
|
assert.ok(codes.includes(PluginErrorCode.PLUGIN_NOT_FOUND));
|
|
assert.ok(codes.includes(PluginErrorCode.ALREADY_INSTALLED));
|
|
assert.ok(codes.includes(PluginErrorCode.DEPENDENCY_MISSING));
|
|
assert.ok(codes.includes(PluginErrorCode.DEPENDENT_EXISTS));
|
|
assert.ok(codes.includes(PluginErrorCode.RATE_LIMITED));
|
|
});
|
|
});
|