mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-16 20:11:08 +00:00
* feat(ssh): opt temporary connections into network device mode Saved hosts and group-backed clones keep their own device type. SSH connections with no saved host, including external launches and quick connect, can start in network device mode when the new Terminal setting is on. The setting stays off unless the user turns it on. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * feat(terminal): quick connect typed addresses from the tab switcher The tab-bar quick switcher now offers the typed address when it already parses as a connection target. Choosing that row opens the existing quick connect wizard, including from a terminal tab where the vault surface is hidden. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * fix(ssh): keep temporary Mosh and ET off network device mode Those transports are stored as SSH plus a flag. Stamping network device mode onto them made raw-host checks skip the copy-session working directory probe. Plain temporary SSH still opts in. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * fix(ssh): read temporary connection settings at connect time VaultView keeps a stale onConnect callback because its memo ignores that prop. Read both temporary-connection toggles from a ref when connecting so turning them on or off applies in the same session. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * fix(terminal): stop word queries from opening quick connect Show the switcher quick-connect row only for address-like input, and place it after matching hosts so Enter still connects to a saved host. Translate the Hosts, Tabs, and New Workspace labels. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * fix(terminal): keep matching tabs ahead of quick connect An address that matches an open session or workspace was still the default Enter target when no saved host matched. Put that row after those tabs so Enter switches to the existing one. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>
214 lines
6.3 KiB
TypeScript
214 lines
6.3 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
prepareConnectionHost,
|
|
temporaryConnectionPrepareOptions,
|
|
} from "./legacyAlgorithms.ts";
|
|
import { normalizeTerminalSettings } from "./models/terminal.ts";
|
|
import type { Host } from "./models.ts";
|
|
import { buildQuickConnectHost } from "./quickConnectHost.ts";
|
|
|
|
const host = (overrides: Partial<Host> = {}): Host => ({
|
|
id: "host-1",
|
|
label: "host",
|
|
hostname: "bastion.example",
|
|
username: "root",
|
|
tags: [],
|
|
os: "linux",
|
|
protocol: "ssh",
|
|
...overrides,
|
|
});
|
|
|
|
test("a saved host keeps its own device type when temporary network device mode is on", () => {
|
|
const saved = host({
|
|
hostname: "10.0.0.8",
|
|
deviceType: "general",
|
|
});
|
|
const unset = host({ hostname: "10.0.0.9" });
|
|
const network = host({ hostname: "10.0.0.10", deviceType: "network" });
|
|
|
|
assert.equal(prepareConnectionHost(saved, {
|
|
temporaryConnectionsNetworkDeviceMode: true,
|
|
}), saved);
|
|
assert.equal(prepareConnectionHost(unset, {
|
|
temporaryConnectionsNetworkDeviceMode: true,
|
|
}), unset);
|
|
assert.equal(prepareConnectionHost(network, {
|
|
temporaryConnectionsNetworkDeviceMode: true,
|
|
}), network);
|
|
});
|
|
|
|
test("an ephemeral clone of a saved host keeps that host's device type", () => {
|
|
const cloned = host({
|
|
id: "ephemeral-from-saved",
|
|
ephemeral: true,
|
|
backedBySavedHost: true,
|
|
hostname: "10.0.0.8",
|
|
deviceType: "general",
|
|
});
|
|
|
|
assert.equal(prepareConnectionHost(cloned, {
|
|
temporaryConnectionsNetworkDeviceMode: true,
|
|
}), cloned);
|
|
assert.equal(prepareConnectionHost(host({
|
|
ephemeral: true,
|
|
backedBySavedHost: true,
|
|
deviceType: "network",
|
|
}), {
|
|
temporaryConnectionsNetworkDeviceMode: false,
|
|
}).deviceType, "network");
|
|
});
|
|
|
|
test("a temporary SSH connection uses network device mode only when the setting is on", () => {
|
|
const temporary = host({
|
|
id: "ephemeral-1",
|
|
ephemeral: true,
|
|
hostname: "10.1.1.1",
|
|
port: 22,
|
|
});
|
|
|
|
assert.equal(prepareConnectionHost(temporary, {
|
|
temporaryConnectionsNetworkDeviceMode: true,
|
|
}).deviceType, "network");
|
|
assert.equal(prepareConnectionHost(temporary, {
|
|
temporaryConnectionsNetworkDeviceMode: false,
|
|
}), temporary);
|
|
assert.equal(prepareConnectionHost(temporary).deviceType, undefined);
|
|
});
|
|
|
|
test("temporary network device mode does not clear an explicit device type when the setting is off", () => {
|
|
const temporary = host({
|
|
ephemeral: true,
|
|
hostname: "10.1.1.1",
|
|
deviceType: "network",
|
|
});
|
|
|
|
assert.equal(prepareConnectionHost(temporary, {
|
|
temporaryConnectionsNetworkDeviceMode: false,
|
|
}), temporary);
|
|
});
|
|
|
|
test("temporary network device mode can be combined with the legacy algorithm opt-in", () => {
|
|
const temporary = host({
|
|
ephemeral: true,
|
|
hostname: "192.0.2.10",
|
|
});
|
|
|
|
const prepared = prepareConnectionHost(temporary, {
|
|
temporaryConnectionsAllowLegacyAlgorithms: true,
|
|
temporaryConnectionsNetworkDeviceMode: true,
|
|
});
|
|
|
|
assert.equal(prepared.legacyAlgorithms, true);
|
|
assert.equal(prepared.deviceType, "network");
|
|
assert.equal(prepared.hostname, "192.0.2.10");
|
|
});
|
|
|
|
test("temporary Mosh and ET connections do not receive network device mode", () => {
|
|
const mosh = host({
|
|
ephemeral: true,
|
|
protocol: "ssh",
|
|
moshEnabled: true,
|
|
hostname: "10.1.1.1",
|
|
});
|
|
const et = host({
|
|
ephemeral: true,
|
|
protocol: "ssh",
|
|
etEnabled: true,
|
|
hostname: "10.1.1.1",
|
|
});
|
|
const options = {
|
|
temporaryConnectionsAllowLegacyAlgorithms: true,
|
|
temporaryConnectionsNetworkDeviceMode: true,
|
|
};
|
|
|
|
assert.equal(prepareConnectionHost(mosh, options).deviceType, undefined);
|
|
assert.equal(prepareConnectionHost(mosh, options).legacyAlgorithms, true);
|
|
assert.equal(prepareConnectionHost(et, options).deviceType, undefined);
|
|
assert.equal(prepareConnectionHost(et, options).legacyAlgorithms, true);
|
|
});
|
|
|
|
test("temporary telnet connections do not receive network device mode", () => {
|
|
const telnet = host({
|
|
ephemeral: true,
|
|
protocol: "telnet",
|
|
hostname: "10.1.1.1",
|
|
});
|
|
|
|
assert.equal(prepareConnectionHost(telnet, {
|
|
temporaryConnectionsNetworkDeviceMode: true,
|
|
}), telnet);
|
|
});
|
|
|
|
test("an unsaved quick connect host receives temporary connection defaults", () => {
|
|
const quickHost = buildQuickConnectHost({
|
|
id: "quick-1",
|
|
createdAt: 1,
|
|
target: { hostname: "10.1.1.1" },
|
|
protocol: "ssh",
|
|
port: 22,
|
|
username: "admin",
|
|
authMethod: "password",
|
|
password: "secret",
|
|
});
|
|
|
|
const prepared = prepareConnectionHost(quickHost, {
|
|
temporaryConnectionsAllowLegacyAlgorithms: true,
|
|
temporaryConnectionsNetworkDeviceMode: true,
|
|
});
|
|
const saved = prepareConnectionHost({ ...quickHost, ephemeral: false }, {
|
|
temporaryConnectionsAllowLegacyAlgorithms: true,
|
|
temporaryConnectionsNetworkDeviceMode: true,
|
|
});
|
|
|
|
assert.equal(prepared.ephemeral, true);
|
|
assert.equal(prepared.legacyAlgorithms, true);
|
|
assert.equal(prepared.deviceType, "network");
|
|
assert.equal(saved.deviceType, undefined);
|
|
assert.equal(saved.legacyAlgorithms, undefined);
|
|
});
|
|
|
|
test("temporary connection toggles are read from the settings object at connect time", () => {
|
|
const settings = {
|
|
temporaryConnectionsAllowLegacyAlgorithms: false,
|
|
temporaryConnectionsNetworkDeviceMode: false,
|
|
};
|
|
const temporary = host({
|
|
id: "ephemeral-live",
|
|
ephemeral: true,
|
|
hostname: "10.9.9.9",
|
|
});
|
|
const connect = () => prepareConnectionHost(
|
|
temporary,
|
|
temporaryConnectionPrepareOptions(settings),
|
|
);
|
|
|
|
assert.equal(connect(), temporary);
|
|
|
|
settings.temporaryConnectionsNetworkDeviceMode = true;
|
|
settings.temporaryConnectionsAllowLegacyAlgorithms = true;
|
|
const enabled = connect();
|
|
assert.equal(enabled.deviceType, "network");
|
|
assert.equal(enabled.legacyAlgorithms, true);
|
|
|
|
settings.temporaryConnectionsNetworkDeviceMode = false;
|
|
settings.temporaryConnectionsAllowLegacyAlgorithms = false;
|
|
assert.equal(connect(), temporary);
|
|
});
|
|
|
|
test("temporary connection network device mode defaults to off", () => {
|
|
assert.equal(normalizeTerminalSettings().temporaryConnectionsNetworkDeviceMode, false);
|
|
assert.equal(
|
|
normalizeTerminalSettings({ temporaryConnectionsNetworkDeviceMode: true })
|
|
.temporaryConnectionsNetworkDeviceMode,
|
|
true,
|
|
);
|
|
assert.equal(
|
|
normalizeTerminalSettings({
|
|
temporaryConnectionsNetworkDeviceMode: "yes" as never,
|
|
}).temporaryConnectionsNetworkDeviceMode,
|
|
false,
|
|
);
|
|
});
|