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 fs = require("node:fs");6
const os = require("node:os");7
const path = require("node:path");8
const { ProfileService } = require("../src/main/profiles/profileService");9
const { VaultStore } = require("../src/main/security/vaultStore");11
test("profile service persists validated profiles and trusted host keys", async (t) => {12
const root = fs.mkdtempSync(path.join(os.tmpdir(), "chj-profiles-"));13
t.after(() => fs.rmSync(root, { recursive: true, force: true }));14
const vault = new VaultStore(root);15
await vault.create("correct horse battery staple");16
const profiles = new ProfileService(vault);18
const saved = profiles.save({ label: "NAS", host: "QNAP.local", port: 22, username: "admin", authMethod: "password" });19
assert.equal(saved.host, "qnap.local");20
assert.equal(profiles.list()[0].id, saved.id);21
const fingerprint = "ab".repeat(32);22
profiles.trustHostKey(saved.host, saved.port, fingerprint);23
assert.equal(profiles.getHostKey("QNAP.LOCAL", 22), fingerprint);24
assert.equal(profiles.delete(saved.id).removed, true);25
assert.equal(profiles.list().length, 0);26
});28
test("profile service rejects invalid connection data", async (t) => {29
const root = fs.mkdtempSync(path.join(os.tmpdir(), "chj-profiles-"));30
t.after(() => fs.rmSync(root, { recursive: true, force: true }));31
const vault = new VaultStore(root);32
await vault.create("correct horse battery staple");33
const profiles = new ProfileService(vault);34
assert.throws(() => profiles.save({ host: "bad host", username: "root" }), /host/);35
assert.throws(() => profiles.save({ host: "server.local", port: 70000, username: "root" }), /port/);36
assert.throws(() => profiles.save({ host: "server.local", username: "root", authMethod: "privateKey" }), /private key/);37
});39
test("profile service stores SSH passwords only in encrypted vault secrets", async (t) => {40
const root = fs.mkdtempSync(path.join(os.tmpdir(), "chj-profile-password-"));41
t.after(() => fs.rmSync(root, { recursive: true, force: true }));42
const vault = new VaultStore(root);43
await vault.create("correct horse battery staple");44
const profiles = new ProfileService(vault);45
const saved = profiles.save({ host: "server.local", username: "test", authMethod: "password", storePassword: true, password: "ssh-secret" });46
assert.equal(saved.hasStoredPassword, true);47
assert.equal(Object.prototype.hasOwnProperty.call(saved, "password"), false);48
assert.equal(profiles.getStoredPassword(saved.id), "ssh-secret");49
assert.doesNotMatch(fs.readFileSync(vault.dataPath, "utf8"), /ssh-secret/);51
profiles.save({ ...saved, storePassword: true, password: "" });52
assert.equal(profiles.getStoredPassword(saved.id), "ssh-secret");53
profiles.save({ ...saved, storePassword: false });54
assert.equal(profiles.getStoredPassword(saved.id), null);55
});SHA-256: 8b6164e63817c6db2dd66796221db5534742a9f18ced742d9db93337cf2dd620
SHA-256 archivu: 5ac91caf4fa32a6fdb114f2430deed486fbe7489d5eea343d1f034169fafb5e0