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

推荐订阅源

H
Help Net Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
Microsoft Azure Blog
Microsoft Azure Blog
Google DeepMind News
Google DeepMind News
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
爱范儿
爱范儿
L
LangChain Blog
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
MongoDB | Blog
MongoDB | Blog
Hugging Face - Blog
Hugging Face - Blog
G
Google Developers Blog
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
宝玉的分享
宝玉的分享
博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net
Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

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
fix(qqbot): authorize approval button callbacks [AI] (#80...
pgondhi987 · 2026-05-12 · via Recent Commits to openclaw:main

@@ -0,0 +1,206 @@

1+

import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";

2+

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

3+

import { registerPlatformAdapter, type PlatformAdapter } from "../adapter/index.js";

4+

import type { InteractionEvent } from "../types.js";

5+

import { createInteractionHandler } from "./interaction-handler.js";

6+

import type { GatewayAccount, GatewayPluginRuntime } from "./types.js";

7+8+

const acknowledgeInteractionMock = vi.hoisted(() => vi.fn(async () => undefined));

9+10+

vi.mock("../messaging/sender.js", () => ({

11+

accountToCreds: (account: GatewayAccount) => ({

12+

appId: account.appId,

13+

clientSecret: account.clientSecret,

14+

}),

15+

acknowledgeInteraction: acknowledgeInteractionMock,

16+

}));

17+18+

const resolveApprovalMock = vi.fn(async () => true);

19+20+

const account: GatewayAccount = {

21+

accountId: "default",

22+

appId: "app",

23+

clientSecret: "secret",

24+

markdownSupport: false,

25+

config: {},

26+

};

27+28+

const runtime = {} as GatewayPluginRuntime;

29+30+

function makeRestrictedCfg(approvers: string[]): OpenClawConfig {

31+

return {

32+

channels: {

33+

qqbot: {

34+

appId: "app",

35+

clientSecret: "secret",

36+

execApprovals: {

37+

enabled: true,

38+

approvers,

39+

},

40+

},

41+

},

42+

} as OpenClawConfig;

43+

}

44+45+

function makeUnrestrictedCfg(): OpenClawConfig {

46+

return {

47+

channels: {

48+

qqbot: {

49+

appId: "app",

50+

clientSecret: "secret",

51+

},

52+

},

53+

} as OpenClawConfig;

54+

}

55+56+

function makeApprovalEvent(overrides: Partial<InteractionEvent> = {}): InteractionEvent {

57+

return {

58+

id: "interaction-1",

59+

type: 11,

60+

chat_type: 1,

61+

group_openid: "group-1",

62+

group_member_openid: "ATTACKER_OPENID",

63+

version: 1,

64+

data: {

65+

type: 11,

66+

resolved: {

67+

button_data: "approve:exec:abc12345:allow-once",

68+

user_id: "ATTACKER_USER_ID",

69+

},

70+

},

71+

...overrides,

72+

};

73+

}

74+75+

function installPlatformAdapter(): void {

76+

registerPlatformAdapter({

77+

validateRemoteUrl: vi.fn(async () => undefined),

78+

resolveSecret: vi.fn(async (value: unknown) => (typeof value === "string" ? value : undefined)),

79+

downloadFile: vi.fn(async () => "/tmp/file"),

80+

fetchMedia: vi.fn(async () => {

81+

throw new Error("unused");

82+

}),

83+

getTempDir: () => "/tmp",

84+

hasConfiguredSecret: (value: unknown) => typeof value === "string" && value.length > 0,

85+

normalizeSecretInputString: (value: unknown) => (typeof value === "string" ? value : undefined),

86+

resolveSecretInputString: ({ value }: { value: unknown }) =>

87+

typeof value === "string" ? value : undefined,

88+

resolveApproval: resolveApprovalMock,

89+

} as PlatformAdapter);

90+

}

91+92+

describe("createInteractionHandler approval buttons", () => {

93+

beforeEach(() => {

94+

vi.clearAllMocks();

95+

installPlatformAdapter();

96+

});

97+98+

it("rejects approval button clicks from users outside the configured approvers", async () => {

99+

const handler = createInteractionHandler(account, runtime, undefined, {

100+

getActiveCfg: () => makeRestrictedCfg(["OWNER_OPENID"]),

101+

});

102+103+

handler(makeApprovalEvent());

104+105+

await vi.waitFor(() => expect(acknowledgeInteractionMock).toHaveBeenCalled());

106+107+

expect(acknowledgeInteractionMock).toHaveBeenCalledWith(

108+

{ appId: "app", clientSecret: "secret" },

109+

"interaction-1",

110+

0,

111+

{ content: "You are not authorized to approve this request." },

112+

);

113+

expect(resolveApprovalMock).not.toHaveBeenCalled();

114+

});

115+116+

it("does not authorize from resolved user id when the actor openid is not approved", async () => {

117+

const handler = createInteractionHandler(account, runtime, undefined, {

118+

getActiveCfg: () => makeRestrictedCfg(["OWNER_OPENID"]),

119+

});

120+121+

handler(

122+

makeApprovalEvent({

123+

data: {

124+

type: 11,

125+

resolved: {

126+

button_data: "approve:exec:abc12345:allow-once",

127+

user_id: "OWNER_OPENID",

128+

},

129+

},

130+

}),

131+

);

132+133+

await vi.waitFor(() => expect(acknowledgeInteractionMock).toHaveBeenCalled());

134+135+

expect(acknowledgeInteractionMock).toHaveBeenCalledWith(

136+

{ appId: "app", clientSecret: "secret" },

137+

"interaction-1",

138+

0,

139+

{ content: "You are not authorized to approve this request." },

140+

);

141+

expect(resolveApprovalMock).not.toHaveBeenCalled();

142+

});

143+144+

it("resolves approval button clicks from configured approvers", async () => {

145+

const handler = createInteractionHandler(account, runtime, undefined, {

146+

getActiveCfg: () => makeRestrictedCfg(["OWNER_OPENID"]),

147+

});

148+149+

handler(makeApprovalEvent({ group_member_openid: "OWNER_OPENID" }));

150+151+

await vi.waitFor(() =>

152+

expect(resolveApprovalMock).toHaveBeenCalledWith("exec:abc12345", "allow-once"),

153+

);

154+

});

155+156+

it("uses the direct user openid when a group member openid is unavailable", async () => {

157+

const handler = createInteractionHandler(account, runtime, undefined, {

158+

getActiveCfg: () => makeRestrictedCfg(["OWNER_OPENID"]),

159+

});

160+161+

handler(

162+

makeApprovalEvent({

163+

chat_type: 2,

164+

group_openid: undefined,

165+

group_member_openid: undefined,

166+

user_openid: "OWNER_OPENID",

167+

}),

168+

);

169+170+

await vi.waitFor(() =>

171+

expect(resolveApprovalMock).toHaveBeenCalledWith("exec:abc12345", "allow-once"),

172+

);

173+

});

174+175+

it("allows approval button clicks when exec approvals are not configured", async () => {

176+

const handler = createInteractionHandler(account, runtime, undefined, {

177+

getActiveCfg: () => makeUnrestrictedCfg(),

178+

});

179+180+

handler(makeApprovalEvent());

181+182+

await vi.waitFor(() =>

183+

expect(resolveApprovalMock).toHaveBeenCalledWith("exec:abc12345", "allow-once"),

184+

);

185+

});

186+187+

it("rejects approval button clicks when active config cannot be loaded", async () => {

188+

const handler = createInteractionHandler(account, runtime, undefined, {

189+

getActiveCfg: () => {

190+

throw new Error("config unavailable");

191+

},

192+

});

193+194+

handler(makeApprovalEvent());

195+196+

await vi.waitFor(() => expect(acknowledgeInteractionMock).toHaveBeenCalled());

197+198+

expect(acknowledgeInteractionMock).toHaveBeenCalledWith(

199+

{ appId: "app", clientSecret: "secret" },

200+

"interaction-1",

201+

0,

202+

{ content: "Approval is unavailable." },

203+

);

204+

expect(resolveApprovalMock).not.toHaveBeenCalled();

205+

});

206+

});