From 1e7d5d620103e6a32883edc75bebea94656e9575 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 12 May 2026 06:15:37 +0100 Subject: [PATCH] test: guard fetch ssrf mock calls --- src/infra/net/fetch-guard.ssrf.test.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/infra/net/fetch-guard.ssrf.test.ts b/src/infra/net/fetch-guard.ssrf.test.ts index 5f07897757c..e571bc8af83 100644 --- a/src/infra/net/fetch-guard.ssrf.test.ts +++ b/src/infra/net/fetch-guard.ssrf.test.ts @@ -98,7 +98,7 @@ function expectDispatcherAttached(value: unknown): void { } function getSecondRequestHeaders(fetchImpl: ReturnType): Headers { - const [, secondInit] = fetchImpl.mock.calls[1] as [string, RequestInit]; + const [, secondInit] = fetchImpl.mock.calls.at(1) as [string, RequestInit]; return new Headers(secondInit.headers); } @@ -119,7 +119,7 @@ function getFirstRequestInit(fetchImpl: ReturnType): RequestInit { } function getSecondRequestInit(fetchImpl: ReturnType): RequestInit { - const [, secondInit] = fetchImpl.mock.calls[1] as [string, RequestInit]; + const [, secondInit] = fetchImpl.mock.calls.at(1) as [string, RequestInit]; return secondInit; } @@ -301,7 +301,7 @@ describe("fetchWithSsrFGuard hardening", () => { ).rejects.toThrow(/private|internal|blocked/i); expect(fetchImpl).not.toHaveBeenCalled(); expect(logWarnMock).toHaveBeenCalledTimes(1); - const [warning] = logWarnMock.mock.calls[0] as [string]; + const [warning] = logWarnMock.mock.calls.at(0) as [string]; expect(warning).toContain( "security: blocked URL fetch (qa-audit) targetOrigin=http://127.0.0.1:8080", ); @@ -602,9 +602,7 @@ describe("fetchWithSsrFGuard hardening", () => { }, }); expect(fetchImpl).toHaveBeenCalledTimes(1); - const fetchCall = fetchImpl.mock.calls[0] as unknown as - | [string, { dispatcher?: unknown }] - | undefined; + const fetchCall = fetchImpl.mock.calls.at(0) as [string, { dispatcher?: unknown }] | undefined; expect(fetchCall?.[0]).toBe("https://public.example/resource"); if (!fetchCall?.[1].dispatcher) { throw new Error("Expected proxy dispatcher");