fix: show why SSH connection tests and runs fail (#7)

Test connection, key installation and runs now tell authentication
failures apart from unreachable hosts (refused, timeout, DNS, ...)
instead of a generic "SSH connection failed".

The web client keeps the server's deliberate error messages (4xx,
502, 503) and shows them in the hosts page; unexpected 500 errors
still show only the status. The reload hint appears only on 409
conflicts.
This commit is contained in:
Florian Schmidt
2026-11-16 10:31:11 +01:00
parent 83e4e3f15e
commit 324ad4b39a
9 changed files with 91 additions and 9 deletions
+19
View File
@@ -454,3 +454,22 @@ it("refuses to write credential secrets inside the git workspace", async () => {
).rejects.toThrow("outside the workspace");
expect(await readdir(dir)).not.toContain("ssh-credentials.key");
});
it("tells wrong credentials apart from unreachable hosts on Test connection", async () => {
const { app, config, store } = await fixture();
const ssh = await createSshFixture(config, cleanup, false);
const { createServer } = await import("node:net");
const closed = createServer();
await new Promise<void>(resolve => closed.listen(0, "127.0.0.1", resolve));
const port = (closed.address() as import("node:net").AddressInfo).port;
await new Promise(resolve => closed.close(resolve));
const offline = { ...ssh.host, name: "offline", port };
await writeFile(path.join(config.workspaceDir, "hosts.yaml"), JSON.stringify([ssh.host, offline]));
await store.set(ssh.host.name, { type: "password", password: "wrong" });
const denied = await app.inject({ method: "POST", url: `/api/host-management/${ssh.host.name}/action`, payload: { action: "test", acceptHostKey: ssh.fp } });
expect(denied.statusCode).toBe(502);
expect(denied.body).toMatch(/authentication failed/i);
expect(denied.body).not.toContain("wrong");
const unreachable = await app.inject({ method: "POST", url: "/api/host-management/offline/action", payload: { action: "test" } });
expect(unreachable.statusCode).toBe(502);
expect(unreachable.body).toMatch(/cannot reach/i);
});
+1 -1
View File
@@ -205,5 +205,5 @@ it("reports SSH authentication failure without raw transport details", async ()
const f = await httpFixture(false);
const result = await run(f, 'authorize');
expect(result.finished.exitCode).toBe(-1);
expect(f.events).toContainEqual({ type: 'run.error', runId: result.id, message: 'SSH authentication failed' });
expect(f.events).toContainEqual({ type: 'run.error', runId: result.id, message: 'SSH authentication failed: check the user and the saved password or key' });
});