From 5eb50c704fc3691995a2dc88fb5eec4badc3ab2f Mon Sep 17 00:00:00 2001 From: Cheng Zhou Date: Thu, 3 Sep 2026 17:00:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A1=8C=E9=9D=A2=E5=87=AD?= =?UTF-8?q?=E6=8D=AE=E6=B5=8B=E8=AF=95=E5=AF=B9=E6=9E=84=E5=BB=BA=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E7=9A=84=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为桌面会话测试显式隔离默认服务器地址,避免持续集成环境影响未配置服务器场景的断言。 补充默认服务器地址下的凭据恢复验证,并确认注入默认地址时全部前端测试通过。 --- .../src/runtime/secureSessionStorage.test.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/frontend/src/runtime/secureSessionStorage.test.ts b/frontend/src/runtime/secureSessionStorage.test.ts index f4fb83e4..2521a3a8 100644 --- a/frontend/src/runtime/secureSessionStorage.test.ts +++ b/frontend/src/runtime/secureSessionStorage.test.ts @@ -41,6 +41,7 @@ const createStorage = (): Storage => { describe("secure session storage", () => { beforeEach(() => { + vi.stubEnv("VITE_DESKTOP_SERVER_URL", ""); vi.useFakeTimers(); vi.setSystemTime(new Date("2026-07-02T00:00:00.000Z")); resetSecureSessionStorageForTests(); @@ -53,6 +54,7 @@ describe("secure session storage", () => { }); afterEach(() => { + vi.unstubAllEnvs(); vi.useRealTimers(); resetSecureSessionStorageForTests(); localStorage.clear(); @@ -158,6 +160,25 @@ describe("secure session storage", () => { expect(invokeMock).not.toHaveBeenCalled(); }); + it("restores credentials for the build default when no desktop server override is stored", async () => { + vi.stubEnv("VITE_DESKTOP_SERVER_URL", "https://default.ctms.example.com"); + localStorage.removeItem(DESKTOP_SERVER_URL_KEY); + const token = createJwt(Date.now() + DESKTOP_SESSION_MAX_AGE_MS); + invokeMock.mockResolvedValue(JSON.stringify({ + version: 1, + token, + storedAt: Date.now(), + expiresAt: Date.now() + DESKTOP_SESSION_MAX_AGE_MS, + })); + + await initializeSecureSessionStorage(); + + expect(getSessionToken()).toBe(token); + expect(invokeMock).toHaveBeenCalledExactlyOnceWith("credential_get", { + serverOrigin: "https://default.ctms.example.com/", + }); + }); + it("clears the previous server credential after a desktop server switch", async () => { const previousServerOrigin = "https://old.ctms.example.com/"; const nextServerOrigin = "https://new.ctms.example.com/";