From 52cbb7de33ffd15842f0b7e98e1732042dc3287c Mon Sep 17 00:00:00 2001 From: Shakker Date: Tue, 12 May 2026 19:16:12 +0100 Subject: [PATCH] test: literalize media fetch redaction --- src/media/fetch.test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/media/fetch.test.ts b/src/media/fetch.test.ts index 5c5010d64b8..c580efd641f 100644 --- a/src/media/fetch.test.ts +++ b/src/media/fetch.test.ts @@ -70,7 +70,7 @@ async function expectRemoteMediaMaxBytesError(params: { async function expectRedactedBotTokenFetchError(params: { botFileUrl: string; botToken: string; - redactedBotToken: string; + expectedErrorText: string; fetchImpl: Parameters[0]["fetchImpl"]; }) { const error = await fetchRemoteMedia({ @@ -87,7 +87,7 @@ async function expectRedactedBotTokenFetchError(params: { expect(error).toBeInstanceOf(Error); const errorText = error instanceof Error ? String(error) : ""; expect(errorText).not.toContain(params.botToken); - expect(errorText).toContain(`bot${params.redactedBotToken}`); + expect(errorText).toBe(params.expectedErrorText); } async function expectFetchRemoteMediaRejected(params: { @@ -266,16 +266,18 @@ describe("fetchRemoteMedia", () => { fetchImpl: vi.fn(async () => { throw new Error(`dial failed for ${botFileUrl}`); }), + expectedErrorText: `MediaFetchError: Failed to fetch media from https://files.example.test/file/bot${redactedBotToken}/photos/1.jpg: dial failed for https://files.example.test/file/bot${redactedBotToken}/photos/1.jpg`, }, { name: "redacts bot tokens from HTTP error messages", fetchImpl: vi.fn(async () => new Response("unauthorized", { status: 401 })), + expectedErrorText: `MediaFetchError: Failed to fetch media from https://files.example.test/file/bot${redactedBotToken}/photos/1.jpg: HTTP 401; body: unauthorized`, }, - ] as const)("$name", async ({ fetchImpl }) => { + ] as const)("$name", async ({ fetchImpl, expectedErrorText }) => { await expectRedactedBotTokenFetchError({ botFileUrl, botToken, - redactedBotToken, + expectedErrorText, fetchImpl, }); });