Vydané zdroje
Stáhnout zdroje ZIP
CH-J Server Manager
Procházejte adresáře a soubory konkrétního vydání aplikace.
Zdroje jsou zveřejněny pod CH-J Proprietary Software License 1.14. Jejich dostupnost nemění licenční podmínky ani neposkytuje další oprávnění.
1
"use strict";3
const test = require("node:test");4
const assert = require("node:assert/strict");5
const crypto = require("node:crypto");6
const fs = require("node:fs");7
const os = require("node:os");8
const path = require("node:path");9
const { PluginCatalogProvider, validatePluginCatalog } = require("../src/main/plugins/pluginCatalogProvider");11
const baseUrl = "https://192.168.10.154/";12
const backupBaseUrl = "https://192.168.10.155/";14
function plugin(overrides = {}) {15
return {16
id: "release-system-monitor",17
plugin_id: "chj.system-monitor",18
name: "System Monitor",19
version: "0.0.1",20
min_app_version: "0.0.1",21
plugin_api: "^1.0.0",22
permissions: ["session.read", "system.metrics.read"],23
channel: "alpha",24
filename: "chj.system-monitor-0.0.1.chjplugin",25
size: 4096,26
sha512: "a".repeat(128),27
download_url: "https://192.168.10.154/files/plugins/chj.system-monitor/0.0.1/plugin.chjplugin",28
published_at: "2026-08-07T18:00:00+02:00",29
...overrides30
};31
}33
test("plugin catalog validates identity, compatibility, permissions and hash", () => {34
const result = validatePluginCatalog({ plugins: [plugin()] }, { channel: "alpha" });35
assert.equal(result[0].id, "chj.system-monitor");36
assert.deepEqual(result[0].permissions, ["session.read", "system.metrics.read"]);37
assert.throws(() => validatePluginCatalog({ plugins: [plugin({ permissions: ["electron.full"] })] }, { channel: "alpha" }), /permission/);38
assert.throws(() => validatePluginCatalog({ plugins: [plugin({ sha512: "bad" })] }, { channel: "alpha" }), /SHA-512/);39
assert.throws(() => validatePluginCatalog({ plugins: [plugin(), plugin()] }, { channel: "alpha" }), /Duplicate plugin ID/);40
});42
test("all plugin channels are fetched separately and merged locally", async () => {43
const requestedChannels = [];44
const provider = new PluginCatalogProvider({45
baseUrls: [baseUrl],46
fetchImpl: async (url) => {47
const channel = url.searchParams.get("channel");48
requestedChannels.push(channel);49
return new Response(JSON.stringify({50
plugins: [plugin({ id: `${channel}-system-monitor`, channel })]51
}), { status: 200 });52
}53
});54
const result = await provider.list({ appVersion: "0.0.1", channel: "all" });55
assert.deepEqual(requestedChannels, ["alpha", "beta", "stable"]);56
assert.deepEqual(new Set(result.plugins.map((item) => item.channel)), new Set(["alpha", "beta", "stable"]));57
});59
test("plugin download fails over to the same file path on a configured backup server", async (t) => {60
const root = fs.mkdtempSync(path.join(os.tmpdir(), "chj-plugin-fallback-"));61
t.after(() => fs.rmSync(root, { recursive: true, force: true }));62
const bytes = Buffer.from("verified-plugin");63
const requested = [];64
const provider = new PluginCatalogProvider({65
baseUrls: [baseUrl, backupBaseUrl],66
downloadRoot: root,67
fetchImpl: async (url) => {68
requested.push(url.toString());69
if (url.hostname === "192.168.10.154") return new Response(null, { status: 503 });70
return new Response(bytes, { status: 200, headers: { "content-length": String(bytes.length) } });71
}72
});73
const result = await provider.downloadAndVerify({74
releaseId: "release-1", id: "chj.system-monitor", version: "0.0.1", filename: "plugin.chjplugin",75
size: bytes.length, sha512: crypto.createHash("sha512").update(bytes).digest("hex"),76
downloadUrl: `${baseUrl}files/plugins/chj.system-monitor/0.0.1/plugin.chjplugin`77
});78
assert.equal(new URL(result.sourceUrl).hostname, "192.168.10.155");79
assert.deepEqual(requested.map((value) => new URL(value).hostname), ["192.168.10.154", "192.168.10.155"]);80
assert.equal(fs.readFileSync(result.path, "utf8"), bytes.toString("utf8"));81
});SHA-256: c2e3e718109f5699bd293428e1c5b8259291aa14059fdf8c3b3544386fa4f353
SHA-256 archivu: 5ac91caf4fa32a6fdb114f2430deed486fbe7489d5eea343d1f034169fafb5e0