11// Browser tests cover cdp.helpers plugin behavior.
22import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime" ;
33import { afterEach , describe , expect , it , vi } from "vitest" ;
4+ import type { LookupFn } from "../infra/net/ssrf.js" ;
45import {
56 assertChromeMcpCdpTransportAllowed ,
67 resolveCdpReachabilityPolicy ,
@@ -13,6 +14,11 @@ const PROFILE_HTTP_REACHABILITY_TIMEOUT_MS = 300;
1314const PROFILE_WS_REACHABILITY_MIN_TIMEOUT_MS = 200 ;
1415const PROFILE_WS_REACHABILITY_MAX_TIMEOUT_MS = 2000 ;
1516
17+ function createLookupFn ( address : string ) : LookupFn {
18+ const family = address . includes ( ":" ) ? 6 : 4 ;
19+ return vi . fn ( async ( ) => [ { address, family } ] ) as unknown as LookupFn ;
20+ }
21+
1622const fetchWithSsrFGuardMock = vi . hoisted ( ( ) => vi . fn ( ) ) ;
1723
1824vi . mock ( "openclaw/plugin-sdk/ssrf-runtime" , async ( importOriginal ) => {
@@ -167,7 +173,7 @@ describe("cdp helpers", () => {
167173 await expect (
168174 resolvePinnedHostnameWithPolicy ( "browser.example" , {
169175 policy : scoped ,
170- lookupFn : async ( ) => [ { address : "10.0.0.8" , family : 4 } ] ,
176+ lookupFn : createLookupFn ( "10.0.0.8" ) ,
171177 } ) ,
172178 ) . rejects . toThrow ( / p r i v a t e \/ i n t e r n a l \/ s p e c i a l - u s e i p a d d r e s s / i) ;
173179 } ) ;
@@ -188,7 +194,7 @@ describe("cdp helpers", () => {
188194 await expect (
189195 resolvePinnedHostnameWithPolicy ( "browser.example" , {
190196 policy : scoped ,
191- lookupFn : async ( ) => [ { address : "10.0.0.8" , family : 4 } ] ,
197+ lookupFn : createLookupFn ( "10.0.0.8" ) ,
192198 } ) ,
193199 ) . resolves . toEqual ( expect . objectContaining ( { addresses : [ "10.0.0.8" ] } ) ) ;
194200 } ) ;
0 commit comments