chore: Fix types in tests 33/N.

This commit is contained in:
cpojer
2026-02-17 15:45:36 +09:00
parent f44b58fd58
commit 49bd9f75f4
21 changed files with 148 additions and 42 deletions

View File

@@ -9,6 +9,8 @@ function redirectResponse(location: string): Response {
}
describe("fetchWithSsrFGuard hardening", () => {
type LookupFn = NonNullable<Parameters<typeof fetchWithSsrFGuard>[0]["lookupFn"]>;
it("blocks private IP literal URLs before fetch", async () => {
const fetchImpl = vi.fn();
await expect(
@@ -21,7 +23,9 @@ describe("fetchWithSsrFGuard hardening", () => {
});
it("blocks redirect chains that hop to private hosts", async () => {
const lookupFn = vi.fn(async () => [{ address: "93.184.216.34", family: 4 }]);
const lookupFn = vi.fn(async () => [
{ address: "93.184.216.34", family: 4 },
]) as unknown as LookupFn;
const fetchImpl = vi.fn().mockResolvedValueOnce(redirectResponse("http://127.0.0.1:6379/"));
await expect(
@@ -47,7 +51,9 @@ describe("fetchWithSsrFGuard hardening", () => {
});
it("allows wildcard allowlisted hosts", async () => {
const lookupFn = vi.fn(async () => [{ address: "93.184.216.34", family: 4 }]);
const lookupFn = vi.fn(async () => [
{ address: "93.184.216.34", family: 4 },
]) as unknown as LookupFn;
const fetchImpl = vi.fn(async () => new Response("ok", { status: 200 }));
const result = await fetchWithSsrFGuard({
url: "https://img.assets.example.com/pic.png",