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

推荐订阅源

J
Java Code Geeks
G
Google Developers Blog
有赞技术团队
有赞技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
博客园 - 聂微东
V
Visual Studio Blog
博客园_首页
D
DataBreaches.Net
腾讯CDC
I
InfoQ
F
Fortinet All Blogs
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 【当耐特】
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
云风的 BLOG
云风的 BLOG
月光博客
月光博客
Recent Announcements
Recent Announcements
MongoDB | Blog
MongoDB | 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
fix(qqbot): validate token expiry lifetimes · openclaw/op...
steipete · 2026-05-29 · via Recent Commits to openclaw:main

File tree

  • extensions/qqbot/src/engine/api

Original file line numberDiff line numberDiff line change

@@ -4,6 +4,7 @@ import { TokenManager } from "./token.js";

44

describe("QQBot token manager", () => {

55

afterEach(() => {

66

vi.unstubAllGlobals();

7+

vi.useRealTimers();

78

});

89
910

it("wraps malformed access token JSON", async () => {

@@ -21,4 +22,45 @@ describe("QQBot token manager", () => {

2122

"QQBot access_token response was malformed JSON",

2223

);

2324

});

25+
26+

it("does not cache access tokens forever when expires_in is unsafe", async () => {

27+

vi.useFakeTimers();

28+

vi.setSystemTime(new Date("2026-05-29T12:00:00.000Z"));

29+

vi.stubGlobal(

30+

"fetch",

31+

vi.fn().mockResolvedValue(

32+

new Response('{"access_token":"token-1","expires_in":1e309}', {

33+

status: 200,

34+

headers: { "content-type": "application/json" },

35+

}),

36+

),

37+

);

38+
39+

const manager = new TokenManager();

40+

await expect(manager.getAccessToken("app-id", "secret")).resolves.toBe("token-1");

41+
42+

const status = manager.getStatus("app-id");

43+

expect(status.status).toBe("valid");

44+

expect(status.expiresAt).toBe(Date.now() + 7200 * 1000);

45+

});

46+
47+

it("does not extend explicit non-positive token lifetimes", async () => {

48+

vi.useFakeTimers();

49+

vi.setSystemTime(new Date("2026-05-29T12:00:00.000Z"));

50+

const fetch = vi.fn().mockResolvedValue(

51+

new Response('{"access_token":"token-1","expires_in":0}', {

52+

status: 200,

53+

headers: { "content-type": "application/json" },

54+

}),

55+

);

56+

vi.stubGlobal("fetch", fetch);

57+
58+

const manager = new TokenManager();

59+

await expect(manager.getAccessToken("app-id", "secret")).resolves.toBe("token-1");

60+
61+

expect(manager.getStatus("app-id")).toEqual({

62+

status: "expired",

63+

expiresAt: Date.now(),

64+

});

65+

});

2466

});

Original file line numberDiff line numberDiff line change

@@ -6,10 +6,12 @@

66

* globals, fully supporting multi-account concurrent operation.

77

*/

88
9+

import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";

910

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

1011

import { formatErrorMessage } from "../utils/format.js";

1112
1213

const TOKEN_URL = "https://bots.qq.com/app/getAppAccessToken";

14+

const DEFAULT_TOKEN_EXPIRES_IN_SECONDS = 7200;

1315
1416

interface CachedToken {

1517

token: string;

@@ -24,6 +26,17 @@ interface BackgroundRefreshOptions {

2426

retryDelayMs?: number;

2527

}

2628
29+

function resolveTokenExpiresInSeconds(value: unknown): number {

30+

const parsed = parseStrictPositiveInteger(value);

31+

if (parsed !== undefined) {

32+

return parsed;

33+

}

34+

if (value == null || (typeof value === "number" && !Number.isFinite(value))) {

35+

return DEFAULT_TOKEN_EXPIRES_IN_SECONDS;

36+

}

37+

return 0;

38+

}

39+
2740

/**

2841

* Per-appId token manager with caching, singleflight, and background refresh.

2942

*

@@ -239,7 +252,7 @@ export class TokenManager {

239252

const logBody = rawBody.replace(/"access_token"\s*:\s*"[^"]+"/g, '"access_token": "***"');

240253

this.logger?.debug?.(`[qqbot:token:${appId}] <<< Body: ${logBody}`);

241254
242-

let data: { access_token?: string; expires_in?: number };

255+

let data: { access_token?: string; expires_in?: unknown };

243256

try {

244257

data = JSON.parse(rawBody);

245258

} catch {

@@ -250,7 +263,7 @@ export class TokenManager {

250263

throw new Error(`Failed to get access_token: ${JSON.stringify(data)}`);

251264

}

252265
253-

const expiresAt = Date.now() + (data.expires_in ?? 7200) * 1000;

266+

const expiresAt = Date.now() + resolveTokenExpiresInSeconds(data.expires_in) * 1000;

254267

this.cache.set(appId, { token: data.access_token, expiresAt, appId });

255268

this.logger?.debug?.(

256269

`[qqbot:token:${appId}] Cached, expires at: ${new Date(expiresAt).toISOString()}`,