mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-17 04:01:05 +00:00
test: isolate media network fetches
This commit is contained in:
@@ -3,7 +3,7 @@ import * as ssrf from "../infra/net/ssrf.js";
|
||||
import { normalizeLowercaseStringOrEmpty } from "../shared/string-coerce.js";
|
||||
|
||||
export function mockPinnedHostnameResolution(addresses: string[] = ["93.184.216.34"]) {
|
||||
return vi.spyOn(ssrf, "resolvePinnedHostname").mockImplementation(async (hostname) => {
|
||||
const resolve = async (hostname: string) => {
|
||||
const normalized = normalizeLowercaseStringOrEmpty(hostname).replace(/\.$/, "");
|
||||
const pinnedAddresses = [...addresses];
|
||||
return {
|
||||
@@ -11,5 +11,15 @@ export function mockPinnedHostnameResolution(addresses: string[] = ["93.184.216.
|
||||
addresses: pinnedAddresses,
|
||||
lookup: ssrf.createPinnedLookup({ hostname: normalized, addresses: pinnedAddresses }),
|
||||
};
|
||||
});
|
||||
};
|
||||
const pinned = vi.spyOn(ssrf, "resolvePinnedHostname").mockImplementation(resolve);
|
||||
const pinnedWithPolicy = vi
|
||||
.spyOn(ssrf, "resolvePinnedHostnameWithPolicy")
|
||||
.mockImplementation(async (hostname) => resolve(hostname));
|
||||
return {
|
||||
mockRestore: () => {
|
||||
pinned.mockRestore();
|
||||
pinnedWithPolicy.mockRestore();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user