sshFirstConnectionProxy.test.ts 1.0 KB

1234567891011121314151617181920212223242526272829
  1. import { createConnection } from "node:net";
  2. import { describe, expect, it } from "vitest";
  3. import { createFirstConnectionStallingSSHProxy } from "./e2e/helpers/ssh-remote-p0.js";
  4. describe("SSH首连接暂停代理", () => {
  5. it("暂停握手但读取客户端banner,使取消后的FIN能被观测", async () => {
  6. const proxy = await createFirstConnectionStallingSSHProxy(
  7. { host: "127.0.0.1", port: 9 },
  8. "R3_PROXY_FIN",
  9. );
  10. const client = createConnection({ host: "127.0.0.1", port: proxy.port });
  11. let timeout: ReturnType<typeof setTimeout> | undefined;
  12. try {
  13. await proxy.firstConnectionAccepted;
  14. client.end("SSH-2.0-r3-fixture\r\n");
  15. const closed = await Promise.race([
  16. proxy.waitForFirstConnectionClosed().then(() => true),
  17. new Promise<boolean>((resolve) => {
  18. timeout = setTimeout(() => resolve(false), 1000);
  19. }),
  20. ]);
  21. expect(closed).toBe(true);
  22. } finally {
  23. if (timeout) clearTimeout(timeout);
  24. client.destroy();
  25. await proxy.close();
  26. }
  27. });
  28. });