feat(pi-ssh): support SSH agent authentication

This commit is contained in:
云服务部-叶林立
2026-08-26 20:01:45 +08:00
parent b7758b239e
commit 874d4da096
10 changed files with 98 additions and 22 deletions
+13 -1
View File
@@ -1,7 +1,7 @@
import assert from "node:assert/strict";
import { EventEmitter } from "node:events";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { homedir, tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
import type { Client, ClientChannel, ConnectConfig, SFTPWrapper } from "ssh2";
@@ -235,6 +235,18 @@ test("loads private-key authentication and forwards the passphrase", async () =>
}
});
test("forwards SSH agent authentication through ssh2", async () => {
const host: SshHostConfig = {
...passwordHost(),
auth: { type: "agent", socketPath: "~/.1password/agent.sock" },
};
const { fake, transport } = await connectedTransport(undefined, host);
assert.equal(fake.connectConfig?.agent, join(homedir(), ".1password", "agent.sock"));
assert.equal(fake.connectConfig?.password, undefined);
assert.equal(fake.connectConfig?.privateKey, undefined);
await transport.dispose();
});
test("reads files, checks access modes, detects images, and reuses SFTP", async () => {
const sftp = new FakeSftp();
sftp.files.set("/srv/app/a.txt", Buffer.from("hello"));