
























@@ -57,27 +57,27 @@ async function expectRemoteMediaMaxBytesError(params: {
5757).rejects.toThrow("exceeds maxBytes");
5858}
595960-async function expectRedactedTelegramFetchError(params: {
61-telegramFileUrl: string;
62-telegramToken: string;
63-redactedTelegramToken: string;
60+async function expectRedactedBotTokenFetchError(params: {
61+botFileUrl: string;
62+botToken: string;
63+redactedBotToken: string;
6464fetchImpl: Parameters<typeof fetchRemoteMedia>[0]["fetchImpl"];
6565}) {
6666const error = await fetchRemoteMedia({
67-url: params.telegramFileUrl,
67+url: params.botFileUrl,
6868fetchImpl: params.fetchImpl,
6969lookupFn: makeLookupFn(),
7070maxBytes: 1024,
7171ssrfPolicy: {
72-allowedHostnames: ["api.telegram.org"],
72+allowedHostnames: ["files.example.test"],
7373allowRfc2544BenchmarkRange: true,
7474},
7575}).catch((err: unknown) => err as Error);
76767777expect(error).toBeInstanceOf(Error);
7878const errorText = error instanceof Error ? String(error) : "";
79-expect(errorText).not.toContain(params.telegramToken);
80-expect(errorText).toContain(`bot${params.redactedTelegramToken}`);
79+expect(errorText).not.toContain(params.botToken);
80+expect(errorText).toContain(`bot${params.redactedBotToken}`);
8181}
82828383async function expectFetchRemoteMediaRejected(params: {
@@ -172,9 +172,9 @@ function createFetchRemoteMediaParams(
172172}
173173174174describe("fetchRemoteMedia", () => {
175-const telegramToken = "123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZabcd";
176-const redactedTelegramToken = `${telegramToken.slice(0, 6)}…${telegramToken.slice(-4)}`;
177-const telegramFileUrl = `https://api.telegram.org/file/bot${telegramToken}/photos/1.jpg`;
175+const botToken = "123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZabcd";
176+const redactedBotToken = `${botToken.slice(0, 6)}…${botToken.slice(-4)}`;
177+const botFileUrl = `https://files.example.test/file/bot${botToken}/photos/1.jpg`;
178178179179beforeAll(async () => {
180180({ fetchRemoteMedia } = await import("./fetch.js"));
@@ -225,20 +225,20 @@ describe("fetchRemoteMedia", () => {
225225226226it.each([
227227{
228-name: "redacts Telegram bot tokens from fetch failure messages",
228+name: "redacts bot tokens from fetch failure messages",
229229fetchImpl: vi.fn(async () => {
230-throw new Error(`dial failed for ${telegramFileUrl}`);
230+throw new Error(`dial failed for ${botFileUrl}`);
231231}),
232232},
233233{
234-name: "redacts Telegram bot tokens from HTTP error messages",
234+name: "redacts bot tokens from HTTP error messages",
235235fetchImpl: vi.fn(async () => new Response("unauthorized", { status: 401 })),
236236},
237237] as const)("$name", async ({ fetchImpl }) => {
238-await expectRedactedTelegramFetchError({
239-telegramFileUrl,
240-telegramToken,
241-redactedTelegramToken,
238+await expectRedactedBotTokenFetchError({
239+botFileUrl,
240+botToken,
241+redactedBotToken,
242242 fetchImpl,
243243});
244244});
@@ -295,7 +295,7 @@ describe("fetchRemoteMedia", () => {
295295const fetchImpl = vi.fn(async () => new Response("ok", { status: 200 }));
296296297297await fetchRemoteMedia({
298-url: "https://api.telegram.org/file/bot123/photos/test.jpg",
298+url: "https://files.example.test/file/bot123/photos/test.jpg",
299299 fetchImpl,
300300lookupFn: makeLookupFn(),
301301trustExplicitProxyDns: true,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。