|
7 | 7 | whatsappOutbound, |
8 | 8 | } from "../../../test/helpers/infra/deliver-test-outbounds.js"; |
9 | 9 | import type { OpenClawConfig } from "../../config/config.js"; |
| 10 | +import * as mediaCapabilityModule from "../../media/read-capability.js"; |
10 | 11 | import { createHookRunner } from "../../plugins/hooks.js"; |
11 | 12 | import { addTestHook } from "../../plugins/hooks.test-helpers.js"; |
12 | 13 | import { createEmptyPluginRegistry } from "../../plugins/registry.js"; |
@@ -217,6 +218,100 @@ describe("deliverOutboundPayloads", () => { |
217 | 218 | releasePinnedPluginChannelRegistry(); |
218 | 219 | setActivePluginRegistry(emptyRegistry); |
219 | 220 | }); |
| 221 | + |
| 222 | + it("keeps requester session channel authoritative for delivery media policy", async () => { |
| 223 | + const resolveMediaAccessSpy = vi.spyOn( |
| 224 | + mediaCapabilityModule, |
| 225 | + "resolveAgentScopedOutboundMediaAccess", |
| 226 | + ); |
| 227 | + const sendWhatsApp = vi.fn().mockResolvedValue({ messageId: "w1", toJid: "jid" }); |
| 228 | + |
| 229 | + await deliverOutboundPayloads({ |
| 230 | + cfg: {}, |
| 231 | + channel: "whatsapp", |
| 232 | + to: "+1555", |
| 233 | + payloads: [{ text: "hello" }], |
| 234 | + deps: { whatsapp: sendWhatsApp }, |
| 235 | + session: { |
| 236 | + key: "agent:main:whatsapp:group:ops", |
| 237 | + requesterSenderId: "attacker", |
| 238 | + }, |
| 239 | + }); |
| 240 | + |
| 241 | + expect(resolveMediaAccessSpy).toHaveBeenCalledWith( |
| 242 | + expect.objectContaining({ |
| 243 | + sessionKey: "agent:main:whatsapp:group:ops", |
| 244 | + messageProvider: undefined, |
| 245 | + requesterSenderId: "attacker", |
| 246 | + }), |
| 247 | + ); |
| 248 | + resolveMediaAccessSpy.mockRestore(); |
| 249 | + }); |
| 250 | + |
| 251 | + it("forwards all sender fields to media access for non-id policy matching", async () => { |
| 252 | + const resolveMediaAccessSpy = vi.spyOn( |
| 253 | + mediaCapabilityModule, |
| 254 | + "resolveAgentScopedOutboundMediaAccess", |
| 255 | + ); |
| 256 | + const sendWhatsApp = vi.fn().mockResolvedValue({ messageId: "w2", toJid: "jid" }); |
| 257 | + |
| 258 | + await deliverOutboundPayloads({ |
| 259 | + cfg: {}, |
| 260 | + channel: "whatsapp", |
| 261 | + to: "+1555", |
| 262 | + payloads: [{ text: "hello" }], |
| 263 | + deps: { whatsapp: sendWhatsApp }, |
| 264 | + session: { |
| 265 | + key: "agent:main:whatsapp:group:ops", |
| 266 | + requesterSenderId: "id:whatsapp:123", |
| 267 | + requesterSenderName: "Alice", |
| 268 | + requesterSenderUsername: "alice_u", |
| 269 | + requesterSenderE164: "+15551234567", |
| 270 | + }, |
| 271 | + }); |
| 272 | + |
| 273 | + expect(resolveMediaAccessSpy).toHaveBeenCalledWith( |
| 274 | + expect.objectContaining({ |
| 275 | + requesterSenderId: "id:whatsapp:123", |
| 276 | + requesterSenderName: "Alice", |
| 277 | + requesterSenderUsername: "alice_u", |
| 278 | + requesterSenderE164: "+15551234567", |
| 279 | + }), |
| 280 | + ); |
| 281 | + resolveMediaAccessSpy.mockRestore(); |
| 282 | + }); |
| 283 | + |
| 284 | + it("uses requester account from session for delivery media policy", async () => { |
| 285 | + const resolveMediaAccessSpy = vi.spyOn( |
| 286 | + mediaCapabilityModule, |
| 287 | + "resolveAgentScopedOutboundMediaAccess", |
| 288 | + ); |
| 289 | + const sendWhatsApp = vi.fn().mockResolvedValue({ messageId: "w3", toJid: "jid" }); |
| 290 | + |
| 291 | + await deliverOutboundPayloads({ |
| 292 | + cfg: {}, |
| 293 | + channel: "whatsapp", |
| 294 | + to: "+1555", |
| 295 | + accountId: "destination-account", |
| 296 | + payloads: [{ text: "hello" }], |
| 297 | + deps: { whatsapp: sendWhatsApp }, |
| 298 | + session: { |
| 299 | + key: "agent:main:whatsapp:group:ops", |
| 300 | + requesterAccountId: "source-account", |
| 301 | + requesterSenderId: "attacker", |
| 302 | + }, |
| 303 | + }); |
| 304 | + |
| 305 | + expect(resolveMediaAccessSpy).toHaveBeenCalledWith( |
| 306 | + expect.objectContaining({ |
| 307 | + sessionKey: "agent:main:whatsapp:group:ops", |
| 308 | + accountId: "source-account", |
| 309 | + requesterSenderId: "attacker", |
| 310 | + }), |
| 311 | + ); |
| 312 | + resolveMediaAccessSpy.mockRestore(); |
| 313 | + }); |
| 314 | + |
220 | 315 | it("chunks direct adapter text and preserves delivery overrides across sends", async () => { |
221 | 316 | const sendText = vi.fn().mockImplementation(async ({ text }: { text: string }) => ({ |
222 | 317 | channel: "matrix" as const, |
|
0 commit comments