/** * Shared utilities for allow-list e2e tests * * This module provides: * - Mock fetch implementation with predefined responses * - Environment adapters for Bash and Sandbox * - Test utilities like expectBlocked */ import { vi } from "vitest"; import type { BashOptions } from "../../Bash.js"; import type { DnsLookupResult } from "../types.js"; /** * Deterministic DNS resolver for tests. As of v6.0.0 `denyPrivateRanges` * defaults ON, so any test using a domain hostname would otherwise perform a * real `dns.lookup` (which hangs/varies in offline CI). This stub resolves all * hostnames to a fixed PUBLIC address so allow-list/firewall/redirect tests * stay deterministic and never touch the network. Tests that specifically * exercise the private-range/rebinding policy override `_dnsResolve` with * their own resolver. */ export declare function publicResolver(): (hostname: string) => Promise; export declare const MOCK_SUCCESS_BODY: string; export declare const MOCK_USERS_BODY: string; export declare const MOCK_POSTS_BODY: string; export declare const MOCK_FILE_BODY: string; export declare const MOCK_EVIL_BODY: string; export declare const originalFetch: typeof fetch; export declare function createMockFetch(): ReturnType>; /** * Environment adapter interface for running tests with both Bash and Sandbox */ export interface EnvAdapter { exec(cmd: string): Promise<{ exitCode: number; stdout: string; stderr: string; }>; readFile(path: string): Promise; } /** * Creates an adapter for Bash */ export declare function createBashAdapter(options: BashOptions): EnvAdapter; /** * Creates an adapter for Sandbox */ export declare function createSandboxAdapter(options: BashOptions): Promise; export type AdapterFactory = (options: BashOptions) => EnvAdapter | Promise; /** * Utility for testing that a URL is blocked */ export declare function expectBlocked(env: EnvAdapter, url: string, expectedUrl?: string): Promise; /** * Utility for testing that a URL is blocked due to private IP */ export declare function expectBlockedPrivate(env: EnvAdapter, url: string, expectedUrl?: string): Promise; /** * Utility for testing that a URL is blocked due to DNS-resolved private IP */ export declare function expectBlockedDnsPrivate(env: EnvAdapter, url: string, expectedUrl?: string): Promise; /** * Utility for testing that a URL is blocked due to DNS resolution failure (fail-closed) */ export declare function expectBlockedDnsFailure(env: EnvAdapter, url: string, expectedUrl?: string): Promise; /** * Utility for testing that a URL succeeds with expected mock response */ export declare function expectAllowed(env: EnvAdapter, url: string, expectedBody: string): Promise;