Files
NetMesh/domain/quickConnectHost.test.ts
zhaolei 3c72efcb7f
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
[Init] Initial commit - NetMesh terminal manager
2026-09-13 18:24:01 +08:00

152 lines
3.9 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import {
buildQuickConnectHost,
isQuickConnectIdentityUsable,
} from "./quickConnectHost.ts";
import { resolveHostAuth } from "./sshAuth.ts";
const target = { hostname: "example.com" };
test("quick connect keeps a selected credential preset as the host identity", () => {
const host = buildQuickConnectHost({
id: "quick-1",
createdAt: 123,
target,
protocol: "ssh",
port: 22,
username: "root",
authMethod: "password",
password: "must-not-be-copied",
selectedIdentityId: "identity-root",
});
assert.equal(host.identityId, "identity-root");
assert.equal(host.username, "root");
assert.equal(host.authMethod, "password");
assert.equal(host.password, undefined);
assert.equal(host.identityFileId, undefined);
assert.equal(host.ephemeral, true);
const resolved = resolveHostAuth({
host,
keys: [],
identities: [{
id: "identity-root",
label: "Root",
username: "root",
authMethod: "password",
password: "resolved-secret",
created: 1,
}],
});
assert.equal(resolved.password, "resolved-secret");
});
test("quick connect only offers one-click connection for usable credential presets", () => {
assert.equal(isQuickConnectIdentityUsable({
id: "password",
label: "Root",
username: "root",
authMethod: "password",
password: "secret",
created: 1,
}, []), true);
assert.equal(isQuickConnectIdentityUsable({
id: "missing-key",
label: "Deploy",
username: "deploy",
authMethod: "key",
keyId: "key-that-is-not-here",
created: 2,
}, []), false);
assert.equal(isQuickConnectIdentityUsable({
id: "telnet-password",
label: "Network password",
username: "admin",
authMethod: "password",
password: "secret",
created: 3,
}, [], "telnet"), false);
});
test("quick connect preserves manually entered password authentication", () => {
const host = buildQuickConnectHost({
id: "quick-2",
createdAt: 456,
target,
protocol: "ssh",
port: 2222,
username: "operator",
authMethod: "password",
password: "manual-secret",
});
assert.equal(host.identityId, undefined);
assert.equal(host.username, "operator");
assert.equal(host.password, "manual-secret");
assert.equal(host.port, 2222);
assert.equal(host.ephemeral, true);
});
test("quick connect creates an ephemeral ET connection without saving credentials", () => {
const host = buildQuickConnectHost({
id: "quick-et",
createdAt: 1,
target,
protocol: "et",
port: 22,
username: "alice",
authMethod: "password",
password: "secret",
});
assert.equal(host.protocol, "ssh");
assert.equal(host.etEnabled, true);
assert.equal(host.etPort, 2022);
assert.equal(host.ephemeral, true);
assert.equal(host.password, "secret");
});
test("quick connect keeps Mosh on SSH bootstrap settings", () => {
const host = buildQuickConnectHost({
id: "quick-mosh",
createdAt: 1,
target,
protocol: "mosh",
port: 2202,
username: "root",
authMethod: "key",
selectedKeyId: "key-1",
save: true,
});
assert.equal(host.protocol, "ssh");
assert.equal(host.port, 2202);
assert.equal(host.moshEnabled, true);
assert.equal(host.identityFileId, "key-1");
assert.equal(host.ephemeral, false);
});
test("quick connect never applies an SSH identity to Telnet", () => {
const host = buildQuickConnectHost({
id: "quick-telnet",
createdAt: 1,
target,
protocol: "telnet",
port: 2323,
username: "telnet-user",
authMethod: "password",
password: "telnet-secret",
selectedIdentityId: "stale-ssh-identity",
});
assert.equal(host.identityId, undefined);
assert.equal(host.telnetIdentityId, undefined);
assert.equal(host.username, "telnet-user");
assert.equal(host.password, "telnet-secret");
assert.equal(host.telnetPort, 2323);
});