import { afterEach, beforeEach, vi } from "vitest";
import * as ssrf from "../../infra/net/ssrf.js";
export function resolveRequestUrl(input) {
    if (typeof input === "string") {
        return input;
    }
    if (input instanceof URL) {
        return input.toString();
    }
    return input.url;
}
export function installPinnedHostnameTestHooks() {
    const resolvePinnedHostname = ssrf.resolvePinnedHostname;
    const resolvePinnedHostnameWithPolicy = ssrf.resolvePinnedHostnameWithPolicy;
    const lookupMock = vi.fn();
    let resolvePinnedHostnameSpy = null;
    let resolvePinnedHostnameWithPolicySpy = null;
    beforeEach(() => {
        lookupMock.mockResolvedValue([{ address: "93.184.216.34", family: 4 }]);
        resolvePinnedHostnameSpy = vi
            .spyOn(ssrf, "resolvePinnedHostname")
            .mockImplementation((hostname) => resolvePinnedHostname(hostname, lookupMock));
        resolvePinnedHostnameWithPolicySpy = vi
            .spyOn(ssrf, "resolvePinnedHostnameWithPolicy")
            .mockImplementation((hostname, params) => resolvePinnedHostnameWithPolicy(hostname, { ...params, lookupFn: lookupMock }));
    });
    afterEach(() => {
        lookupMock.mockReset();
        resolvePinnedHostnameSpy?.mockRestore();
        resolvePinnedHostnameWithPolicySpy?.mockRestore();
        resolvePinnedHostnameSpy = null;
        resolvePinnedHostnameWithPolicySpy = null;
    });
}
