修复桌面凭据测试对构建环境的依赖
为桌面会话测试显式隔离默认服务器地址,避免持续集成环境影响未配置服务器场景的断言。 补充默认服务器地址下的凭据恢复验证,并确认注入默认地址时全部前端测试通过。
This commit is contained in:
@@ -41,6 +41,7 @@ const createStorage = (): Storage => {
|
|||||||
|
|
||||||
describe("secure session storage", () => {
|
describe("secure session storage", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
vi.stubEnv("VITE_DESKTOP_SERVER_URL", "");
|
||||||
vi.useFakeTimers();
|
vi.useFakeTimers();
|
||||||
vi.setSystemTime(new Date("2026-07-02T00:00:00.000Z"));
|
vi.setSystemTime(new Date("2026-07-02T00:00:00.000Z"));
|
||||||
resetSecureSessionStorageForTests();
|
resetSecureSessionStorageForTests();
|
||||||
@@ -53,6 +54,7 @@ describe("secure session storage", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
vi.unstubAllEnvs();
|
||||||
vi.useRealTimers();
|
vi.useRealTimers();
|
||||||
resetSecureSessionStorageForTests();
|
resetSecureSessionStorageForTests();
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
@@ -158,6 +160,25 @@ describe("secure session storage", () => {
|
|||||||
expect(invokeMock).not.toHaveBeenCalled();
|
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 () => {
|
it("clears the previous server credential after a desktop server switch", async () => {
|
||||||
const previousServerOrigin = "https://old.ctms.example.com/";
|
const previousServerOrigin = "https://old.ctms.example.com/";
|
||||||
const nextServerOrigin = "https://new.ctms.example.com/";
|
const nextServerOrigin = "https://new.ctms.example.com/";
|
||||||
|
|||||||
Reference in New Issue
Block a user