mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 15:47:28 +00:00
test: literalize media fetch redaction
This commit is contained in:
@@ -70,7 +70,7 @@ async function expectRemoteMediaMaxBytesError(params: {
|
||||
async function expectRedactedBotTokenFetchError(params: {
|
||||
botFileUrl: string;
|
||||
botToken: string;
|
||||
redactedBotToken: string;
|
||||
expectedErrorText: string;
|
||||
fetchImpl: Parameters<typeof fetchRemoteMedia>[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,
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user