mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-20 12:54:47 +00:00
test: dedupe web guarded fetch mock reads
This commit is contained in:
@@ -25,6 +25,14 @@ vi.mock("../../infra/net/fetch-guard.js", () => {
|
||||
};
|
||||
});
|
||||
|
||||
function firstFetchCall(): Record<string, unknown> {
|
||||
const call = vi.mocked(fetchWithSsrFGuard).mock.calls[0]?.[0];
|
||||
if (!call || typeof call !== "object") {
|
||||
throw new Error("Expected guarded fetch call");
|
||||
}
|
||||
return call as Record<string, unknown>;
|
||||
}
|
||||
|
||||
describe("web-guarded-fetch", () => {
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
@@ -39,7 +47,7 @@ describe("web-guarded-fetch", () => {
|
||||
|
||||
await withTrustedWebToolsEndpoint({ url: "https://example.com" }, async () => undefined);
|
||||
|
||||
const call = vi.mocked(fetchWithSsrFGuard).mock.calls.at(0)?.[0];
|
||||
const call = firstFetchCall();
|
||||
expect(call?.url).toBe("https://example.com");
|
||||
expect(call?.policy).toEqual({
|
||||
allowRfc2544BenchmarkRange: true,
|
||||
@@ -58,11 +66,12 @@ describe("web-guarded-fetch", () => {
|
||||
|
||||
await withSelfHostedWebToolsEndpoint({ url: "http://127.0.0.1:8080" }, async () => undefined);
|
||||
|
||||
const call = vi.mocked(fetchWithSsrFGuard).mock.calls.at(0)?.[0];
|
||||
const call = firstFetchCall();
|
||||
expect(call?.url).toBe("http://127.0.0.1:8080");
|
||||
expect(call?.policy?.dangerouslyAllowPrivateNetwork).toBe(true);
|
||||
expect(call?.policy?.allowRfc2544BenchmarkRange).toBe(true);
|
||||
expect(call?.policy?.allowIpv6UniqueLocalRange).toBe(true);
|
||||
const policy = call.policy as Record<string, unknown> | undefined;
|
||||
expect(policy?.dangerouslyAllowPrivateNetwork).toBe(true);
|
||||
expect(policy?.allowRfc2544BenchmarkRange).toBe(true);
|
||||
expect(policy?.allowIpv6UniqueLocalRange).toBe(true);
|
||||
expect(call?.mode).toBe(GUARDED_FETCH_MODE.TRUSTED_ENV_PROXY);
|
||||
});
|
||||
|
||||
@@ -75,7 +84,7 @@ describe("web-guarded-fetch", () => {
|
||||
|
||||
await withStrictWebToolsEndpoint({ url: "https://example.com" }, async () => undefined);
|
||||
|
||||
const call = vi.mocked(fetchWithSsrFGuard).mock.calls.at(0)?.[0];
|
||||
const call = firstFetchCall();
|
||||
expect(call?.url).toBe("https://example.com");
|
||||
expect(call?.policy).toBeUndefined();
|
||||
expect(call?.mode).toBe(GUARDED_FETCH_MODE.STRICT);
|
||||
|
||||
Reference in New Issue
Block a user