diff --git a/extensions/slack/src/monitor/media.test.ts b/extensions/slack/src/monitor/media.test.ts index 0cc0df0acd8..91b89a5dd08 100644 --- a/extensions/slack/src/monitor/media.test.ts +++ b/extensions/slack/src/monitor/media.test.ts @@ -178,7 +178,7 @@ describe("fetchWithSlackAuth", () => { describe("resolveSlackMedia", () => { beforeEach(() => { mockFetch = vi.fn(); - globalThis.fetch = withFetchPreconnect(mockFetch); + globalThis.fetch = mockFetch as unknown as typeof fetch; mockPinnedHostnameResolution(); }); @@ -655,16 +655,8 @@ describe("Slack media SSRF policy", () => { describe("resolveSlackAttachmentContent", () => { beforeEach(() => { mockFetch = vi.fn(); - globalThis.fetch = withFetchPreconnect(mockFetch); - vi.spyOn(ssrf, "resolvePinnedHostnameWithPolicy").mockImplementation(async (hostname) => { - const normalized = hostname.trim().toLowerCase().replace(/\.$/, ""); - const addresses = ["93.184.216.34"]; - return { - hostname: normalized, - addresses, - lookup: ssrf.createPinnedLookup({ hostname: normalized, addresses }), - }; - }); + globalThis.fetch = mockFetch as unknown as typeof fetch; + mockPinnedHostnameResolution(); }); afterEach(() => { diff --git a/extensions/slack/src/monitor/media.ts b/extensions/slack/src/monitor/media.ts index 42f287f1883..16e47f4526b 100644 --- a/extensions/slack/src/monitor/media.ts +++ b/extensions/slack/src/monitor/media.ts @@ -122,6 +122,7 @@ export async function fetchWithSlackAuth(url: string, token: string): Promise { + const resolve = async (hostname: string) => { const normalized = normalizeLowercaseStringOrEmpty(hostname).replace(/\.$/, ""); const pinnedAddresses = [...addresses]; return { @@ -11,5 +11,15 @@ export function mockPinnedHostnameResolution(addresses: string[] = ["93.184.216. addresses: pinnedAddresses, lookup: ssrf.createPinnedLookup({ hostname: normalized, addresses: pinnedAddresses }), }; - }); + }; + const pinned = vi.spyOn(ssrf, "resolvePinnedHostname").mockImplementation(resolve); + const pinnedWithPolicy = vi + .spyOn(ssrf, "resolvePinnedHostnameWithPolicy") + .mockImplementation(async (hostname) => resolve(hostname)); + return { + mockRestore: () => { + pinned.mockRestore(); + pinnedWithPolicy.mockRestore(); + }, + }; }