Published source
Download source ZIP
CH-J Server Manager
Browse directories and files for a specific application release.
Source is provided under the CH-J Proprietary Software License 1.14. Its availability does not change the license terms or grant additional rights.
1
"use strict";3
const test = require("node:test");4
const assert = require("node:assert/strict");5
const fs = require("node:fs");6
const os = require("node:os");7
const path = require("node:path");8
const AdmZip = require("adm-zip");9
const { ALLOWED_EXTENSIONS, PluginInstaller, safeEntryName } = require("../src/main/plugins/pluginInstaller");10
const { PluginRegistry } = require("../src/main/plugins/pluginRegistry");12
function manifest() {13
return {14
schemaVersion: 1,15
id: "chj.system-monitor",16
name: "System Monitor",17
version: "0.0.1",18
publisher: "CH-J",19
entry: "ui/index.html",20
pluginApi: "^1.0.0",21
minAppVersion: "0.0.1",22
permissions: ["session.read", "system.metrics.read"]23
};24
}26
test("plugin installer validates and atomically installs a standalone package", (t) => {27
const root = fs.mkdtempSync(path.join(os.tmpdir(), "chj-plugin-install-"));28
t.after(() => fs.rmSync(root, { recursive: true, force: true }));29
const archive = path.join(root, "system-monitor.chjplugin");30
const zip = new AdmZip();31
zip.addFile("manifest.json", Buffer.from(JSON.stringify(manifest())));32
zip.addFile("ui/index.html", Buffer.from("<!doctype html><script src=\"index.js\"></script>"));33
zip.addFile("ui/index.js", Buffer.from("'use strict';"));34
zip.writeZip(archive);35
const catalog = {36
releaseId: "release-1", id: "chj.system-monitor", version: "0.0.1", pluginApi: "^1.0.0", minAppVersion: "0.0.1",37
permissions: ["session.read", "system.metrics.read"], sha512: "a".repeat(128), publishedAt: "2026-08-07T16:00:00Z"38
};39
const installer = new PluginInstaller({ storageRoot: root, appVersion: "0.0.1" });40
const result = installer.install(archive, catalog);41
assert.equal(result.manifest.id, "chj.system-monitor");42
assert.equal(new PluginRegistry(root).listInstalled()[0].version, "0.0.1");43
assert.equal(installer.install(archive, catalog).reused, true);44
});46
test("plugin paths reject traversal, absolute paths and drive paths", () => {47
assert.throws(() => safeEntryName("../escape.js"), /Unsafe/);48
assert.throws(() => safeEntryName("/absolute.js"), /Unsafe/);49
assert.throws(() => safeEntryName("C:/escape.js"), /Unsafe/);50
assert.equal(safeEntryName("ui/index.js"), "ui/index.js");51
assert.ok(ALLOWED_EXTENSIONS.has(".ttf"));52
});SHA-256: 428bf529120358d3a7c5aa0d8543cabd74e888ea202e2c3e0ef9fe0ae3868a02
Archive SHA-256: 5ac91caf4fa32a6fdb114f2430deed486fbe7489d5eea343d1f034169fafb5e0