Open History to see the last commit
1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { assert, describe, it } from "@effect/vitest";
3
4import * as Effect from "effect/Effect";
5import * as FileSystem from "effect/FileSystem";
6import * as Path from "effect/Path";
7
8import {
9 buildSshAskpassHelperDescriptor,
10 buildSshChildEnvironment,
11 isSshAuthFailure,
12} from "./auth.ts";
13
14describe("ssh auth", () => {
15 it.effect("detects ssh auth failures from common permission denied messages", () =>
16 Effect.sync(() => {
17 assert.equal(
18 isSshAuthFailure(
19 new Error(
20 "julius@100.65.180.100: Permission denied (publickey,password,keyboard-interactive).",
21 ),
22 ),
23 true,
24 );
25 assert.equal(isSshAuthFailure(new Error("Permission denied (publickey).")), true);
26 assert.equal(isSshAuthFailure(new Error("Connection timed out")), false);
27 assert.equal(isSshAuthFailure(new Error("mkdir: Permission denied")), false);
28 }),
29 );
30
31 it.effect("creates askpass env for cached password prompts", () =>
32 Effect.gen(function* () {
33 const fs = yield* FileSystem.FileSystem;
34 const path = yield* Path.Path;
35 const directory = yield* fs.makeTempDirectoryScoped({ prefix: "t3-ssh-askpass-test-" });
36 const env = yield* buildSshChildEnvironment({
37 authSecret: "super-secret",
38 interactiveAuth: true,
39 askpassDirectory: directory,
40 platform: "linux",
41 baseEnv: {},
42 });
43
44 const askpassPath = path.join(directory, "ssh-askpass.sh");
45 assert.equal(env.SSH_ASKPASS, askpassPath);
46 assert.equal(env.SSH_ASKPASS_REQUIRE, "force");
47 assert.equal(env.T3_SSH_AUTH_SECRET, "super-secret");
48 assert.equal(env.DISPLAY, "t3code");
49 assert.equal(yield* fs.exists(askpassPath), true);
50 assert.include(yield* fs.readFileString(askpassPath), 'printf "%s\\n" "$T3_SSH_AUTH_SECRET"');
51 }).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
52 );
53
54 it.effect("builds a windows askpass launcher pair", () =>
55 Effect.gen(function* () {
56 const descriptor = yield* buildSshAskpassHelperDescriptor({
57 directory: "C:\\temp\\t3code-ssh-askpass",
58 platform: "win32",
59 }).pipe(Effect.provide(NodeServices.layer));
60
61 assert.equal(descriptor.launcherPath, "C:\\temp\\t3code-ssh-askpass\\ssh-askpass.cmd");
62 assert.deepEqual(
63 descriptor.files.map((file) => file.path.split("\\").at(-1)),
64 ["ssh-askpass.cmd", "ssh-askpass.ps1"],
65 );
66 }),
67 );
68});