


































@@ -19,12 +19,12 @@ async function withBlockedLocalAttachmentFallback(
1919run: (params: { cache: MediaAttachmentCache; fallbackUrl: string }) => Promise<void>,
2020) {
2121await withTempDir({ prefix }, async (base) => {
22+const attachmentRoot = path.join(base, "attachment");
2223const allowedRoot = path.join(base, "allowed");
23-const blockedRoot = path.join(base, "blocked");
24-const attachmentPath = path.join(blockedRoot, "voice-note.m4a");
24+const attachmentPath = path.join(attachmentRoot, "voice-note.m4a");
2525const fallbackUrl = "https://example.com/fallback.jpg";
26+await fs.mkdir(attachmentRoot, { recursive: true });
2627await fs.mkdir(allowedRoot, { recursive: true });
27-await fs.mkdir(blockedRoot, { recursive: true });
2828await fs.writeFile(attachmentPath, "ok");
29293030const cache = new MediaAttachmentCache(
@@ -33,20 +33,12 @@ async function withBlockedLocalAttachmentFallback(
3333localPathRoots: [allowedRoot],
3434},
3535);
36-const originalRealpath = fs.realpath.bind(fs);
3736fetchRemoteMediaMock.mockResolvedValue({
3837buffer: Buffer.from("fallback-buffer"),
3938contentType: "image/jpeg",
4039fileName: "fallback.jpg",
4140});
424143-vi.spyOn(fs, "realpath").mockImplementation(async (candidatePath) => {
44-if (String(candidatePath) === attachmentPath) {
45-throw new Error("EACCES");
46-}
47-return await originalRealpath(candidatePath);
48-});
49-5042await run({ cache, fallbackUrl });
5143});
5244}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。