Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion packages/ssh/src/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as Result from "effect/Result";
import * as Sink from "effect/Sink";
import * as Stream from "effect/Stream";
import * as TestClock from "effect/testing/TestClock";
import { ChildProcessSpawner } from "effect/unstable/process";
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";

import {
baseSshArgs,
Expand Down Expand Up @@ -99,6 +99,42 @@ describe("ssh command", () => {
}),
);

it.effect("terminates SSH options before a user-controlled destination", () => {
let spawnedCommand: ChildProcess.Command | null = null;
const spawner = ChildProcessSpawner.make((command) => {
spawnedCommand = command;
return Effect.succeed(makeFailedProcess({ stdout: "", stderr: "Host lookup failed.\n" }));
});
const processLayer = Layer.mergeAll(
NodeServices.layer,
Layer.succeed(ChildProcessSpawner.ChildProcessSpawner, spawner),
);

return Effect.gen(function* () {
yield* runSshCommand(
{
alias: "-oProxyCommand=malicious-command",
hostname: "-oProxyCommand=malicious-command",
username: null,
port: null,
},
{ remoteCommandArgs: ["sh", "-s"] },
).pipe(Effect.flip);

assert.isNotNull(spawnedCommand);
if (spawnedCommand !== null && ChildProcess.isStandardCommand(spawnedCommand)) {
const separatorIndex = spawnedCommand.args.indexOf("--");
assert.isAtLeast(separatorIndex, 0);
assert.deepEqual(spawnedCommand.args.slice(separatorIndex), [
"--",
"-oProxyCommand=malicious-command",
"sh",
"-s",
]);
}
}).pipe(Effect.provide(processLayer));
});

it.effect("resolves the remote t3 package spec from the desktop release channel", () =>
Effect.sync(() => {
assert.equal(
Expand Down
1 change: 1 addition & 0 deletions packages/ssh/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ const runSshCommandInScope = Effect.fn("ssh/command.runSshCommand.inScope")(func
batchMode: input.batchMode ?? (input.interactiveAuth ? "no" : "yes"),
}),
...(input.preHostArgs ?? []),
"--",
hostSpec,
...(input.remoteCommandArgs ?? []),
];
Expand Down
12 changes: 10 additions & 2 deletions packages/ssh/src/tunnel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,11 @@ describe("ssh tunnel scripts", () => {
tunnelKillCount += 1;
});
}
if (args.includes("sh") && args.includes("--")) {
if (
args.some(
(arg, index) => arg === "sh" && args[index + 1] === "-s" && args[index + 2] === "--",
)
) {
return makeSuccessfulProcess('{"remotePort":3773}\n');
}
if (args.includes("sh")) {
Expand Down Expand Up @@ -388,7 +392,11 @@ describe("ssh tunnel scripts", () => {

yield* manager.ensureEnvironment(target);

assert.equal(spawnedCommands.filter((args) => args.includes("-N")).length, 2);
const tunnelCommands = spawnedCommands.filter((args) => args.includes("-N"));
assert.equal(tunnelCommands.length, 2);
for (const args of tunnelCommands) {
assert.deepEqual(args.slice(-2), ["--", "julius@devbox"]);
}
assert.equal(tunnelKillCount, 1);
}).pipe(Effect.provide(layer), Effect.scoped);
});
Expand Down
1 change: 1 addition & 0 deletions packages/ssh/src/tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,7 @@ const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input:
"-N",
"-L",
`${input.localPort}:127.0.0.1:${input.remotePort}`,
"--",
hostSpec,
];
const sshCommand = yield* resolveSshCommand;
Expand Down
Loading