mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-20 07:04:53 +00:00
* feat(plugins): add isolated plugin host runtime * test(plugins): build runtime dependencies before tests * fix(plugins): harden runtime lifecycle and recovery * fix(plugins): harden runtime extension boundaries * fix(plugins): enforce runtime integrity boundaries * fix(plugins): await utility process exit * fix(plugins): harden utility process containment * fix(plugins): close runtime recovery gaps * fix(plugins): harden runtime lifecycle boundaries
49 lines
1.9 KiB
JavaScript
49 lines
1.9 KiB
JavaScript
"use strict";
|
|
|
|
const assert = require("node:assert/strict");
|
|
const test = require("node:test");
|
|
|
|
const {
|
|
PLUGIN_JSON_MAX_DEPTH,
|
|
PLUGIN_JSON_MAX_NODES,
|
|
assertPluginJsonValue,
|
|
} = require("./jsonBoundary.cjs");
|
|
|
|
test("main-process JSON boundary matches the public contract budgets", async () => {
|
|
const contract = await import("@netcatty/plugin-contract");
|
|
const hostLimits = require("./constants.cjs");
|
|
assert.equal(PLUGIN_JSON_MAX_DEPTH, contract.PLUGIN_JSON_MAX_DEPTH);
|
|
assert.equal(PLUGIN_JSON_MAX_NODES, contract.PLUGIN_JSON_MAX_NODES);
|
|
assert.equal(hostLimits.PLUGIN_RPC_MAX_JSON_BYTES, contract.PLUGIN_RPC_MAX_JSON_BYTES);
|
|
assert.equal(
|
|
hostLimits.PLUGIN_STREAM_MAX_FRAME_JSON_BYTES,
|
|
contract.PLUGIN_STREAM_MAX_FRAME_JSON_BYTES,
|
|
);
|
|
});
|
|
|
|
test("main-process JSON boundary rejects deep, sparse, cyclic, and accessor values", () => {
|
|
let deep = null;
|
|
for (let index = 0; index <= PLUGIN_JSON_MAX_DEPTH; index += 1) deep = [deep];
|
|
assert.throws(() => assertPluginJsonValue(deep), /levels/);
|
|
const sparse = [];
|
|
sparse.length = 1;
|
|
assert.throws(() => assertPluginJsonValue(sparse), /dense/);
|
|
const cyclic = {};
|
|
cyclic.self = cyclic;
|
|
assert.throws(() => assertPluginJsonValue(cyclic), /cycles/);
|
|
const accessor = {};
|
|
Object.defineProperty(accessor, "value", { get: () => 1, enumerable: true });
|
|
assert.throws(() => assertPluginJsonValue(accessor), /data properties/);
|
|
});
|
|
|
|
test("main-process JSON boundary enforces an incremental UTF-8 byte budget", () => {
|
|
const value = { text: "你好\n\"", empty: [] };
|
|
const exactBytes = Buffer.byteLength(JSON.stringify(value), "utf8");
|
|
assert.deepEqual(assertPluginJsonValue(value, { maxBytes: exactBytes }), value);
|
|
assert.throws(
|
|
() => assertPluginJsonValue(value, { maxBytes: exactBytes - 1 }),
|
|
new RegExp(`exceeds ${exactBytes - 1} bytes`),
|
|
);
|
|
assert.throws(() => assertPluginJsonValue({}, { maxBytes: 0 }), /positive safe integer/);
|
|
});
|