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>
45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
import { describe, it, afterEach } from "node:test";
|
|
import assert from "node:assert";
|
|
import { existsSync, readFileSync, rmSync } from "fs";
|
|
import { join } from "path";
|
|
import { tmpdir } from "os";
|
|
import { PluginLogger } from "../../src/lib/plugins/logger.ts";
|
|
|
|
describe("PluginLogger", () => {
|
|
const testDir = join(tmpdir(), `plugin-logger-test-${Date.now()}`);
|
|
|
|
afterEach(() => {
|
|
try { rmSync(testDir, { recursive: true, force: true }); } catch {}
|
|
});
|
|
|
|
it("creates log file and writes JSON entries", () => {
|
|
const logger = new PluginLogger("test-plugin", testDir);
|
|
logger.info("hello world");
|
|
const logPath = join(testDir, "test-plugin", "plugin.log");
|
|
assert.ok(existsSync(logPath));
|
|
const content = readFileSync(logPath, "utf-8").trim();
|
|
const entry = JSON.parse(content);
|
|
assert.strictEqual(entry.level, "INFO");
|
|
assert.strictEqual(entry.message, "hello world");
|
|
assert.ok(entry.timestamp);
|
|
});
|
|
|
|
it("writes error entries", () => {
|
|
const logger = new PluginLogger("err-plugin", testDir);
|
|
logger.error("bad thing", { code: 500 });
|
|
const logPath = join(testDir, "err-plugin", "plugin.log");
|
|
const entry = JSON.parse(readFileSync(logPath, "utf-8").trim());
|
|
assert.strictEqual(entry.level, "ERROR");
|
|
assert.deepStrictEqual(entry.data, { code: 500 });
|
|
});
|
|
|
|
it("appends multiple entries", () => {
|
|
const logger = new PluginLogger("multi-plugin", testDir);
|
|
logger.info("first");
|
|
logger.warn("second");
|
|
const logPath = join(testDir, "multi-plugin", "plugin.log");
|
|
const lines = readFileSync(logPath, "utf-8").trim().split("\n");
|
|
assert.strictEqual(lines.length, 2);
|
|
});
|
|
});
|