Skip to content

Commit e30026a

Browse files
only21milclaude
andcommitted
test(ssh): base the other-user askpass check on the directory owner
The other-user case added one to process.getuid(), which can equal the cached directory's owner when the real and effective UIDs differ. It now adds one to the owner read from stat. The symlink case skips on hosts that cannot create symlinks, using the shared symlinksSupported probe. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 27317d8 commit e30026a

1 file changed

Lines changed: 36 additions & 26 deletions

File tree

‎packages/ssh/src/auth.test.ts‎

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import * as Effect from "effect/Effect";
66
import * as Fiber from "effect/Fiber";
77
import * as FileSystem from "effect/FileSystem";
88
import * as Layer from "effect/Layer";
9+
import * as Option from "effect/Option";
910
import * as Path from "effect/Path";
1011
import * as HostProcess from "@t3tools/shared/HostProcess";
12+
import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
1113

1214
import { buildSshChildEnvironment, isSshAuthFailure } from "./auth.ts";
1315

@@ -71,8 +73,12 @@ describe("ssh auth", () => {
7173
assert.notEqual(recreated, first);
7274
assert.equal(yield* fs.exists(recreated), true);
7375

76+
const cachedOwner = yield* fs.stat(runtimeDirectoryOf(recreated));
7477
const otherUser = yield* askpassPath().pipe(
75-
Effect.provideService(HostProcess.UserId, (process.getuid?.() ?? 0) + 1),
78+
Effect.provideService(
79+
HostProcess.UserId,
80+
(Option.getOrUndefined(cachedOwner.uid) ?? 0) + 1,
81+
),
7682
);
7783
assert.notEqual(otherUser, recreated);
7884

@@ -83,31 +89,35 @@ describe("ssh auth", () => {
8389
),
8490
);
8591

86-
it.effect("does not reuse a symlink left at the default askpass directory path", () =>
87-
Effect.gen(function* () {
88-
const fs = yield* FileSystem.FileSystem;
89-
const path = yield* Path.Path;
90-
const askpassPath = () =>
91-
buildSshChildEnvironment({ interactiveAuth: true, authSecret: "pw" }).pipe(
92-
Effect.map((env) => env.SSH_ASKPASS ?? ""),
93-
);
94-
const runtimeDirectoryOf = (askpass: string) => path.dirname(path.dirname(askpass));
95-
96-
const first = yield* askpassPath();
97-
const ownedTarget = yield* fs.makeTempDirectory({ prefix: "t3code-ssh-symlink-target-" });
98-
yield* fs.remove(runtimeDirectoryOf(first), { recursive: true });
99-
yield* fs.symlink(ownedTarget, runtimeDirectoryOf(first));
100-
101-
const next = yield* askpassPath();
102-
assert.notEqual(next, first);
103-
assert.equal(yield* fs.exists(path.join(ownedTarget, "t3code-ssh-askpass")), false);
104-
105-
yield* fs.remove(runtimeDirectoryOf(first));
106-
yield* fs.remove(ownedTarget, { recursive: true });
107-
yield* fs.remove(runtimeDirectoryOf(next), { recursive: true });
108-
}).pipe(
109-
Effect.provide(Layer.merge(NodeServices.layer, Layer.succeed(HostProcess.Platform, "linux"))),
110-
),
92+
it.effect.skipIf(!symlinksSupported)(
93+
"does not reuse a symlink left at the default askpass directory path",
94+
() =>
95+
Effect.gen(function* () {
96+
const fs = yield* FileSystem.FileSystem;
97+
const path = yield* Path.Path;
98+
const askpassPath = () =>
99+
buildSshChildEnvironment({ interactiveAuth: true, authSecret: "pw" }).pipe(
100+
Effect.map((env) => env.SSH_ASKPASS ?? ""),
101+
);
102+
const runtimeDirectoryOf = (askpass: string) => path.dirname(path.dirname(askpass));
103+
104+
const first = yield* askpassPath();
105+
const ownedTarget = yield* fs.makeTempDirectory({ prefix: "t3code-ssh-symlink-target-" });
106+
yield* fs.remove(runtimeDirectoryOf(first), { recursive: true });
107+
yield* fs.symlink(ownedTarget, runtimeDirectoryOf(first));
108+
109+
const next = yield* askpassPath();
110+
assert.notEqual(next, first);
111+
assert.equal(yield* fs.exists(path.join(ownedTarget, "t3code-ssh-askpass")), false);
112+
113+
yield* fs.remove(runtimeDirectoryOf(first));
114+
yield* fs.remove(ownedTarget, { recursive: true });
115+
yield* fs.remove(runtimeDirectoryOf(next), { recursive: true });
116+
}).pipe(
117+
Effect.provide(
118+
Layer.merge(NodeServices.layer, Layer.succeed(HostProcess.Platform, "linux")),
119+
),
120+
),
111121
);
112122

113123
it.effect("writes the default askpass helper once when interactive commands overlap", () =>

0 commit comments

Comments
 (0)