


















@@ -6,6 +6,19 @@ import type { VoiceMessageMetadata } from "./voice-message.js";
6677const runFfprobeMock = vi.hoisted(() => vi.fn<(...args: unknown[]) => Promise<string>>());
88const runFfmpegMock = vi.hoisted(() => vi.fn<(...args: unknown[]) => Promise<void>>());
9+const fetchWithSsrFGuardMock = vi.hoisted(() =>
10+vi.fn(
11+async (params: {
12+url: string;
13+init?: RequestInit;
14+policy?: { allowRfc2544BenchmarkRange?: boolean; allowIpv6UniqueLocalRange?: boolean };
15+auditContext?: string;
16+}) => ({
17+response: await globalThis.fetch(params.url, params.init),
18+release: async () => {},
19+}),
20+),
21+);
9221023vi.mock("openclaw/plugin-sdk/temp-path", async () => {
1124return {
@@ -31,10 +44,7 @@ vi.mock("openclaw/plugin-sdk/media-runtime", async () => {
31443245vi.mock("openclaw/plugin-sdk/ssrf-runtime", async () => {
3346return {
34-fetchWithSsrFGuard: async (params: { url: string; init?: RequestInit }) => ({
35-response: await globalThis.fetch(params.url, params.init),
36-release: async () => {},
37-}),
47+fetchWithSsrFGuard: fetchWithSsrFGuardMock,
3848};
3949});
4050@@ -196,6 +206,7 @@ describe("sendDiscordVoiceMessage", () => {
196206197207beforeEach(() => {
198208vi.restoreAllMocks();
209+fetchWithSsrFGuardMock.mockClear();
199210});
200211201212function createRest(post = vi.fn(async () => ({ id: "msg-1", channel_id: "channel-1" }))) {
@@ -269,6 +280,35 @@ describe("sendDiscordVoiceMessage", () => {
269280270281expect(uploadUrlRequests).toBe(2);
271282expect(fetchMock).toHaveBeenCalledTimes(4);
283+expect(fetchWithSsrFGuardMock).toHaveBeenCalledTimes(4);
284+expect(
285+fetchWithSsrFGuardMock.mock.calls.map(([params]) => ({
286+auditContext: params.auditContext,
287+allowRfc2544BenchmarkRange: params.policy?.allowRfc2544BenchmarkRange,
288+allowIpv6UniqueLocalRange: params.policy?.allowIpv6UniqueLocalRange,
289+})),
290+).toEqual([
291+{
292+auditContext: "discord.voice.upload-url",
293+allowRfc2544BenchmarkRange: true,
294+allowIpv6UniqueLocalRange: true,
295+},
296+{
297+auditContext: "discord.voice.attachment-upload",
298+allowRfc2544BenchmarkRange: true,
299+allowIpv6UniqueLocalRange: true,
300+},
301+{
302+auditContext: "discord.voice.upload-url",
303+allowRfc2544BenchmarkRange: true,
304+allowIpv6UniqueLocalRange: true,
305+},
306+{
307+auditContext: "discord.voice.attachment-upload",
308+allowRfc2544BenchmarkRange: true,
309+allowIpv6UniqueLocalRange: true,
310+},
311+]);
272312expect(post).toHaveBeenCalledWith("/channels/channel-1/messages", {
273313body: {
274314flags: 8192,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。