conversation-session-ssh-remote-colon-username.test.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { ServiceChannels } from "@zcode/shared";
  2. import { TID_SSH_PASSWORD_INPUT } from "@zcode/shared/test-ids";
  3. import type { RemoteProjectDirectory } from "@zcode/services";
  4. import {
  5. clearAppData,
  6. setInputValueByTestIdDom,
  7. waitForWorkspaceApp,
  8. } from "#e2e/helpers/desktop-app";
  9. import { prepareV4ConversationE2E } from "#e2e/helpers/v4-conversation";
  10. import { callHandoffHost, installHandoffRpcProbe } from "#e2e/helpers/remote-project-handoff-probe";
  11. import {
  12. clickLastEnabledSSHDialogButton,
  13. fillSSHPasswordSettings,
  14. openSSHRemoteDialog,
  15. openSSHSourceDirectory,
  16. prepareSSHConnectionPage,
  17. readHostProcesses,
  18. readSSHRuntimeConfig,
  19. selectSSHRemoteDirectory,
  20. SSH_WORKSPACE_READY_TIMEOUT_MS,
  21. waitForRemoteTab,
  22. waitForSSHDirectoryStep,
  23. waitForSSHError,
  24. } from "#e2e/helpers/ssh-remote-p0";
  25. const CASE_MARKER = "E2E_SSH_COLON_USERNAME";
  26. describe(`${CASE_MARKER}: SSH 用户名中的冒号`, () => {
  27. after(async () => {
  28. await browser.execute(() => window.__remoteProjectHandoffRpc?.restore());
  29. await browser.electron.restoreAllMocks();
  30. await clearAppData();
  31. });
  32. it("SSH-P0-CONN-09 含冒号用户名认证失败后可重试成功,目录与稳定身份正常", async function () {
  33. this.timeout(20 * 60_000);
  34. const config = readSSHRuntimeConfig(CASE_MARKER);
  35. const username = `${config.username}:tenant`;
  36. await prepareSSHConnectionPage(CASE_MARKER);
  37. await prepareV4ConversationE2E({ skipProvider: true });
  38. await installHandoffRpcProbe();
  39. const initialHosts = await readHostProcesses();
  40. await openSSHRemoteDialog(CASE_MARKER);
  41. await fillSSHPasswordSettings({ ...config, username, password: `${config.password}-invalid` });
  42. await clickLastEnabledSSHDialogButton(CASE_MARKER);
  43. // 缺陷曾在本地身份解析时终止连接;错误密码应到达真实 SSH 认证,并保留可读的失败状态。
  44. const error = await waitForSSHError(CASE_MARKER);
  45. expect(error).toMatch(/authentication|认证/iu);
  46. expect(error).not.toContain("invalid-host-identity");
  47. expect(error).not.toContain(config.password);
  48. const directory = await callHandoffHost<RemoteProjectDirectory>(
  49. ServiceChannels.RemoteProjects,
  50. "readDirectory",
  51. );
  52. const host = directory.hosts.find(
  53. (item) => item.target?.kind === "ssh" && item.target.username === username,
  54. );
  55. expect(host).toMatchObject({
  56. id: `remote:ssh:${config.host}:${config.port}:${username}`,
  57. connectionStatus: "offline",
  58. target: { kind: "ssh", username },
  59. });
  60. expect(host?.lastConnectionError).not.toContain("invalid-host-identity");
  61. expect(await readHostProcesses()).toEqual(initialHosts);
  62. await setInputValueByTestIdDom(TID_SSH_PASSWORD_INPUT, config.password);
  63. await clickLastEnabledSSHDialogButton(CASE_MARKER);
  64. if ((await waitForSSHDirectoryStep(CASE_MARKER)) === "closed") {
  65. await openSSHSourceDirectory({ ...config, username }, CASE_MARKER);
  66. }
  67. await selectSSHRemoteDirectory(config.workspacePaths[0], CASE_MARKER);
  68. await waitForWorkspaceApp(config.workspacePaths[0], SSH_WORKSPACE_READY_TIMEOUT_MS);
  69. const tab = await waitForRemoteTab({
  70. caseMarker: CASE_MARKER,
  71. expectedPath: config.workspacePaths[0],
  72. });
  73. const connected = await callHandoffHost<RemoteProjectDirectory>(
  74. ServiceChannels.RemoteProjects,
  75. "readDirectory",
  76. );
  77. const onlineHost = connected.hosts.find(
  78. (item) => item.target?.kind === "ssh" && item.target.username === username,
  79. );
  80. expect(onlineHost?.id).toMatch(/^remote:server:/u);
  81. expect(onlineHost?.connectionStatus).toBe("online");
  82. expect(connected.hosts.some((item) => item.id === host?.id)).toBe(false);
  83. expect(tab.workspaceIdentity).toBe(`${onlineHost?.id}:${config.workspacePaths[0]}`);
  84. expect(tab.secretPersistedInTab).toBe(false);
  85. expect(await readHostProcesses()).toEqual(initialHosts);
  86. });
  87. });