Skip to content

Commit

Permalink
socket doesnt allow ssh to close on and test never finish
Browse files Browse the repository at this point in the history
  • Loading branch information
dominusmars committed Mar 1, 2024
1 parent b6d8b82 commit 205c17f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tests/ssh.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { detect_hostname, detect_os, ejectSSHkey, makeConnection, removeSSHkey,
import { computers } from "./computers";
import assert from "assert";
import dotenv from "dotenv";
import { Channel } from "ssh2";
dotenv.config();

const defaultPassword = process.env.DEFAULT;
Expand Down Expand Up @@ -133,43 +134,45 @@ for (let computer of computers) {
if (!ssh) {
throw new Error("Unable to connect to target server");
}
let socket = await ssh.shell();
let socket: Channel = await ssh.shell();
let result = await sendCommandExpect(socket, `powershell.exe`, `> `);
assert.ok(result.includes("> "), "Didn't get expected output: " + result);
socket.close();
await ssh.close();
});
it("socketGetOutput", async () => {
let ssh = await makeConnection(user, 3000, 3);
if (!ssh) {
throw new Error("Unable to connect to target server");
}
let socket = await ssh.shell();
let socket: Channel = await ssh.shell();
let result = await socketGetOutput(socket, `powershell.exe`);
assert.ok(result.includes("> "), "Didn't get expected output: " + result);
socket.close();
await ssh.close();
});
it("sendCommandNoExpect", async () => {
let ssh = await makeConnection(user, 3000, 3);
if (!ssh) {
throw new Error("Unable to connect to target server");
}
let socket = await ssh.shell();

let socket: Channel = await ssh.shell();
await assert.doesNotReject(
sendCommandNoExpect(socket, `hostname`, "Pineapples are great"),
"Unable to check for not expect output"
);

socket.close();
await ssh.close();
});
it("sendCommand", async () => {
let ssh = await makeConnection(user, 3000, 3);
if (!ssh) {
throw new Error("Unable to connect to target server");
}
let socket = await ssh.shell();
let socket: Channel = await ssh.shell();
let result = await sendCommand(socket, "echo hello");
assert.ok(result.includes("echo"), "Didn't get expected output: " + result);
socket.close();
await ssh.close();
});
});
Expand Down

0 comments on commit 205c17f

Please sign in to comment.