conversation-session-ssh-remote-connection-p0.test.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { buildRemoteWorkspaceIdentity, type RemoteTarget } from "@zcode/shared";
  2. import {
  3. clearAppData,
  4. waitForWorkspaceApp,
  5. } from "../helpers/desktop-app.js";
  6. import { prepareV4ConversationE2E } from "../helpers/v4-conversation.js";
  7. import {
  8. clickLastEnabledSSHDialogButton,
  9. fillSSHPasswordSettings,
  10. openSSHRemoteDialog,
  11. readHostProcesses,
  12. readRemoteTabSnapshot,
  13. readSSHRuntimeConfig,
  14. selectSSHRemoteDirectory,
  15. waitForRemoteTab,
  16. waitForSSHDirectoryStep,
  17. waitForSSHError,
  18. SSH_WORKSPACE_READY_TIMEOUT_MS,
  19. } from "../helpers/ssh-remote-p0.js";
  20. const CASE_MARKER = "SSH_P0_CONNECTION";
  21. describe(`${CASE_MARKER}: SSH password 连接 P0`, () => {
  22. after(async () => {
  23. await browser.electron.restoreAllMocks();
  24. await clearAppData();
  25. });
  26. it("SSH-P0-CONN-02/01 错误密码失败后,以正确密码重试并选择远端目录", async function () {
  27. this.timeout(20 * 60_000);
  28. const config = readSSHRuntimeConfig(CASE_MARKER);
  29. const workspacePath = config.workspacePaths[0];
  30. const target: RemoteTarget = {
  31. kind: "ssh",
  32. host: config.host,
  33. port: config.port,
  34. username: config.username,
  35. };
  36. const identity = buildRemoteWorkspaceIdentity(workspacePath, target);
  37. await prepareV4ConversationE2E({ skipProvider: true });
  38. const initialHosts = await readHostProcesses();
  39. expect(initialHosts).toHaveLength(1);
  40. await openSSHRemoteDialog(CASE_MARKER);
  41. const invalidPassword = `${config.password}-e2e-invalid`;
  42. await fillSSHPasswordSettings({
  43. ...config,
  44. password: invalidPassword,
  45. });
  46. await clickLastEnabledSSHDialogButton(CASE_MARKER);
  47. const errorText = await waitForSSHError(CASE_MARKER);
  48. expect(errorText).not.toContain(config.password);
  49. expect(errorText).not.toContain(invalidPassword);
  50. expect((await readRemoteTabSnapshot(identity)).remoteSessionId).toBeNull();
  51. expect(await readHostProcesses()).toEqual(initialHosts);
  52. await closeSSHDialogAfterFailure();
  53. await openSSHRemoteDialog(CASE_MARKER);
  54. await fillSSHPasswordSettings(config);
  55. await clickLastEnabledSSHDialogButton(CASE_MARKER);
  56. await waitForSSHDirectoryStep(CASE_MARKER);
  57. await selectSSHRemoteDirectory(workspacePath, CASE_MARKER);
  58. await waitForWorkspaceApp(workspacePath, SSH_WORKSPACE_READY_TIMEOUT_MS);
  59. const tab = await waitForRemoteTab({
  60. caseMarker: CASE_MARKER,
  61. expectedIdentity: identity,
  62. expectedPath: workspacePath,
  63. });
  64. expect(tab.remoteKind).toBe("ssh");
  65. expect(tab.remoteHost).toBe(config.host);
  66. expect(tab.secretPersistedInTab).toBe(false);
  67. expect(await readHostProcesses()).toEqual(initialHosts);
  68. });
  69. });
  70. async function closeSSHDialogAfterFailure(): Promise<void> {
  71. await browser.keys("Escape");
  72. await browser.waitUntil(
  73. () =>
  74. browser.execute(
  75. () => !document.querySelector('[data-testid="ssh-dialog"]'),
  76. ),
  77. {
  78. timeout: 15_000,
  79. timeoutMsg: `${CASE_MARKER}: 失败后的 SSH 向导没有关闭`,
  80. },
  81. );
  82. }