feat(hosts): manage servers and encrypted SSH credentials in UI (#7)
This commit is contained in:
@@ -3,7 +3,7 @@ import { Server, utils, type Connection } from "ssh2";
|
||||
import type { HostInfo } from "@shellbook/core";
|
||||
import type { ServerConfig } from "../src/config";
|
||||
import { fingerprint } from "../src/ssh";
|
||||
export async function createSshFixture(config: ServerConfig, cleanup: (() => Promise<unknown>)[], authenticate = true) {
|
||||
export async function createSshFixture(config: ServerConfig, cleanup: (() => Promise<unknown>)[], authenticate: boolean | ((ctx: import("ssh2").AuthContext) => void) = true) {
|
||||
const key = generateKeyPairSync("rsa", { modulusLength: 2048 }).privateKey.export({ type: "pkcs1", format: "pem" }).toString();
|
||||
const parsed = utils.parseKey(key);
|
||||
if (parsed instanceof Error) throw parsed;
|
||||
@@ -15,7 +15,7 @@ export async function createSshFixture(config: ServerConfig, cleanup: (() => Pro
|
||||
clients.add(client);
|
||||
client.on("error", () => {});
|
||||
client.on("close", () => clients.delete(client));
|
||||
client.on("authentication", ctx => authenticate ? ctx.accept() : ctx.reject());
|
||||
client.on("authentication", ctx => typeof authenticate === "function" ? authenticate(ctx) : authenticate ? ctx.accept() : ctx.reject());
|
||||
client.on("ready", () => client.on("session", accept => {
|
||||
const session = accept();
|
||||
session.on("exec", (acceptExec, _reject, info) => {
|
||||
|
||||
Reference in New Issue
Block a user