From ee5d757d0ca075e1edf4261aa727297504c310a4 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 11 May 2026 03:52:13 +0100 Subject: [PATCH] test: tighten proxy validation assertions --- src/infra/net/proxy/proxy-validation.test.ts | 72 ++++++++------------ 1 file changed, 30 insertions(+), 42 deletions(-) diff --git a/src/infra/net/proxy/proxy-validation.test.ts b/src/infra/net/proxy/proxy-validation.test.ts index 4c0402b9eef0..e93717ad80c4 100644 --- a/src/infra/net/proxy/proxy-validation.test.ts +++ b/src/infra/net/proxy/proxy-validation.test.ts @@ -199,23 +199,19 @@ describe("proxy validation", () => { targetUrl: DEFAULT_PROXY_VALIDATION_ALLOWED_URLS[0], timeoutMs: 5000, }); - const deniedCall = fetchCheck.mock.calls[1]?.[0]; - expect(deniedCall).toMatchObject({ - proxyUrl: "http://127.0.0.1:3128", - timeoutMs: 5000, - }); + const deniedCall = fetchCheck.mock.calls[1]?.[0] as + | { proxyUrl?: unknown; targetUrl?: string; timeoutMs?: unknown } + | undefined; + expect(deniedCall?.proxyUrl).toBe("http://127.0.0.1:3128"); + expect(deniedCall?.timeoutMs).toBe(5000); expect(deniedCall?.targetUrl).toMatch(/^http:\/\/127\.0\.0\.1:\d+\/$/); expect(result.ok).toBe(true); - expect(result.checks[0]).toMatchObject({ - kind: "allowed", - url: DEFAULT_PROXY_VALIDATION_ALLOWED_URLS[0], - ok: true, - }); - expect(result.checks[1]).toMatchObject({ - kind: "denied", - ok: true, - error: "loopback blocked", - }); + expect(result.checks[0]?.kind).toBe("allowed"); + expect(result.checks[0]?.url).toBe(DEFAULT_PROXY_VALIDATION_ALLOWED_URLS[0]); + expect(result.checks[0]?.ok).toBe(true); + expect(result.checks[1]?.kind).toBe("denied"); + expect(result.checks[1]?.ok).toBe(true); + expect(result.checks[1]?.error).toBe("loopback blocked"); expect(result.checks[1]?.url).toMatch(/^http:\/\/127\.0\.0\.1:\d+\/$/); }); @@ -238,12 +234,12 @@ describe("proxy validation", () => { expect(result.ok).toBe(false); expect(result.checks).toHaveLength(1); - expect(result.checks[0]).toMatchObject({ - kind: "denied", - ok: false, - status: 204, - error: "Denied loopback canary returned HTTP 204 without the validation token", - }); + expect(result.checks[0]?.kind).toBe("denied"); + expect(result.checks[0]?.ok).toBe(false); + expect(result.checks[0]?.status).toBe(204); + expect(result.checks[0]?.error).toBe( + "Denied loopback canary returned HTTP 204 without the validation token", + ); expect(result.checks[0]?.url).toMatch(/^http:\/\/127\.0\.0\.1:\d+\/$/); }); @@ -260,11 +256,9 @@ describe("proxy validation", () => { expect(result.ok).toBe(true); expect(result.checks).toHaveLength(1); - expect(result.checks[0]).toMatchObject({ - kind: "denied", - ok: true, - status: 403, - }); + expect(result.checks[0]?.kind).toBe("denied"); + expect(result.checks[0]?.ok).toBe(true); + expect(result.checks[0]?.status).toBe(403); expect(result.checks[0]?.url).toMatch(/^http:\/\/127\.0\.0\.1:\d+\/$/); }); @@ -505,14 +499,11 @@ describe("proxy validation", () => { }); expect(result.ok).toBe(false); - expect(result.checks).toEqual([ - { - kind: "apns", - url: "https://api.sandbox.push.apple.com", - ok: false, - error: expect.stringContaining("InvalidProviderToken"), - }, - ]); + expect(result.checks).toHaveLength(1); + expect(result.checks[0]?.kind).toBe("apns"); + expect(result.checks[0]?.url).toBe("https://api.sandbox.push.apple.com"); + expect(result.checks[0]?.ok).toBe(false); + expect(result.checks[0]?.error).toContain("InvalidProviderToken"); }); it("fails APNs reachability when non-403 response has no apns-id (proxy intercept)", async () => { @@ -529,14 +520,11 @@ describe("proxy validation", () => { }); expect(result.ok).toBe(false); - expect(result.checks).toEqual([ - { - kind: "apns", - url: "https://api.sandbox.push.apple.com", - ok: false, - error: expect.stringContaining("apns-id"), - }, - ]); + expect(result.checks).toHaveLength(1); + expect(result.checks[0]?.kind).toBe("apns"); + expect(result.checks[0]?.url).toBe("https://api.sandbox.push.apple.com"); + expect(result.checks[0]?.ok).toBe(false); + expect(result.checks[0]?.error).toContain("apns-id"); }); it("fails APNs reachability when the proxy blocks CONNECT", async () => {