mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-11 17:00:22 +00:00
* feat(ssh): add per-host TOTP with QR scan and MFA auto-fill Store an optional otpauth TOTP secret on the host, encrypt and sync it like a password, and auto-submit it once when a keyboard-interactive prompt matches JumpServer or PAM TOTP text. Closes #3323 Refs #3415 Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * fix(ssh): address Codex TOTP review findings Reset authenticator editor state when the host changes, match custom prompts with RE2, offer keyboard-interactive during connection tests when TOTP is configured, and drop the secret when a host becomes a plugin. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * fix(ssh): fill TOTP from the active prompt and ship re2js Attach the connection's otpauth URI to the keyboard-interactive dialog so Fill current code uses that attempt, including unsaved hosts. Move re2js into production dependencies so packaged builds can match custom prompts. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * fix(ssh): ship the shared TOTP runtime in packaged builds electron-builder allowlists domain CommonJS modules individually, and sshAuthHelper requires domain/totp.shared.cjs at load. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * fix(ssh): save a pasted TOTP secret and ignore stale QR imports Host save waits for the authenticator draft to validate before writing the host. QR import completions from the previous host no longer change busy state or errors on the newly selected host. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * test(host): ignore TOTP copy in the proxy command summary check The assertion was matching the word secret in the authenticator UI. It now checks that the ProxyCommand token itself is not rendered. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * feat(ssh): simplify host TOTP setup and type codes into the terminal Move authenticator setup into a dialog so the host form keeps a single setting row, show keyboard-interactive prompts as field labels, and add a terminal context-menu action that types the current code without Enter. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * fix(ssh): keep TOTP fill inside the auth dialog Remove the terminal context-menu action. Offer the verification-code button on each non-password prompt, highlight OTP prompts, and never write the code into the password field. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * fix(ssh): keep MFA instructions and scan every screen Show keyboard-interactive name and instructions as plain text when they are not already the field label, and scan each unmatched desktop source once instead of repeating the first display. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * fix(ssh): keep multiline MFA prompt directions Show lines before the last keyboard-interactive prompt as plain-text guidance, and keep that last line as the field label. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * fix(ssh): scan TOTP QR codes at each display's full size Request a thumbnail as wide as the widest display and as tall as the tallest, so a portrait screen is not scaled into a landscape frame. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * fix(ssh): keep TOTP fill off menu prompts Judge the fill action from the last prompt line and the shared menu, SMS, and confirmation exclusion list. Use a secondary button on the label row, and simplify the host authenticator row. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>
102 lines
4.7 KiB
TypeScript
102 lines
4.7 KiB
TypeScript
// Created: 2026-07-15
|
|
// Purpose: verify keyboard-interactive modal server prompt formatting.
|
|
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import { createRequire } from "node:module";
|
|
|
|
const require = createRequire(import.meta.url);
|
|
|
|
import {
|
|
keyboardInteractiveFieldLabel,
|
|
keyboardInteractiveGuidance,
|
|
totpFillPlacement,
|
|
visibleTotpFillPlacements,
|
|
} from "./KeyboardInteractiveModal.tsx";
|
|
|
|
const modalSource = readFileSync(new URL("./KeyboardInteractiveModal.tsx", import.meta.url), "utf8");
|
|
|
|
test("keyboardInteractiveFieldLabel uses the cleaned last prompt line", () => {
|
|
assert.equal(keyboardInteractiveFieldLabel("Secondary Authentication Password:", "Verification code"), "Secondary Authentication Password");
|
|
assert.equal(keyboardInteractiveFieldLabel("JumpServer:\n| SMS code:", "Verification code"), "SMS code");
|
|
assert.equal(keyboardInteractiveFieldLabel("[OTP Code]: ", "Verification code"), "OTP Code");
|
|
assert.equal(keyboardInteractiveFieldLabel(" ", "Verification code"), "Verification code");
|
|
});
|
|
|
|
test("keyboard-interactive dialog shows a field label and an inline TOTP action", async () => {
|
|
assert.doesNotMatch(modalSource, /<pre/);
|
|
assert.match(modalSource, /keyboardInteractiveFieldLabel\(/);
|
|
assert.match(modalSource, /keyboardInteractiveGuidance\(/);
|
|
assert.match(modalSource, /data-totp-fill=\{fillPlacement\}/);
|
|
assert.match(modalSource, /variant="secondary"/);
|
|
assert.doesNotMatch(modalSource, /variant=\{fillPlacement/);
|
|
assert.match(modalSource, /totpPrompt\.shared\.mjs/);
|
|
const shared = require("../domain/totpPrompt.shared.cjs") as { NON_TOTP_PROMPT: RegExp };
|
|
const runtime = require("../domain/totp.shared.cjs") as { NON_TOTP_PROMPT: RegExp };
|
|
const esm = await import("../domain/totpPrompt.shared.mjs");
|
|
assert.equal(shared.NON_TOTP_PROMPT, runtime.NON_TOTP_PROMPT);
|
|
assert.equal(esm.NON_TOTP_PROMPT.source, shared.NON_TOTP_PROMPT.source);
|
|
assert.doesNotMatch(modalSource, /ring-primary/);
|
|
assert.doesNotMatch(modalSource, /className="w-full"/);
|
|
assert.doesNotMatch(modalSource, /onTypeTotp/);
|
|
});
|
|
|
|
test("keyboardInteractiveGuidance keeps directions that are not already the field label", () => {
|
|
assert.equal(keyboardInteractiveGuidance({
|
|
name: "bastion",
|
|
hostname: "bastion",
|
|
instructions: "",
|
|
prompts: [{ prompt: "Verification code:", echo: false }],
|
|
}), "");
|
|
assert.equal(keyboardInteractiveGuidance({
|
|
name: "Duo Security",
|
|
hostname: "vpn.example",
|
|
instructions: "1. Duo Push\n2. SMS\nPasscode or option (1-3):",
|
|
prompts: [{ prompt: "Passcode or option (1-3):", echo: true }],
|
|
}), "Duo Security\n1. Duo Push\n2. SMS");
|
|
assert.equal(keyboardInteractiveGuidance({
|
|
name: "host",
|
|
hostname: "other",
|
|
instructions: "| Verification code:",
|
|
prompts: [{ prompt: "Verification code:", echo: false }],
|
|
}), "host");
|
|
assert.equal(keyboardInteractiveGuidance({
|
|
name: "bastion",
|
|
hostname: "bastion",
|
|
instructions: "",
|
|
prompts: [{ prompt: "1. OTP\n2. SMS\nOption> ", echo: true }],
|
|
}), "1. OTP\n2. SMS");
|
|
assert.equal(keyboardInteractiveGuidance({
|
|
name: "bastion",
|
|
hostname: "bastion",
|
|
instructions: "1. OTP",
|
|
prompts: [{ prompt: "1. OTP\nOption>", echo: true }],
|
|
}), "1. OTP");
|
|
});
|
|
|
|
test("TOTP fill stays off password prompts and prefers verification prompts", () => {
|
|
assert.equal(totpFillPlacement({ prompt: "Password:", echo: false }), "hidden");
|
|
assert.equal(totpFillPlacement({ prompt: "Verification code:", echo: false }), "preferred");
|
|
assert.equal(totpFillPlacement({ prompt: "[OTP Code]:", echo: false }), "preferred");
|
|
assert.equal(totpFillPlacement({ prompt: "One-time password:", echo: false }), "preferred");
|
|
assert.equal(totpFillPlacement({ prompt: "SMS code:", echo: false }), "hidden");
|
|
assert.equal(totpFillPlacement({ prompt: "1. OTP\n2. SMS\nOption> ", echo: true }), "hidden");
|
|
assert.equal(totpFillPlacement({ prompt: "[Y/n]", echo: true }), "hidden");
|
|
assert.equal(totpFillPlacement({ prompt: "1. OTP\nVerification code:", echo: false }), "preferred");
|
|
assert.equal(totpFillPlacement({ prompt: "Response:", echo: true }), "available");
|
|
assert.deepEqual(visibleTotpFillPlacements([
|
|
{ prompt: "Password:", echo: false },
|
|
{ prompt: "Verification code:", echo: false },
|
|
]), ["hidden", "preferred"]);
|
|
assert.deepEqual(visibleTotpFillPlacements([
|
|
{ prompt: "Password:", echo: false },
|
|
]), ["hidden"]);
|
|
});
|
|
|
|
test("keyboard-interactive modal cannot be dismissed by outside click or Escape", () => {
|
|
assert.match(modalSource, /onOpenChange=\{\(\) => \{\/\* intentionally non-dismissable \*\/\}\}/);
|
|
assert.match(modalSource, /onInteractOutside=\{\(e\) => e\.preventDefault\(\)\}/);
|
|
assert.match(modalSource, /onEscapeKeyDown=\{\(e\) => e\.preventDefault\(\)\}/);
|
|
});
|