惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
MongoDB | Blog
MongoDB | Blog
GbyAI
GbyAI
L
LangChain Blog
B
Blog
博客园 - 三生石上(FineUI控件)
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
Recent Announcements
Recent Announcements
P
Proofpoint News Feed
U
Unit 42
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
雷峰网
雷峰网
Microsoft Security Blog
Microsoft Security Blog
T
The Blog of Author Tim Ferriss
爱范儿
爱范儿
小众软件
小众软件
I
InfoQ
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
人人都是产品经理
人人都是产品经理
C
Check Point Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
test: tighten gateway tool assertions · openclaw/openclaw...
steipete · 2026-05-10 · via Recent Commits to openclaw:main

@@ -1,4 +1,5 @@

11

import { afterAll, beforeEach, describe, expect, it, vi } from "vitest";

2+

import type { CallGatewayScopedOptions } from "../../gateway/call.js";

23

import { callGatewayTool, resolveGatewayOptions } from "./gateway.js";

3445

const mocks = vi.hoisted(() => ({

@@ -15,6 +16,15 @@ vi.mock("../../gateway/call.js", () => ({

1516

callGateway: (...args: unknown[]) => mocks.callGateway(...args),

1617

}));

171819+

function capturedGatewayCall(): CallGatewayScopedOptions {

20+

expect(mocks.callGateway).toHaveBeenCalledTimes(1);

21+

const call = mocks.callGateway.mock.calls[0];

22+

if (!call) {

23+

throw new Error("expected callGateway to be called");

24+

}

25+

return call[0] as CallGatewayScopedOptions;

26+

}

27+1828

describe("gateway tool defaults", () => {

1929

const envSnapshot = {

2030

openclaw: process.env.OPENCLAW_GATEWAY_TOKEN,

@@ -46,14 +56,13 @@ describe("gateway tool defaults", () => {

4656

{ gatewayUrl: "ws://127.0.0.1:18789", gatewayToken: "t", timeoutMs: 5000 },

4757

{},

4858

);

49-

expect(mocks.callGateway).toHaveBeenCalledWith(

50-

expect.objectContaining({

51-

url: "ws://127.0.0.1:18789",

52-

token: "t",

53-

timeoutMs: 5000,

54-

scopes: ["operator.read"],

55-

}),

56-

);

59+

const call = capturedGatewayCall();

60+

expect(call.method).toBe("health");

61+

expect(call.params).toEqual({});

62+

expect(call.url).toBe("ws://127.0.0.1:18789");

63+

expect(call.token).toBe("t");

64+

expect(call.timeoutMs).toBe(5000);

65+

expect(call.scopes).toEqual(["operator.read"]);

5766

});

58675968

it("uses OPENCLAW_GATEWAY_TOKEN for allowlisted local overrides", () => {

@@ -142,23 +151,19 @@ describe("gateway tool defaults", () => {

142151

it("uses least-privilege write scope for write methods", async () => {

143152

mocks.callGateway.mockResolvedValueOnce({ ok: true });

144153

await callGatewayTool("wake", {}, { mode: "now", text: "hi" });

145-

expect(mocks.callGateway).toHaveBeenCalledWith(

146-

expect.objectContaining({

147-

method: "wake",

148-

scopes: ["operator.write"],

149-

}),

150-

);

154+

const call = capturedGatewayCall();

155+

expect(call.method).toBe("wake");

156+

expect(call.params).toEqual({ mode: "now", text: "hi" });

157+

expect(call.scopes).toEqual(["operator.write"]);

151158

});

152159153160

it("uses admin scope only for admin methods", async () => {

154161

mocks.callGateway.mockResolvedValueOnce({ ok: true });

155162

await callGatewayTool("cron.add", {}, { id: "job-1" });

156-

expect(mocks.callGateway).toHaveBeenCalledWith(

157-

expect.objectContaining({

158-

method: "cron.add",

159-

scopes: ["operator.admin"],

160-

}),

161-

);

163+

const call = capturedGatewayCall();

164+

expect(call.method).toBe("cron.add");

165+

expect(call.params).toEqual({ id: "job-1" });

166+

expect(call.scopes).toEqual(["operator.admin"]);

162167

});

163168164169

it("allows explicit scope overrides for dynamic callers", async () => {

@@ -169,23 +174,19 @@ describe("gateway tool defaults", () => {

169174

{ requestId: "req-1" },

170175

{ scopes: ["operator.admin"] },

171176

);

172-

expect(mocks.callGateway).toHaveBeenCalledWith(

173-

expect.objectContaining({

174-

method: "node.pair.approve",

175-

scopes: ["operator.admin"],

176-

}),

177-

);

177+

const call = capturedGatewayCall();

178+

expect(call.method).toBe("node.pair.approve");

179+

expect(call.params).toEqual({ requestId: "req-1" });

180+

expect(call.scopes).toEqual(["operator.admin"]);

178181

});

179182180183

it("default-denies unknown methods by sending no scopes", async () => {

181184

mocks.callGateway.mockResolvedValueOnce({ ok: true });

182185

await callGatewayTool("nonexistent.method", {}, {});

183-

expect(mocks.callGateway).toHaveBeenCalledWith(

184-

expect.objectContaining({

185-

method: "nonexistent.method",

186-

scopes: [],

187-

}),

188-

);

186+

const call = capturedGatewayCall();

187+

expect(call.method).toBe("nonexistent.method");

188+

expect(call.params).toEqual({});

189+

expect(call.scopes).toEqual([]);

189190

});

190191191192

it("rejects non-allowlisted overrides (SSRF hardening)", async () => {