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
136 lines
3.4 KiB
TypeScript
136 lines
3.4 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import { applyGroupDefaults } from "../../domain/groupConfig";
|
|
import { resolveHostAuth } from "../../domain/sshAuth";
|
|
import type { Host, Identity } from "../../types";
|
|
import {
|
|
buildSavedAuthHostUpdate,
|
|
isAuthPasswordProvided,
|
|
} from "./hooks/useTerminalAuthState";
|
|
|
|
const baseHost: Host = {
|
|
id: "host-1",
|
|
label: "Test Host",
|
|
hostname: "example.com",
|
|
port: 22,
|
|
username: "olduser",
|
|
authMethod: "key",
|
|
identityId: "identity-1",
|
|
identityFileId: "key-1",
|
|
tags: [],
|
|
os: "linux",
|
|
};
|
|
|
|
test("isAuthPasswordProvided accepts whitespace-only passwords (#2036)", () => {
|
|
assert.equal(isAuthPasswordProvided(""), false);
|
|
assert.equal(isAuthPasswordProvided(" "), true);
|
|
assert.equal(isAuthPasswordProvided(" "), true);
|
|
assert.equal(isAuthPasswordProvided("secret"), true);
|
|
});
|
|
|
|
test("password save clears identityId and identityFileId", () => {
|
|
const updated = buildSavedAuthHostUpdate(baseHost, {
|
|
authMethod: "password",
|
|
username: "root",
|
|
password: "secret",
|
|
keyId: null,
|
|
});
|
|
|
|
assert.equal(updated.identityId, "");
|
|
assert.equal(updated.identityFileId, undefined);
|
|
assert.equal(updated.password, "secret");
|
|
assert.equal(updated.savePassword, true);
|
|
assert.equal(updated.authMethod, "password");
|
|
assert.equal(updated.username, "root");
|
|
});
|
|
|
|
test("password save preserves a single-space password (#2036)", () => {
|
|
const updated = buildSavedAuthHostUpdate(baseHost, {
|
|
authMethod: "password",
|
|
username: "root",
|
|
password: " ",
|
|
keyId: null,
|
|
});
|
|
|
|
assert.equal(updated.password, " ");
|
|
assert.equal(updated.savePassword, true);
|
|
});
|
|
|
|
test("key save clears identityId and sets identityFileId", () => {
|
|
const updated = buildSavedAuthHostUpdate(baseHost, {
|
|
authMethod: "key",
|
|
username: "deploy",
|
|
password: "",
|
|
keyId: "key-2",
|
|
});
|
|
|
|
assert.equal(updated.identityId, "");
|
|
assert.equal(updated.identityFileId, "key-2");
|
|
assert.equal(updated.password, undefined);
|
|
});
|
|
|
|
test("resolveHostAuth uses saved host credentials after identityId is cleared", () => {
|
|
const identity: Identity = {
|
|
id: "identity-1",
|
|
label: "old",
|
|
username: "olduser",
|
|
authMethod: "password",
|
|
password: "wrong",
|
|
created: 0,
|
|
};
|
|
|
|
const updated = buildSavedAuthHostUpdate(
|
|
{ ...baseHost, identityId: "identity-1" },
|
|
{
|
|
authMethod: "password",
|
|
username: "root",
|
|
password: "correct",
|
|
keyId: null,
|
|
},
|
|
);
|
|
|
|
const resolved = resolveHostAuth({
|
|
host: updated,
|
|
keys: [],
|
|
identities: [identity],
|
|
});
|
|
|
|
assert.equal(resolved.username, "root");
|
|
assert.equal(resolved.password, "correct");
|
|
});
|
|
|
|
test("saved credentials override a group-inherited identity", () => {
|
|
const identity: Identity = {
|
|
id: "identity-1",
|
|
label: "old",
|
|
username: "olduser",
|
|
authMethod: "password",
|
|
password: "wrong",
|
|
created: 0,
|
|
};
|
|
|
|
const updated = buildSavedAuthHostUpdate(
|
|
{ ...baseHost, identityId: undefined },
|
|
{
|
|
authMethod: "password",
|
|
username: "root",
|
|
password: "correct",
|
|
keyId: null,
|
|
},
|
|
);
|
|
|
|
const effective = applyGroupDefaults(updated, { identityId: "identity-1" });
|
|
|
|
assert.equal(effective.identityId, "");
|
|
|
|
const resolved = resolveHostAuth({
|
|
host: effective,
|
|
keys: [],
|
|
identities: [identity],
|
|
});
|
|
|
|
assert.equal(resolved.username, "root");
|
|
assert.equal(resolved.password, "correct");
|
|
});
|