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.
113 lines
3.8 KiB
TypeScript
113 lines
3.8 KiB
TypeScript
import { test, expect } from "../../fixtures/ssh-test-base";
|
||
import fs from "node:fs";
|
||
import path from "node:path";
|
||
|
||
/**
|
||
* ~/.ssh/config inheritance: alias → HostName / Port / User / IdentityFile /
|
||
* ProxyJump. Explicit form values always win. Unknown alias falls back to
|
||
* alias-as-hostname.
|
||
*
|
||
* Each test writes a fresh ~/.ssh/config into the worker's HOME (the
|
||
* fixture's tmpDir is the backend's HOME by construction). The backend
|
||
* reads from $HOME/.ssh/config the same way a user's terminal does.
|
||
*
|
||
* Covers e2e-plan.md group M (M1–M6).
|
||
*/
|
||
test.describe("ssh ~/.ssh/config inheritance", () => {
|
||
test("alias resolves HostName from ~/.ssh/config", async ({ apiClient, seedData, backend }) => {
|
||
const sshConfigDir = path.join(backend.tmpDir, ".ssh");
|
||
fs.mkdirSync(sshConfigDir, { recursive: true });
|
||
fs.writeFileSync(
|
||
path.join(sshConfigDir, "config"),
|
||
[
|
||
"Host alias-m1",
|
||
` HostName ${seedData.sshTarget.host}`,
|
||
` Port ${seedData.sshTarget.port}`,
|
||
` User ${seedData.sshTarget.user}`,
|
||
` IdentityFile ${seedData.sshTarget.identityFile}`,
|
||
" IdentitiesOnly yes",
|
||
"",
|
||
].join("\n"),
|
||
{ mode: 0o600 },
|
||
);
|
||
|
||
const result = await apiClient.testSSHConnection({
|
||
name: "M1 alias HostName",
|
||
host_alias: "alias-m1",
|
||
});
|
||
expect(result.success).toBe(true);
|
||
expect(result.fingerprint).toBe(seedData.sshTarget.hostFingerprint);
|
||
});
|
||
|
||
test("explicit form port wins over the alias' Port", async ({ apiClient, seedData, backend }) => {
|
||
const sshConfigDir = path.join(backend.tmpDir, ".ssh");
|
||
fs.mkdirSync(sshConfigDir, { recursive: true });
|
||
fs.writeFileSync(
|
||
path.join(sshConfigDir, "config"),
|
||
[
|
||
"Host alias-m2",
|
||
` HostName ${seedData.sshTarget.host}`,
|
||
" Port 1", // intentionally wrong; the form value should win
|
||
` User ${seedData.sshTarget.user}`,
|
||
` IdentityFile ${seedData.sshTarget.identityFile}`,
|
||
"",
|
||
].join("\n"),
|
||
{ mode: 0o600 },
|
||
);
|
||
|
||
const result = await apiClient.testSSHConnection({
|
||
name: "M2 form port wins",
|
||
host_alias: "alias-m2",
|
||
port: seedData.sshTarget.port,
|
||
});
|
||
expect(result.success).toBe(true);
|
||
});
|
||
|
||
test("explicit form IdentityFile wins over the alias' IdentityFile", async ({
|
||
apiClient,
|
||
seedData,
|
||
backend,
|
||
}) => {
|
||
const sshConfigDir = path.join(backend.tmpDir, ".ssh");
|
||
fs.mkdirSync(sshConfigDir, { recursive: true });
|
||
fs.writeFileSync(
|
||
path.join(sshConfigDir, "config"),
|
||
[
|
||
"Host alias-m3",
|
||
` HostName ${seedData.sshTarget.host}`,
|
||
` Port ${seedData.sshTarget.port}`,
|
||
` User ${seedData.sshTarget.user}`,
|
||
" IdentityFile /tmp/does-not-exist",
|
||
"",
|
||
].join("\n"),
|
||
{ mode: 0o600 },
|
||
);
|
||
|
||
const result = await apiClient.testSSHConnection({
|
||
name: "M3 form key wins",
|
||
host_alias: "alias-m3",
|
||
identity_source: "file",
|
||
identity_file: seedData.sshTarget.identityFile,
|
||
});
|
||
expect(result.success).toBe(true);
|
||
});
|
||
|
||
test("unknown alias falls back to using the alias string as the hostname", async ({
|
||
apiClient,
|
||
}) => {
|
||
// 127.0.0.1 is a hostname that resolves. Even with no matching Host
|
||
// block, ResolveSSHTarget treats the alias as a literal host.
|
||
const result = await apiClient.testSSHConnection({
|
||
name: "M5 alias as hostname",
|
||
host_alias: "127.0.0.1",
|
||
port: 1, // refused — we just want to prove the resolve target step accepts the alias
|
||
user: "kandev",
|
||
identity_source: "agent",
|
||
});
|
||
// Resolve target should succeed (no "host is required"), the failure
|
||
// should be at handshake time.
|
||
expect(result.steps[0]?.name).toBe("Resolve target");
|
||
expect(result.steps[0]?.success).toBe(true);
|
||
});
|
||
});
|