Skip to content

Commit c4f46ba

Browse files
Alix-007Leon-SK668steipete
authored
fix(nextcloud-talk): add timeout to room info lookup (#102859)
* fix(nextcloud-talk): add timeout to room info lookup * test(nextcloud-talk): assert room lookup deadline Co-authored-by: llagy009 <[email protected]> --------- Co-authored-by: llagy009 <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
1 parent c47ceb0 commit c4f46ba

3 files changed

Lines changed: 59 additions & 3 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Nextcloud Talk room info lookup tests cover real HTTP timeout behavior.
2+
import { withServer } from "openclaw/plugin-sdk/test-env";
3+
import { describe, expect, it, vi } from "vitest";
4+
import { resolveNextcloudTalkRoomKind, testing } from "./room-info.js";
5+
6+
describe("nextcloud talk room info fetch timeout", () => {
7+
it("bounds hanging room info GET requests", async () => {
8+
let received = false;
9+
const runtimeError = vi.fn();
10+
11+
try {
12+
await withServer(
13+
(request) => {
14+
received = true;
15+
expect(request.method).toBe("GET");
16+
expect(request.url).toBe("/ocs/v2.php/apps/spreed/api/v4/room/abc123");
17+
request.resume();
18+
},
19+
async (baseUrl) => {
20+
const kind = await resolveNextcloudTalkRoomKind({
21+
account: {
22+
accountId: "acct-hanging-room-info",
23+
baseUrl,
24+
config: {
25+
apiUser: "bot",
26+
apiPassword: "secret",
27+
network: { dangerouslyAllowPrivateNetwork: true },
28+
},
29+
} as never,
30+
roomToken: "abc123",
31+
runtime: {
32+
error: runtimeError,
33+
exit: vi.fn(),
34+
log: vi.fn(),
35+
},
36+
timeoutMs: 50,
37+
});
38+
39+
expect(kind).toBeUndefined();
40+
},
41+
);
42+
} finally {
43+
testing.resetRoomCache();
44+
}
45+
46+
expect(received).toBe(true);
47+
expect(String(runtimeError.mock.calls[0]?.[0] ?? "")).toMatch(/abort|timeout/i);
48+
});
49+
});

‎extensions/nextcloud-talk/src/room-info.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ afterEach(() => {
2020
}
2121
});
2222

23-
function requireFirstFetchParams(): {
23+
type RoomInfoFetchParams = {
2424
auditContext?: string;
2525
init?: { headers?: { Authorization?: string } };
26+
timeoutMs?: number;
2627
url?: string;
27-
} {
28+
};
29+
30+
function requireFirstFetchParams(): RoomInfoFetchParams {
2831
const [call] = fetchWithSsrFGuard.mock.calls;
2932
if (!call) {
3033
throw new Error("expected Nextcloud Talk room info fetch call");
@@ -33,7 +36,7 @@ function requireFirstFetchParams(): {
3336
if (!fetchParams || typeof fetchParams !== "object" || Array.isArray(fetchParams)) {
3437
throw new Error("expected Nextcloud Talk room info fetch call");
3538
}
36-
return fetchParams as { auditContext?: string; url?: string };
39+
return fetchParams as RoomInfoFetchParams;
3740
}
3841

3942
function jsonResponse(payload: unknown, init?: ResponseInit): Response {
@@ -76,6 +79,7 @@ describe("nextcloud talk room info", () => {
7679
"https://nc.example.com/ocs/v2.php/apps/spreed/api/v4/room/room-direct",
7780
);
7881
expect(fetchParams.auditContext).toBe("nextcloud-talk.room-info");
82+
expect(fetchParams.timeoutMs).toBe(30_000);
7983
expect(release).toHaveBeenCalledTimes(1);
8084
});
8185

‎extensions/nextcloud-talk/src/room-info.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { resolveNextcloudTalkApiCredentials } from "./api-credentials.js";
1111
const ROOM_CACHE_TTL_MS = 5 * 60 * 1000;
1212
const ROOM_CACHE_ERROR_TTL_MS = 30 * 1000;
1313
const ROOM_CACHE_MAX_ENTRIES = 1000;
14+
const NEXTCLOUD_TALK_ROOM_INFO_TIMEOUT_MS = 30_000;
1415

1516
const roomCache = new Map<
1617
string,
@@ -56,6 +57,7 @@ export async function resolveNextcloudTalkRoomKind(params: {
5657
account: ResolvedNextcloudTalkAccount;
5758
roomToken: string;
5859
runtime?: RuntimeEnv;
60+
timeoutMs?: number;
5961
}): Promise<"direct" | "group" | undefined> {
6062
const { account, roomToken, runtime } = params;
6163
const key = resolveRoomCacheKey({ accountId: account.accountId, roomToken });
@@ -103,6 +105,7 @@ export async function resolveNextcloudTalkRoomKind(params: {
103105
},
104106
auditContext: "nextcloud-talk.room-info",
105107
policy: ssrfPolicyFromPrivateNetworkOptIn(account.config),
108+
timeoutMs: params.timeoutMs ?? NEXTCLOUD_TALK_ROOM_INFO_TIMEOUT_MS,
106109
});
107110
try {
108111
if (!response.ok) {

0 commit comments

Comments
 (0)