




















@@ -332,6 +332,42 @@ describe("web session", () => {
332332},
333333);
334334335+it.runIf(process.platform !== "win32")(
336+"rejects symlinked creds before atomic credential saves",
337+async () => {
338+const authDir = createTempAuthDir("openclaw-wa-creds-symlink-save");
339+const targetPath = path.join(authDir, "target-creds.json");
340+const credsPath = path.join(authDir, "creds.json");
341+fsSync.writeFileSync(targetPath, "keep", "utf-8");
342+fsSync.symlinkSync(targetPath, credsPath);
343+344+await expect(
345+writeCredsJsonAtomically(authDir, { me: { id: "15551234567@s.whatsapp.net" } }),
346+).rejects.toThrow("creds.json must be a regular file or missing");
347+348+expect(fsSync.lstatSync(credsPath).isSymbolicLink()).toBe(true);
349+expect(fsSync.readFileSync(targetPath, "utf-8")).toBe("keep");
350+},
351+);
352+353+it.runIf(process.platform !== "win32")(
354+"rejects symlinked credential parents before atomic credential saves",
355+async () => {
356+const rootDir = createTempAuthDir("openclaw-wa-creds-parent-symlink-save");
357+const targetBaseDir = path.join(rootDir, "target-base");
358+const linkedBaseDir = path.join(rootDir, "linked-base");
359+const authDir = path.join(linkedBaseDir, "default");
360+fsSync.mkdirSync(targetBaseDir);
361+fsSync.symlinkSync(targetBaseDir, linkedBaseDir, "dir");
362+363+await expect(
364+writeCredsJsonAtomically(authDir, { me: { id: "15551234567@s.whatsapp.net" } }),
365+).rejects.toThrow("creds.json must be a regular file or missing");
366+367+expect(fsSync.existsSync(path.join(targetBaseDir, "default"))).toBe(false);
368+},
369+);
370+335371it("passes explicit Baileys socket timing overrides", async () => {
336372await createWaSocket(false, false, {
337373keepAliveIntervalMs: 10_000,
@@ -652,6 +688,25 @@ describe("web session", () => {
652688}
653689});
654690691+it.runIf(process.platform !== "win32")(
692+"does not rotate creds backup through a symlinked backup path",
693+async () => {
694+const authDir = createTempAuthDir("openclaw-wa-rotate-backup-symlink");
695+const credsPath = path.join(authDir, "creds.json");
696+const backupPath = path.join(authDir, "creds.json.bak");
697+const targetPath = path.join(authDir, "backup-target.json");
698+fsSync.writeFileSync(credsPath, "{}", "utf-8");
699+fsSync.writeFileSync(targetPath, "keep", "utf-8");
700+fsSync.symlinkSync(targetPath, backupPath);
701+702+await createWaSocket(false, false, { authDir });
703+await emitCredsUpdate(authDir);
704+705+expect(fsSync.lstatSync(backupPath).isSymbolicLink()).toBe(true);
706+expect(fsSync.readFileSync(targetPath, "utf-8")).toBe("keep");
707+},
708+);
709+655710it("writes creds.json atomically via temp file and rename", async () => {
656711const openMock = mockFsOpenForCredsWrites();
657712const renameSpy = vi.spyOn(fs, "rename").mockResolvedValue(undefined);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。