c5d678a37a
Every spec drives the real sshd container set up by the ssh-test-base fixture; no mocks. Specs are grouped by concern (file per group), mirroring the docker/ directory style. Each one maps 1:1 to a row in docs/specs/ssh-executor/e2e-plan.md. UI surface: - connection-form.spec.ts — field rendering, save/test gating, identity-source toggle, default port. - test-result.spec.ts — successful + failed Test Connection paths, per-step badges, fingerprint surfacing, cached/will-upload copy. - trust-gate.spec.ts — save disabled until trust ticked, edits reset result + trust, fingerprint-change warning when pinned != observed. - sessions-card.spec.ts — empty state, row rendering, manual refresh, status badges, truncation, polling pickup. - persistence.spec.ts — fingerprint persists across reload, new form starts blank, executor list label, partial state doesn't leak. API contract: - test-endpoint.spec.ts — POST /api/v1/ssh/test step ordering, invalid body, host-required, handshake short-circuit, cached/uploaded states. - sessions-endpoint.spec.ts — GET /api/v1/ssh/executors/:id/sessions filters to ssh-runtime rows, populates metadata, monotonic uptime. - executor-crud.spec.ts — type=ssh persists fingerprint, profile workdir round-trip, edit-with-running-sessions keeps snapshots. Real-SSH integration: - launch-task.spec.ts — full smoke: agentctl upload + sha256 cache hit on second launch, task/session dir layout, stop cleans session dir. - recovery.spec.ts — backend restart reconnects, dead pid surfaces failure, persisted metadata keys present. - auth-methods.spec.ts — key + valid, missing key, passphrase-protected rejection, agent without SSH_AUTH_SOCK, wrong-key auth failure. - concurrency.spec.ts — two sessions share task dir distinct ports, two tasks distinct dirs, traffic drop + restore exercises eviction + reconnect. - hostkey-rotation.spec.ts — regenerate host key surfaces new fingerprint, stale pinned fingerprint blocks launch verbatim, re-trust restores function. - config-inheritance.spec.ts — ~/.ssh/config HostName / Port / IdentityFile / ProxyJump inheritance with form-overrides-config rules. - workdir-per-profile.spec.ts — per-profile ssh_workdir_root routes to separate remote workdir trees; default falls back to ~/.kandev. - proxy-jump.spec.ts — 2-container bastion topology asserts target is unreachable directly, reachable via ProxyJump, chained ProxyJump fails. - error-surfacing.spec.ts — TCP refused, auth failed, bastion unreachable surface verbatim; backend 400 stays a 400 not a synthesised failure. Also adds an AGENTS.md (CLAUDE.md symlink) line pointing at the e2e/README.md so future agents discover the containers project + KANDEV_E2E_CONTAINERS env var without grepping playwright.config.ts.
104 lines
3.9 KiB
TypeScript
104 lines
3.9 KiB
TypeScript
import { test, expect } from "../../fixtures/ssh-test-base";
|
||
import { execFileSync } from "node:child_process";
|
||
import fs from "node:fs";
|
||
import path from "node:path";
|
||
|
||
/**
|
||
* SSH auth surface area: identity_source = file (with valid + missing +
|
||
* passphrase-protected key files) and identity_source = agent (with and
|
||
* without a running ssh-agent).
|
||
*
|
||
* Covers e2e-plan.md group L (L1–L5).
|
||
*/
|
||
test.describe("ssh auth methods", () => {
|
||
test("identity_source=file with a valid key succeeds", async ({ apiClient, seedData }) => {
|
||
const result = await apiClient.testSSHConnection({
|
||
name: "L1",
|
||
host: seedData.sshTarget.host,
|
||
port: seedData.sshTarget.port,
|
||
user: seedData.sshTarget.user,
|
||
identity_source: "file",
|
||
identity_file: seedData.sshTarget.identityFile,
|
||
});
|
||
expect(result.success).toBe(true);
|
||
expect(result.fingerprint).toBe(seedData.sshTarget.hostFingerprint);
|
||
});
|
||
|
||
test("identity_source=file with a missing key file surfaces a clear error", async ({
|
||
apiClient,
|
||
seedData,
|
||
}) => {
|
||
const result = await apiClient.testSSHConnection({
|
||
name: "L2",
|
||
host: seedData.sshTarget.host,
|
||
port: seedData.sshTarget.port,
|
||
user: seedData.sshTarget.user,
|
||
identity_source: "file",
|
||
identity_file: "/tmp/does-not-exist-i-promise",
|
||
});
|
||
expect(result.success).toBe(false);
|
||
const handshake = result.steps.find((s) => s.name === "SSH handshake");
|
||
expect(handshake?.error).toMatch(/identity file|no such file|read/i);
|
||
});
|
||
|
||
test("identity_source=file with a passphrase-protected key surfaces 'load into ssh-agent'", async ({
|
||
apiClient,
|
||
seedData,
|
||
}) => {
|
||
const keyPath = path.join(seedData.sshTarget.workDir, "passphrase-protected");
|
||
fs.rmSync(keyPath, { force: true });
|
||
fs.rmSync(`${keyPath}.pub`, { force: true });
|
||
execFileSync("ssh-keygen", ["-t", "ed25519", "-f", keyPath, "-N", "hunter2", "-q"]);
|
||
|
||
const result = await apiClient.testSSHConnection({
|
||
name: "L3",
|
||
host: seedData.sshTarget.host,
|
||
port: seedData.sshTarget.port,
|
||
user: seedData.sshTarget.user,
|
||
identity_source: "file",
|
||
identity_file: keyPath,
|
||
});
|
||
expect(result.success).toBe(false);
|
||
const handshake = result.steps.find((s) => s.name === "SSH handshake");
|
||
expect(handshake?.error).toMatch(/passphrase|ssh-agent/i);
|
||
});
|
||
|
||
test("identity_source=agent without SSH_AUTH_SOCK fails with a clear message", async ({
|
||
apiClient,
|
||
seedData,
|
||
}) => {
|
||
// The backend was spawned without SSH_AUTH_SOCK (per backend.ts), so an
|
||
// agent test should fail at handshake time.
|
||
const result = await apiClient.testSSHConnection({
|
||
name: "L5",
|
||
host: seedData.sshTarget.host,
|
||
port: seedData.sshTarget.port,
|
||
user: seedData.sshTarget.user,
|
||
identity_source: "agent",
|
||
});
|
||
expect(result.success).toBe(false);
|
||
const handshake = result.steps.find((s) => s.name === "SSH handshake");
|
||
expect(handshake?.error).toMatch(/ssh-agent|SSH_AUTH_SOCK/i);
|
||
});
|
||
|
||
test("auth failure (wrong key) surfaces verbatim", async ({ apiClient, seedData }) => {
|
||
// Generate a brand-new keypair that isn't in authorized_keys.
|
||
const strangerKey = path.join(seedData.sshTarget.workDir, "stranger");
|
||
fs.rmSync(strangerKey, { force: true });
|
||
fs.rmSync(`${strangerKey}.pub`, { force: true });
|
||
execFileSync("ssh-keygen", ["-t", "ed25519", "-f", strangerKey, "-N", "", "-q"]);
|
||
|
||
const result = await apiClient.testSSHConnection({
|
||
name: "L-auth-fail",
|
||
host: seedData.sshTarget.host,
|
||
port: seedData.sshTarget.port,
|
||
user: seedData.sshTarget.user,
|
||
identity_source: "file",
|
||
identity_file: strangerKey,
|
||
});
|
||
expect(result.success).toBe(false);
|
||
const handshake = result.steps.find((s) => s.name === "SSH handshake");
|
||
expect(handshake?.error).toMatch(/handshake|unable to authenticate|permission denied/i);
|
||
});
|
||
});
|