mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-30 07:05:24 +00:00
feat: give ssh transports the host origin and sync id (#1717)
This commit is contained in:
1 parent
d715d097c5
commit
7493c0aa17
9 files changed
+84
-21
No files matched your search
@@ -7,6 +7,7 @@ import { WebSocket, WebSocketServer } from "ws";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
resolveHostById: vi.fn(),
|
||||
resolveHostBySyncId: vi.fn(),
|
||||
openSshTransport: vi.fn(),
|
||||
handler: null as null | ((connection: unknown) => Promise<void>),
|
||||
}));
|
||||
@@ -17,6 +18,7 @@ vi.mock("../../utils/logger.js", () => {
|
||||
});
|
||||
vi.mock("../../hosts/host-resolver.js", () => ({
|
||||
resolveHostById: mocks.resolveHostById,
|
||||
resolveHostBySyncId: mocks.resolveHostBySyncId,
|
||||
}));
|
||||
vi.mock("../../hosts/connect/transport.js", () => ({
|
||||
openSshTransport: mocks.openSshTransport,
|
||||
@@ -114,6 +116,23 @@ describe("ssh relay", () => {
|
||||
await vi.waitFor(() => expect(end).toHaveBeenCalled());
|
||||
});
|
||||
|
||||
it("finds the host by sync id for a linked desktop", async () => {
|
||||
mocks.resolveHostBySyncId.mockResolvedValue({
|
||||
id: 9,
|
||||
ip: "127.0.0.1",
|
||||
port: echoPort,
|
||||
});
|
||||
const { socket } = await open("?syncId=abc");
|
||||
const received = new Promise<string>((resolve) =>
|
||||
socket.once("message", (data) => resolve(data.toString())),
|
||||
);
|
||||
socket.send("ping");
|
||||
expect(await received).toBe("ping");
|
||||
expect(mocks.resolveHostBySyncId).toHaveBeenCalledWith("abc", "user-1");
|
||||
expect(mocks.resolveHostById).not.toHaveBeenCalled();
|
||||
socket.close();
|
||||
});
|
||||
|
||||
it("refuses a host the user can't connect to", async () => {
|
||||
mocks.resolveHostById.mockResolvedValue(null);
|
||||
const { closed } = await open("?hostId=5");
|
||||
|
||||
Reference in new issue
Block a user