mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-17 13:01:24 +00:00
* fix(#3475): automated AI fix * fix: address Codex review on PR #3477 * fix: keep SSH identity picker state accurate * style: keep SSH identity picker source ASCII-only * fix: require usernames for saved SSH identity retries * Keep selected SSH identity for terminal SFTP * Share reauthenticated identity with all terminal SFTP entry points * Pass SFTP identity source setter into layer effects * Use effective identity for preset SFTP panel * fix: keep focused SFTP identity in sync for toggle * fix(terminal): use selected vault identity without exposing password --------- Co-authored-by: netcatty-bot <308658023+netcatty-bot@users.noreply.github.com> Co-authored-by: bincxz <16399091+binaricat@users.noreply.github.com>
59 lines
2.3 KiB
TypeScript
59 lines
2.3 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { listPasswordAuthIdentities, resolvePasswordAuthSftpHost } from "./authIdentityPicker.ts";
|
|
import type { Identity } from "./models.ts";
|
|
import type { Host } from "./models.ts";
|
|
|
|
const passwordIdentity = (overrides: Partial<Identity> = {}): Identity => ({
|
|
id: "id-1",
|
|
label: "Default password",
|
|
username: "root",
|
|
authMethod: "password",
|
|
password: "secret",
|
|
created: 0,
|
|
...overrides,
|
|
});
|
|
|
|
test("keeps only password identities with a usable stored password", () => {
|
|
const identities: Identity[] = [
|
|
passwordIdentity(),
|
|
passwordIdentity({ id: "id-2", label: "Password B", username: "deploy" }),
|
|
passwordIdentity({ id: "id-3", authMethod: "key", keyId: "key-1" }),
|
|
passwordIdentity({ id: "id-4", password: undefined }),
|
|
passwordIdentity({ id: "id-5", password: "" }),
|
|
passwordIdentity({ id: "id-6", password: "enc:v1:djEwdGVzdAAAAAAAAAAAAAAAAA==" }),
|
|
passwordIdentity({ id: "id-7", username: "" }),
|
|
passwordIdentity({ id: "id-8", username: " " }),
|
|
];
|
|
|
|
const result = listPasswordAuthIdentities(identities);
|
|
|
|
assert.deepEqual(
|
|
result.map((identity) => identity.id),
|
|
["id-1", "id-2"],
|
|
);
|
|
});
|
|
|
|
test("tolerates missing identity lists", () => {
|
|
assert.deepEqual(listPasswordAuthIdentities(undefined), []);
|
|
assert.deepEqual(listPasswordAuthIdentities([]), []);
|
|
});
|
|
|
|
test("temporary deploy identity carries into SFTP without changing the saved host", () => {
|
|
const host = { id: "host-1", hostname: "example.test", username: "root", identityId: "root-id" } as Host;
|
|
const identities = [
|
|
passwordIdentity({ id: "root-id", password: "bad-root" }),
|
|
passwordIdentity({ id: "deploy-id", username: "deploy", password: "good-deploy" }),
|
|
];
|
|
const auth = { authMethod: "password", username: "deploy", password: "good-deploy", savedToHost: false };
|
|
assert.deepEqual(resolvePasswordAuthSftpHost(host, identities, auth), {
|
|
...host, username: "deploy", identityId: "deploy-id",
|
|
});
|
|
assert.equal(host.username, "root");
|
|
assert.equal(host.identityId, "root-id");
|
|
assert.equal(resolvePasswordAuthSftpHost(host, identities, { ...auth, password: "manual" }), host);
|
|
assert.equal(resolvePasswordAuthSftpHost(host, identities, { ...auth, savedToHost: true }), host);
|
|
assert.equal(resolvePasswordAuthSftpHost(host, identities, null), host);
|
|
});
|