mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-26 10:53:56 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27a6135437 | ||
|
|
883fdaf114 |
No files matched your search
@@ -106,3 +106,69 @@ test("connection test countdown follows the probe timeouts and invalidates the a
|
||||
assert.equal(current().state.status, "disconnected");
|
||||
assert.equal(current().state.error, "Connection timed out. Please try again.");
|
||||
});
|
||||
|
||||
test("connection test seeds the bastion address and tracks the final host label", async (t) => {
|
||||
const actEnvironment = globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean };
|
||||
const previousActEnvironment = actEnvironment.IS_REACT_ACT_ENVIRONMENT;
|
||||
actEnvironment.IS_REACT_ACT_ENVIRONMENT = true;
|
||||
const previousWindowDescriptor = Object.getOwnPropertyDescriptor(globalThis, "window");
|
||||
let listener: Parameters<NonNullable<NetcattyBridge["onChainProgress"]>>[0] = () => {};
|
||||
let sessionId = "";
|
||||
const bridge = {
|
||||
testConnection: (options: { sessionId: string; hostLabel?: string }) => {
|
||||
sessionId = options.sessionId;
|
||||
assert.equal(options.hostLabel, "Prod DB");
|
||||
return new Promise(() => {});
|
||||
},
|
||||
cancelTestConnection: async () => ({ success: true }),
|
||||
onChainProgress: (cb: typeof listener) => { listener = cb; return () => {}; },
|
||||
onHostKeyVerification: () => () => {},
|
||||
};
|
||||
Object.defineProperty(globalThis, "window", {
|
||||
configurable: true, writable: true, value: { netcatty: bridge },
|
||||
});
|
||||
const target: Host = {
|
||||
...targetHost, label: "Prod DB", hostname: "192.168.1.10", hostChain: { hostIds: ["jump-1"] },
|
||||
};
|
||||
const bastion: Host = {
|
||||
...targetHost, id: "jump-1", label: "Bastion", hostname: "bastion.example.com", port: 2222,
|
||||
};
|
||||
let api: HookApi | null = null;
|
||||
let renderer: ReactTestRenderer | null = null;
|
||||
const Probe = () => {
|
||||
api = useHostConnectionTest({ host: target, hosts: [target, bastion], keys: [] });
|
||||
return null;
|
||||
};
|
||||
const current = () => { assert.ok(api); return api; };
|
||||
t.after(async () => {
|
||||
await act(async () => { renderer?.unmount(); });
|
||||
if (previousWindowDescriptor) Object.defineProperty(globalThis, "window", previousWindowDescriptor);
|
||||
else delete (globalThis as { window?: unknown }).window;
|
||||
actEnvironment.IS_REACT_ACT_ENVIRONMENT = previousActEnvironment;
|
||||
});
|
||||
await act(async () => { renderer = create(React.createElement(Probe)); });
|
||||
await act(async () => { void current().startTest(); });
|
||||
const firstHop = {
|
||||
currentHop: 1, totalHops: 2, currentHostLabel: "Bastion",
|
||||
currentHostname: "bastion.example.com", currentPort: 2222, connectionPhase: "connecting",
|
||||
};
|
||||
assert.deepEqual(current().state.chainProgress, firstHop);
|
||||
await act(async () => {
|
||||
listener(sessionId, 1, 2, "Bastion", "connecting", undefined,
|
||||
{ hostname: "bastion.example.com", port: 2222 });
|
||||
});
|
||||
assert.deepEqual(current().state.chainProgress, firstHop);
|
||||
await act(async () => {
|
||||
listener(sessionId, 2, 2, "Prod DB", "connecting", undefined,
|
||||
{ hostname: "192.168.1.10", port: 22 });
|
||||
});
|
||||
assert.deepEqual(current().state.chainProgress, {
|
||||
currentHop: 2, totalHops: 2, currentHostLabel: "Prod DB",
|
||||
currentHostname: "192.168.1.10", currentPort: 22, connectionPhase: "connecting",
|
||||
});
|
||||
assert.ok(current().state.progressLogs.includes("[2/2] Connecting to Prod DB..."));
|
||||
assert.equal(current().state.progressLogs.includes("[2/2] Connecting to 192.168.1.10..."), false);
|
||||
await act(async () => { listener(sessionId, 2, 2, "Prod DB", "authenticating"); });
|
||||
assert.equal(current().state.chainProgress?.currentHostname, undefined);
|
||||
assert.equal(current().state.chainProgress?.currentPort, undefined);
|
||||
});
|
||||
@@ -15,6 +15,8 @@ export type ChainProgress = {
|
||||
currentHop: number;
|
||||
totalHops: number;
|
||||
currentHostLabel: string;
|
||||
currentHostname?: string;
|
||||
currentPort?: number;
|
||||
connectionPhase: string;
|
||||
} | null;
|
||||
|
||||
@@ -117,13 +119,15 @@ export function useHostConnectionTest(input: HostConnectionTestInput) {
|
||||
|
||||
// Subscribe to chain progress for the active attempt.
|
||||
useEffect(() => {
|
||||
const unsub = backend.onChainProgress?.((sessionId, hop, total, label, phase, phaseError) => {
|
||||
const unsub = backend.onChainProgress?.((sessionId, hop, total, label, phase, phaseError, address) => {
|
||||
if (sessionId !== sessionIdRef.current) return;
|
||||
if (total > 1) {
|
||||
setChainProgress({
|
||||
currentHop: hop,
|
||||
totalHops: total,
|
||||
currentHostLabel: label,
|
||||
currentHostname: address?.hostname,
|
||||
currentPort: address?.port,
|
||||
connectionPhase: phase,
|
||||
});
|
||||
}
|
||||
@@ -219,6 +223,18 @@ export function useHostConnectionTest(input: HostConnectionTestInput) {
|
||||
return;
|
||||
}
|
||||
|
||||
const firstJump = plan.options.jumpHosts?.[0];
|
||||
if (firstJump) {
|
||||
setChainProgress({
|
||||
currentHop: 1,
|
||||
totalHops: plan.options.jumpHosts.length + 1,
|
||||
currentHostLabel: firstJump.label || firstJump.hostname,
|
||||
currentHostname: firstJump.hostname,
|
||||
currentPort: firstJump.port || 22,
|
||||
connectionPhase: "connecting",
|
||||
});
|
||||
}
|
||||
|
||||
deadlineMsRef.current = resolveHostConnectionTestDeadlineMs(plan.options);
|
||||
setStatus("connecting");
|
||||
setIsAwaitingUserInput(false);
|
||||
|
||||
@@ -419,7 +419,7 @@ export const useTerminalBackend = () => {
|
||||
return bridge.getTelnetEchoMode(sessionId);
|
||||
}, []);
|
||||
|
||||
const onChainProgress = useCallback((cb: (sessionId: string, hop: number, total: number, label: string, status: string, error?: string) => void) => {
|
||||
const onChainProgress = useCallback((cb: (sessionId: string, hop: number, total: number, label: string, status: string, error?: string, address?: { hostname: string; port?: number }) => void) => {
|
||||
const bridge = netcattyBridge.get();
|
||||
return bridge?.onChainProgress?.(cb);
|
||||
}, []);
|
||||
|
||||
@@ -1020,6 +1020,8 @@ const TerminalComponent: React.FC<TerminalProps> = ({
|
||||
currentHop: number;
|
||||
totalHops: number;
|
||||
currentHostLabel: string;
|
||||
currentHostname?: string;
|
||||
currentPort?: number;
|
||||
connectionPhase: string;
|
||||
} | null>(null);
|
||||
const [isConnectionAwaitingUserInput, setIsConnectionAwaitingUserInput] = useState(false);
|
||||
|
||||
@@ -313,3 +313,41 @@ test("re-auth dialog offers saved password identities from the vault (#3475)", (
|
||||
|
||||
assert.equal(withoutIdentities.includes("Use saved identity"), false);
|
||||
});
|
||||
|
||||
for (const [hop, label, hostname, port] of [
|
||||
[1, "Bastion", "bastion.example.com", 2222],
|
||||
[2, "Prod DB", "192.168.1.10", 22],
|
||||
[1, "IPv6 Bastion", "2001:db8::1", 22],
|
||||
] as const) {
|
||||
test(`chain dialog shows hop ${hop} label and address for ${label}`, () => {
|
||||
const markup = renderDialog({
|
||||
host: { ...host, label: "Prod DB", hostname: "192.168.1.10" },
|
||||
chainProgress: {
|
||||
currentHop: hop,
|
||||
totalHops: 2,
|
||||
currentHostLabel: label,
|
||||
currentHostname: hostname,
|
||||
currentPort: port,
|
||||
},
|
||||
});
|
||||
|
||||
assert.ok(markup.includes(`Chain ${hop} of 2`));
|
||||
assert.ok(markup.includes(label));
|
||||
const address = hostname.includes(":") ? `[${hostname}]:${port}` : `${hostname}:${port}`;
|
||||
assert.ok(markup.includes(`SSH ${address}`));
|
||||
if (hop === 1) assert.equal(markup.includes("SSH 192.168.1.10:22"), false);
|
||||
});
|
||||
}
|
||||
|
||||
test("chain dialog falls back to the target address for legacy progress events", () => {
|
||||
const markup = renderDialog({
|
||||
chainProgress: { currentHop: 1, totalHops: 2, currentHostLabel: "Bastion" },
|
||||
});
|
||||
assert.ok(markup.includes("SSH 10.2.0.32:22"));
|
||||
});
|
||||
|
||||
test("direct dialog keeps the host label and address", () => {
|
||||
const markup = renderDialog({ host: { ...host, label: "Prod DB" } });
|
||||
assert.ok(markup.includes("Prod DB"));
|
||||
assert.ok(markup.includes("SSH 10.2.0.32:22"));
|
||||
});
|
||||
@@ -28,6 +28,8 @@ export interface ChainProgress {
|
||||
currentHop: number;
|
||||
totalHops: number;
|
||||
currentHostLabel: string;
|
||||
currentHostname?: string;
|
||||
currentPort?: number;
|
||||
}
|
||||
|
||||
export interface TerminalConnectionDialogProps {
|
||||
@@ -304,7 +306,7 @@ export const TerminalConnectionDialog: React.FC<TerminalConnectionDialogProps> =
|
||||
className="text-[10px] font-mono truncate"
|
||||
style={{ color: 'color-mix(in srgb, var(--terminal-ui-fg, var(--foreground)) 58%, transparent)' }}
|
||||
>
|
||||
{t(protocolInfo.i18nKey)} {protocolInfo.showPort ? formatHostPort(host.hostname, protocolInfo.port) : host.hostname}
|
||||
{t(protocolInfo.i18nKey)} {protocolInfo.showPort ? formatHostPort(chainProgress.currentHostname || host.hostname, chainProgress.currentPort || protocolInfo.port) : (chainProgress.currentHostname || host.hostname)}
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
|
||||
@@ -4394,3 +4394,52 @@ test("startSSH sends local identity file paths with saved passwords for key auth
|
||||
assert.equal(capturedOptions.password, "saved-password");
|
||||
assert.deepEqual(capturedOptions.identityFilePaths, ["/Users/alice/.ssh/id_ed25519"]);
|
||||
});
|
||||
|
||||
test("startSSH seeds the bastion address and tracks per-hop labels and addresses", async () => {
|
||||
const states: unknown[] = [];
|
||||
let logs: string[] = [];
|
||||
let listener: Parameters<NonNullable<NetcattyBridge["onChainProgress"]>>[0] = noop;
|
||||
const ctx = createStarterContext({
|
||||
host: {
|
||||
id: "host-1", label: "Prod DB", hostname: "192.168.1.10", username: "alice",
|
||||
password: "secret", hostChain: { hostIds: ["jump-1"] },
|
||||
},
|
||||
resolvedChainHosts: [{
|
||||
id: "jump-1", label: "Bastion", hostname: "bastion.example.com", port: 2222,
|
||||
username: "alice", password: "secret",
|
||||
}],
|
||||
terminalBackend: createMockTerminalBackend({
|
||||
onChainProgress: (cb: typeof listener) => { listener = cb; return noop; },
|
||||
startSSHSession: async (options: { hostLabel: string }) => {
|
||||
assert.equal(options.hostLabel, "Prod DB");
|
||||
assert.deepEqual(states.at(-1), {
|
||||
currentHop: 1, totalHops: 2, currentHostLabel: "Bastion",
|
||||
currentHostname: "bastion.example.com", currentPort: 2222, connectionPhase: "connecting",
|
||||
});
|
||||
listener("session-1", 1, 2, "Bastion", "connecting", undefined,
|
||||
{ hostname: "bastion.example.com", port: 2222 });
|
||||
listener("session-1", 2, 2, "Prod DB", "connecting", undefined,
|
||||
{ hostname: "192.168.1.10", port: 22 });
|
||||
return "ssh-session";
|
||||
},
|
||||
}),
|
||||
setChainProgress: (state: unknown) => { states.push(state); },
|
||||
setProgressLogs: (update: string[] | ((prev: string[]) => string[])) => {
|
||||
logs = typeof update === "function" ? update(logs) : update;
|
||||
},
|
||||
});
|
||||
|
||||
await createTerminalSessionStarters(ctx as never).startSSH(createTermStub() as never);
|
||||
|
||||
const hopStates = states.filter((state) => state !== null);
|
||||
assert.deepEqual(hopStates[1], {
|
||||
currentHop: 1, totalHops: 2, currentHostLabel: "Bastion",
|
||||
currentHostname: "bastion.example.com", currentPort: 2222, connectionPhase: "connecting",
|
||||
});
|
||||
assert.deepEqual(hopStates[2], {
|
||||
currentHop: 2, totalHops: 2, currentHostLabel: "Prod DB",
|
||||
currentHostname: "192.168.1.10", currentPort: 22, connectionPhase: "connecting",
|
||||
});
|
||||
assert.ok(logs.includes("[2/2] Connecting to Prod DB..."));
|
||||
assert.equal(logs.includes("[2/2] Connecting to 192.168.1.10..."), false);
|
||||
});
|
||||
@@ -642,12 +642,14 @@ export const createTerminalSessionStarters = (ctx: TerminalSessionStartersContex
|
||||
totalHops,
|
||||
currentHostLabel:
|
||||
jumpHosts[0]?.label || jumpHosts[0]?.hostname || ctx.host.hostname,
|
||||
currentHostname: jumpHosts[0]?.hostname,
|
||||
currentPort: jumpHosts[0]?.port || 22,
|
||||
connectionPhase: 'connecting',
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const unsub = ctx.terminalBackend.onChainProgress((sid, hop, total, label, status, error) => {
|
||||
const unsub = ctx.terminalBackend.onChainProgress((sid, hop, total, label, status, error, address) => {
|
||||
// P1: Only process events for this session
|
||||
if (sid !== ctx.sessionId) return;
|
||||
// Disconnect/reconnect can leave two SSH starts sharing this UI
|
||||
@@ -660,6 +662,8 @@ export const createTerminalSessionStarters = (ctx: TerminalSessionStartersContex
|
||||
currentHop: hop,
|
||||
totalHops: total,
|
||||
currentHostLabel: label,
|
||||
currentHostname: address?.hostname,
|
||||
currentPort: address?.port,
|
||||
connectionPhase: status,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ export type TerminalBackendApi = {
|
||||
error?: string;
|
||||
}>;
|
||||
onChainProgress: (
|
||||
cb: (sessionId: string, hop: number, total: number, label: string, status: string, error?: string) => void,
|
||||
cb: (sessionId: string, hop: number, total: number, label: string, status: string, error?: string, address?: { hostname: string; port?: number }) => void,
|
||||
) => (() => void) | undefined;
|
||||
onConnectionReuseFallback?: (
|
||||
cb: (sessionId: string, sourceSessionId?: string) => void,
|
||||
@@ -126,6 +126,8 @@ type ChainProgressState = {
|
||||
currentHop: number;
|
||||
totalHops: number;
|
||||
currentHostLabel: string;
|
||||
currentHostname?: string;
|
||||
currentPort?: number;
|
||||
connectionPhase: string;
|
||||
} | null;
|
||||
|
||||
|
||||
@@ -376,7 +376,12 @@ async function connectThroughChain(event, options, jumpHosts, targetHost, target
|
||||
|
||||
const sendProgress = (hop, total, label, status, error) => {
|
||||
if (!sender.isDestroyed()) {
|
||||
sender.send("netcatty:chain:progress", { sessionId, hop, total, label, status, error });
|
||||
const jump = jumpHosts[hop - 1];
|
||||
sender.send("netcatty:chain:progress", {
|
||||
sessionId, hop, total, label, status, error,
|
||||
hostname: jump.hostname,
|
||||
port: jump.port || 22,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -830,6 +830,7 @@ test("Copy Tab reuses the source connection instead of dialing fresh", async (t)
|
||||
{
|
||||
sessionId: "copy",
|
||||
hostname: "10.0.0.1",
|
||||
hostLabel: "Prod DB",
|
||||
username: "alice",
|
||||
port: 22,
|
||||
sourceSessionId: "source",
|
||||
@@ -850,6 +851,11 @@ test("Copy Tab reuses the source connection instead of dialing fresh", async (t)
|
||||
// A 'connected' progress event was emitted for the renderer.
|
||||
const progress = sender.sent.filter((m) => m.channel === "netcatty:chain:progress");
|
||||
assert.ok(progress.some((m) => m.payload.status === "connected"));
|
||||
for (const { payload } of progress) {
|
||||
assert.equal(payload.label, "Prod DB");
|
||||
assert.equal(payload.hostname, "10.0.0.1");
|
||||
assert.equal(payload.port, 22);
|
||||
}
|
||||
assert.equal(getConnectionReuseFallbackEvents(sender).length, 0, "successful reuse should not emit fallback");
|
||||
});
|
||||
|
||||
|
||||
@@ -170,6 +170,16 @@ test("jump-host chain connections verify hop host keys against known hosts", asy
|
||||
"session-1",
|
||||
);
|
||||
|
||||
const progress = sender.sent.filter((message) => message.channel === "netcatty:chain:progress");
|
||||
assert.ok(progress.length > 0);
|
||||
for (const { payload } of progress) {
|
||||
assert.equal(payload.label, "Bastion");
|
||||
assert.equal(payload.hostname, "bastion.example.com");
|
||||
assert.equal(payload.port, 22);
|
||||
assert.equal(payload.hop, 1);
|
||||
assert.equal(payload.total, 2);
|
||||
}
|
||||
|
||||
assert.equal(MockSSHClient.instances.length, 1);
|
||||
const connectOpts = MockSSHClient.instances[0].connectOpts;
|
||||
assert.equal(connectOpts.timeout, 45_000);
|
||||
|
||||
@@ -859,7 +859,8 @@ function createStartSessionApi(ctx) {
|
||||
const sendProgress = (status, error) => {
|
||||
if (!sender.isDestroyed()) {
|
||||
sender.send("netcatty:chain:progress", {
|
||||
sessionId, hop: 1, total: 1, label: options.hostname, status, error,
|
||||
sessionId, hop: 1, total: 1, label: options.hostLabel || options.label || options.hostname, status, error,
|
||||
hostname: options.hostname, port: options.port || 22,
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1519,9 +1520,13 @@ function createStartSessionApi(ctx) {
|
||||
const cols = options.cols || 80;
|
||||
const rows = options.rows || 24;
|
||||
|
||||
const targetHostLabel = options.hostLabel || options.label || options.hostname;
|
||||
const sendProgress = (hop, total, label, status, error) => {
|
||||
if (!sender.isDestroyed()) {
|
||||
sender.send("netcatty:chain:progress", { sessionId, hop, total, label, status, error });
|
||||
sender.send("netcatty:chain:progress", {
|
||||
sessionId, hop, total, label, status, error,
|
||||
hostname: options.hostname, port: options.port || 22,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1708,10 +1713,10 @@ function createStartSessionApi(ctx) {
|
||||
bootEpoch: options.bootEpoch,
|
||||
logPrefix: "[SSH]",
|
||||
onPassphrasePromptShown: () => sendProgress(
|
||||
totalHops, totalHops, options.hostname, "auth-attempt", "waiting for user input...",
|
||||
totalHops, totalHops, targetHostLabel, "auth-attempt", "waiting for user input...",
|
||||
),
|
||||
onPassphrasePromptResolved: () => sendProgress(
|
||||
totalHops, totalHops, options.hostname, "auth-attempt", "user responded",
|
||||
totalHops, totalHops, targetHostLabel, "auth-attempt", "user responded",
|
||||
),
|
||||
onLoaded: (loaded) => {
|
||||
log("Loaded identity file", { keyPath: loaded.keyPath, encrypted: !!loaded.passphrase });
|
||||
@@ -1737,10 +1742,10 @@ function createStartSessionApi(ctx) {
|
||||
bootEpoch: options.bootEpoch,
|
||||
logPrefix: "[SSH]",
|
||||
onPassphrasePromptShown: () => sendProgress(
|
||||
totalHops, totalHops, options.hostname, "auth-attempt", "waiting for user input...",
|
||||
totalHops, totalHops, targetHostLabel, "auth-attempt", "waiting for user input...",
|
||||
),
|
||||
onPassphrasePromptResolved: () => sendProgress(
|
||||
totalHops, totalHops, options.hostname, "auth-attempt", "user responded",
|
||||
totalHops, totalHops, targetHostLabel, "auth-attempt", "user responded",
|
||||
),
|
||||
})
|
||||
: null;
|
||||
@@ -2057,7 +2062,7 @@ function createStartSessionApi(ctx) {
|
||||
|
||||
// Log rejection of previous method
|
||||
if (lastTriedMethod && !partialSuccess) {
|
||||
sendProgress(totalHops, totalHops, options.hostname, 'auth-attempt', `${lastTriedMethod} rejected`);
|
||||
sendProgress(totalHops, totalHops, targetHostLabel, 'auth-attempt', `${lastTriedMethod} rejected`);
|
||||
if (
|
||||
lastTriedMethod === "password" &&
|
||||
passwordAttemptSawKeyboardInteractive &&
|
||||
@@ -2081,7 +2086,7 @@ function createStartSessionApi(ctx) {
|
||||
if (methodsLeft === null && !attemptedMethodIds.has("none")) {
|
||||
attemptedMethodIds.add("none");
|
||||
lastTriedMethod = "none";
|
||||
sendProgress(totalHops, totalHops, options.hostname, 'auth-attempt', 'none (no credentials)');
|
||||
sendProgress(totalHops, totalHops, targetHostLabel, 'auth-attempt', 'none (no credentials)');
|
||||
return callback("none");
|
||||
}
|
||||
|
||||
@@ -2218,7 +2223,7 @@ function createStartSessionApi(ctx) {
|
||||
// Only log safe identifier, not the full agent object which may contain private keys
|
||||
const agentType = typeof method.agent === "string" ? "path" : "NetcattyAgent";
|
||||
log("Trying agent auth", { id: method.id, agentType });
|
||||
sendProgress(totalHops, totalHops, options.hostname, 'auth-attempt', 'SSH agent');
|
||||
sendProgress(totalHops, totalHops, targetHostLabel, 'auth-attempt', 'SSH agent');
|
||||
return method.agent === connectOpts.agent
|
||||
? callback("agent")
|
||||
: callback({
|
||||
@@ -2235,7 +2240,7 @@ function createStartSessionApi(ctx) {
|
||||
: method.id === "publickey-user"
|
||||
? "configured key"
|
||||
: method.id;
|
||||
sendProgress(totalHops, totalHops, options.hostname, 'auth-attempt', keyLabel);
|
||||
sendProgress(totalHops, totalHops, targetHostLabel, 'auth-attempt', keyLabel);
|
||||
return callback({
|
||||
type: "publickey",
|
||||
username: connectOpts.username,
|
||||
@@ -2244,7 +2249,7 @@ function createStartSessionApi(ctx) {
|
||||
});
|
||||
} else if (method.type === "password") {
|
||||
log("Trying password auth", { id: method.id });
|
||||
sendProgress(totalHops, totalHops, options.hostname, 'auth-attempt', 'password');
|
||||
sendProgress(totalHops, totalHops, targetHostLabel, 'auth-attempt', 'password');
|
||||
passwordAttemptSawKeyboardInteractive = availableMethods.includes("keyboard-interactive");
|
||||
return callback({
|
||||
type: "password",
|
||||
@@ -2253,7 +2258,7 @@ function createStartSessionApi(ctx) {
|
||||
});
|
||||
} else if (method.type === "keyboard-interactive") {
|
||||
log("Trying keyboard-interactive auth", { id: method.id });
|
||||
sendProgress(totalHops, totalHops, options.hostname, 'auth-attempt', 'keyboard-interactive');
|
||||
sendProgress(totalHops, totalHops, targetHostLabel, 'auth-attempt', 'keyboard-interactive');
|
||||
// Return string instead of object - ssh2 requires a prompt function
|
||||
// for keyboard-interactive objects. Returning the string lets ssh2
|
||||
// use its default handling and trigger the keyboard-interactive event.
|
||||
@@ -2262,7 +2267,7 @@ function createStartSessionApi(ctx) {
|
||||
}
|
||||
|
||||
log("All auth methods exhausted");
|
||||
sendProgress(totalHops, totalHops, options.hostname, 'auth-attempt', 'all methods exhausted');
|
||||
sendProgress(totalHops, totalHops, targetHostLabel, 'auth-attempt', 'all methods exhausted');
|
||||
return callback(false);
|
||||
};
|
||||
|
||||
@@ -2313,9 +2318,9 @@ function createStartSessionApi(ctx) {
|
||||
delete connectOpts.host;
|
||||
delete connectOpts.port;
|
||||
|
||||
sendProgress(totalHops, totalHops, options.hostname, 'connecting');
|
||||
sendProgress(totalHops, totalHops, targetHostLabel, 'connecting');
|
||||
} else if (hasProxy) {
|
||||
sendProgress(1, 1, options.hostname, 'connecting');
|
||||
sendProgress(1, 1, targetHostLabel, 'connecting');
|
||||
connectionSocket = await createProxySocket(
|
||||
options.proxy,
|
||||
options.hostname,
|
||||
@@ -2336,7 +2341,7 @@ function createStartSessionApi(ctx) {
|
||||
}
|
||||
} else {
|
||||
// Direct connection (no jump hosts, no proxy)
|
||||
sendProgress(1, 1, options.hostname, 'connecting');
|
||||
sendProgress(1, 1, targetHostLabel, 'connecting');
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -2391,7 +2396,7 @@ function createStartSessionApi(ctx) {
|
||||
elapsedMs: Date.now() - connectionStartedAt,
|
||||
authReadyTimeoutMs,
|
||||
});
|
||||
sendProgress(totalHops, totalHops, options.hostname, 'tcp-connected');
|
||||
sendProgress(totalHops, totalHops, targetHostLabel, 'tcp-connected');
|
||||
enableSshNoDelay(conn);
|
||||
});
|
||||
});
|
||||
@@ -2405,7 +2410,7 @@ function createStartSessionApi(ctx) {
|
||||
hostname: options.hostname,
|
||||
elapsedMs: Date.now() - connectionStartedAt,
|
||||
});
|
||||
sendProgress(totalHops, totalHops, options.hostname, 'authenticating');
|
||||
sendProgress(totalHops, totalHops, targetHostLabel, 'authenticating');
|
||||
});
|
||||
|
||||
conn.on("banner", (message) => {
|
||||
@@ -2436,7 +2441,7 @@ function createStartSessionApi(ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
sendProgress(totalHops, totalHops, options.hostname, 'authenticated');
|
||||
sendProgress(totalHops, totalHops, targetHostLabel, 'authenticated');
|
||||
|
||||
if (testMode) {
|
||||
// Headless connection test: authentication succeeded. Report the
|
||||
@@ -2462,7 +2467,7 @@ function createStartSessionApi(ctx) {
|
||||
return;
|
||||
}
|
||||
|
||||
sendProgress(totalHops, totalHops, options.hostname, 'shell');
|
||||
sendProgress(totalHops, totalHops, targetHostLabel, 'shell');
|
||||
|
||||
let establishedOwnerSession = null;
|
||||
const sendTerminalMessage = (data) => {
|
||||
@@ -2525,12 +2530,12 @@ function createStartSessionApi(ctx) {
|
||||
if (options.x11Forwarding && /x11/i.test(err.message || "")) {
|
||||
sendTerminalMessage("\r\n[X11] Could not enable X11 forwarding. Make sure X11 forwarding is allowed on the server and xauth is installed.\r\n");
|
||||
}
|
||||
sendProgress(totalHops, totalHops, options.hostname, 'error', `Failed to open shell: ${err.message}`);
|
||||
sendProgress(totalHops, totalHops, targetHostLabel, 'error', `Failed to open shell: ${err.message}`);
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
sendProgress(totalHops, totalHops, options.hostname, 'connected');
|
||||
sendProgress(totalHops, totalHops, targetHostLabel, 'connected');
|
||||
|
||||
// Create the shared reference-counted descriptor for this
|
||||
// connection now that the owning channel is open, then wire the
|
||||
@@ -2667,7 +2672,7 @@ function createStartSessionApi(ctx) {
|
||||
}
|
||||
|
||||
const visibleError = userVisibleSshErrorMessage(err, options);
|
||||
sendProgress(totalHops, totalHops, options.hostname, 'error', visibleError);
|
||||
sendProgress(totalHops, totalHops, targetHostLabel, 'error', visibleError);
|
||||
const suppressPreShellAuthExit = Boolean(options._suppressPreShellAuthExit && isAuthError);
|
||||
if (suppressPreShellAuthExit) {
|
||||
log("suppressing pre-shell auth exit for wrapper-managed retry", {
|
||||
@@ -2712,7 +2717,7 @@ function createStartSessionApi(ctx) {
|
||||
authReadyTimeoutMs,
|
||||
});
|
||||
const contents = event.sender;
|
||||
sendProgress(totalHops, totalHops, options.hostname, 'error', err.message);
|
||||
sendProgress(totalHops, totalHops, targetHostLabel, 'error', err.message);
|
||||
safeSendSessionExit({ safeSend, electronModule, sessions }, contents, sessionId, { sessionId, exitCode: 1, error: err.message, reason: "timeout" });
|
||||
sessionLogStreamManager.stopStream(sessionId, ownerLogStreamToken);
|
||||
sessions.get(sessionId)?.zmodemSentry?.cancel();
|
||||
@@ -2743,7 +2748,7 @@ function createStartSessionApi(ctx) {
|
||||
transportError: ownsCurrentSession ? currentSession?._transportError : undefined,
|
||||
});
|
||||
if (!settled) {
|
||||
sendProgress(totalHops, totalHops, options.hostname, 'error', `Connection to ${options.hostname} closed unexpectedly`);
|
||||
sendProgress(totalHops, totalHops, targetHostLabel, 'error', `Connection to ${options.hostname} closed unexpectedly`);
|
||||
}
|
||||
// This handler owns teardown for the *owner* session only. ssh2
|
||||
// fires conn "close" before the owner's stream "close" on a
|
||||
@@ -2844,14 +2849,14 @@ function createStartSessionApi(ctx) {
|
||||
getAuthBanner: () => authBanner,
|
||||
shouldSkipAutoFill: () => shouldSkipKiPasswordAutoFill(authPhase),
|
||||
onAutoFill: (kind) => sendProgress(
|
||||
totalHops, totalHops, options.hostname, 'auth-attempt',
|
||||
totalHops, totalHops, targetHostLabel, 'auth-attempt',
|
||||
kind === 'totp' ? 'using authenticator code' : 'using saved password',
|
||||
),
|
||||
onPromptShown: () => sendProgress(
|
||||
totalHops, totalHops, options.hostname, 'auth-attempt', 'waiting for user input...',
|
||||
totalHops, totalHops, targetHostLabel, 'auth-attempt', 'waiting for user input...',
|
||||
),
|
||||
onUserResponded: () => sendProgress(
|
||||
totalHops, totalHops, options.hostname, 'auth-attempt', 'user responded',
|
||||
totalHops, totalHops, targetHostLabel, 'auth-attempt', 'user responded',
|
||||
),
|
||||
}));
|
||||
|
||||
|
||||
@@ -400,3 +400,36 @@ test("monitor authentication returns a pooled transport without a shell, termina
|
||||
assert.equal(sent.some(e => e.channel === "netcatty:test:result" || e.channel === "netcatty:exit"), false);
|
||||
require("../sshConnectionPool.cjs").discardTransport(result.transport);
|
||||
});
|
||||
|
||||
for (const [path, extra, expectedLabel] of [
|
||||
["direct", { hostLabel: "Prod DB", label: "Old label" }, "Prod DB"],
|
||||
["direct label fallback", { label: "Prod DB" }, "Prod DB"],
|
||||
["direct hostname fallback", {}, "192.168.1.10"],
|
||||
["proxy", { hostLabel: "Prod DB", proxy: { type: "socks5", host: "proxy.example.com", port: 1080 } }, "Prod DB"],
|
||||
["chain", { hostLabel: "Prod DB", jumpHosts: [{ hostname: "bastion.example.com", label: "Bastion" }] }, "Prod DB"],
|
||||
]) {
|
||||
test(`${path} progress uses the target label and address on every event`, async () => {
|
||||
const { api, sent, sender } = createHarness({
|
||||
onConnect: (conn) => queueMicrotask(() => {
|
||||
conn.emit("connect");
|
||||
conn.emit("handshake");
|
||||
conn.emit("ready");
|
||||
}),
|
||||
chainDial: async () => ({ socket: new EventEmitter(), connections: [] }),
|
||||
ctxOverrides: { createProxySocket: async () => new EventEmitter() },
|
||||
});
|
||||
await api.startSSHSession({ sender }, {
|
||||
...baseOptions(), hostname: "192.168.1.10", port: undefined, ...extra,
|
||||
});
|
||||
const progress = sent.filter(({ channel }) => channel === "netcatty:chain:progress").map(({ payload }) => payload);
|
||||
assert.ok(progress.some(({ status }) => status === "connecting"));
|
||||
assert.ok(progress.some(({ status }) => status === "authenticated"));
|
||||
for (const event of progress) {
|
||||
assert.equal(event.label, expectedLabel);
|
||||
assert.equal(event.hostname, "192.168.1.10");
|
||||
assert.equal(event.port, 22);
|
||||
assert.equal(event.hop, path === "chain" ? 2 : 1);
|
||||
assert.equal(event.total, path === "chain" ? 2 : 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -493,11 +493,11 @@ ipcRenderer.on("netcatty:exit", (_event, payload) => {
|
||||
|
||||
// Chain progress events (for jump host connections)
|
||||
ipcRenderer.on("netcatty:chain:progress", (_event, payload) => {
|
||||
const { sessionId, hop, total, label, status, error } = payload;
|
||||
const { sessionId, hop, total, label, status, error, hostname, port } = payload;
|
||||
// Notify all registered chain progress listeners
|
||||
chainProgressListeners.forEach((cb) => {
|
||||
try {
|
||||
cb(sessionId, hop, total, label, status, error);
|
||||
cb(sessionId, hop, total, label, status, error, hostname ? { hostname, port } : undefined);
|
||||
} catch (err) {
|
||||
console.error("Chain progress callback failed", err);
|
||||
}
|
||||
|
||||
@@ -1969,3 +1969,28 @@ test('real OpenWrt ash hides wrapped input and preserves output with priming (#3
|
||||
client.end();
|
||||
}
|
||||
});
|
||||
|
||||
test("chain progress keeps six callback arguments and adds only the hop address", () => {
|
||||
const preload = loadPreloadWithFakeElectron();
|
||||
try {
|
||||
const received = [];
|
||||
let legacyReceived;
|
||||
preload.api.onChainProgress((...args) => received.push(args));
|
||||
preload.api.onChainProgress((sessionId, hop, total, label, status, error) => {
|
||||
legacyReceived = [sessionId, hop, total, label, status, error];
|
||||
});
|
||||
const payload = {
|
||||
sessionId: "session-1", hop: 1, total: 2, label: "Bastion", status: "connecting",
|
||||
hostname: "bastion.example.com", port: 2222, unrelated: "must not be forwarded",
|
||||
};
|
||||
preload.handlers.get("netcatty:chain:progress")({}, payload);
|
||||
const firstSix = ["session-1", 1, 2, "Bastion", "connecting", undefined];
|
||||
assert.deepEqual(legacyReceived, firstSix);
|
||||
assert.deepEqual(received[0], [...firstSix, { hostname: "bastion.example.com", port: 2222 }]);
|
||||
const { hostname, port, ...legacyPayload } = payload;
|
||||
preload.handlers.get("netcatty:chain:progress")({}, legacyPayload);
|
||||
assert.deepEqual(received[1], [...firstSix, undefined]);
|
||||
} finally {
|
||||
preload.cleanup();
|
||||
}
|
||||
});
|
||||
+3
-3
@@ -1,14 +1,14 @@
|
||||
{
|
||||
version = "1.1.90";
|
||||
version = "1.1.91";
|
||||
|
||||
sources = {
|
||||
x86_64-linux = {
|
||||
appImageArch = "x86_64";
|
||||
hash = "sha256-oa/T3Zey0FHsH+SOt4C1H4CT6aZRJta+x4x/11EAOJE=";
|
||||
hash = "sha256-+JUalTjinzIH2sIovwtwhEP6IaaYPZDgfPoj0rVDOsM=";
|
||||
};
|
||||
aarch64-linux = {
|
||||
appImageArch = "arm64";
|
||||
hash = "sha256-r5hr3+gpIGrv9XJ7PQkHCdhOd2COkhELMHlnr3xIG7A=";
|
||||
hash = "sha256-kDwH7pLgaPoC/4AqoQhlZDo8/dbEL9Il2H+mPlUgu64=";
|
||||
};
|
||||
};
|
||||
}
|
||||
+2
-2
@@ -310,8 +310,8 @@ declare global {
|
||||
onLanguageChanged?(cb: (language: string) => void): () => void;
|
||||
|
||||
// Chain progress listener for jump host connections
|
||||
// Callback receives: (sessionId: string, currentHop: number, totalHops: number, hostLabel: string, status: string, error?: string)
|
||||
onChainProgress?(cb: (sessionId: string, hop: number, total: number, label: string, status: string, error?: string) => void): () => void;
|
||||
// Callback receives: (sessionId: string, currentHop: number, totalHops: number, hostLabel: string, status: string, error?: string, address?: { hostname: string; port?: number })
|
||||
onChainProgress?(cb: (sessionId: string, hop: number, total: number, label: string, status: string, error?: string, address?: { hostname: string; port?: number }) => void): () => void;
|
||||
|
||||
// Fired when a requested SSH connection reuse cannot be honored and the
|
||||
// session falls back to a regular fresh connection.
|
||||
|
||||
Reference in new issue
Block a user