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

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
I
InfoQ
博客园_首页
G
Google Developers Blog
爱范儿
爱范儿
Last Week in AI
Last Week in AI
量子位
阮一峰的网络日志
阮一峰的网络日志
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
Vercel News
Vercel News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
月光博客
月光博客
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
N
Netflix TechBlog - Medium
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东

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
test(qa): validate Discord Convex credential payloads (#7...
Patrick-Eric · 2026-04-24 · via Recent Commits to openclaw:main

@@ -0,0 +1,121 @@

1+

export class CredentialPayloadValidationError extends Error {

2+

code: string;

3+

httpStatus: number;

4+5+

constructor(httpStatus: number, code: string, message: string) {

6+

super(message);

7+

this.name = "CredentialPayloadValidationError";

8+

this.httpStatus = httpStatus;

9+

this.code = code;

10+

}

11+

}

12+13+

type PayloadValidationFailureFactory = (httpStatus: number, code: string, message: string) => Error;

14+15+

const DISCORD_SNOWFLAKE_RE = /^\d{17,20}$/u;

16+

const TELEGRAM_CHAT_ID_RE = /^-?\d+$/u;

17+18+

function createCredentialPayloadValidationError(httpStatus: number, code: string, message: string) {

19+

return new CredentialPayloadValidationError(httpStatus, code, message);

20+

}

21+22+

function throwPayloadError(createFailure: PayloadValidationFailureFactory, message: string): never {

23+

throw createFailure(400, "INVALID_PAYLOAD", message);

24+

}

25+26+

function requirePayloadString(

27+

payload: Record<string, unknown>,

28+

key: string,

29+

kind: string,

30+

createFailure: PayloadValidationFailureFactory,

31+

): string {

32+

const raw = payload[key];

33+

if (typeof raw !== "string") {

34+

throwPayloadError(

35+

createFailure,

36+

`Credential payload for kind "${kind}" must include "${key}" as a string.`,

37+

);

38+

}

39+

const value = raw.trim();

40+

if (!value) {

41+

throwPayloadError(

42+

createFailure,

43+

`Credential payload for kind "${kind}" must include a non-empty "${key}" value.`,

44+

);

45+

}

46+

return value;

47+

}

48+49+

function requireDiscordSnowflakePayloadString(

50+

payload: Record<string, unknown>,

51+

key: string,

52+

createFailure: PayloadValidationFailureFactory,

53+

) {

54+

const value = requirePayloadString(payload, key, "discord", createFailure);

55+

if (!DISCORD_SNOWFLAKE_RE.test(value)) {

56+

throwPayloadError(

57+

createFailure,

58+

`Credential payload for kind "discord" must include "${key}" as a Discord snowflake string.`,

59+

);

60+

}

61+

return value;

62+

}

63+64+

function normalizeTelegramCredentialPayload(

65+

payload: Record<string, unknown>,

66+

createFailure: PayloadValidationFailureFactory,

67+

) {

68+

const groupId = requirePayloadString(payload, "groupId", "telegram", createFailure);

69+

if (!TELEGRAM_CHAT_ID_RE.test(groupId)) {

70+

throwPayloadError(

71+

createFailure,

72+

'Credential payload for kind "telegram" must include a numeric "groupId" string.',

73+

);

74+

}

75+76+

const driverToken = requirePayloadString(payload, "driverToken", "telegram", createFailure);

77+

const sutToken = requirePayloadString(payload, "sutToken", "telegram", createFailure);

78+79+

return {

80+

groupId,

81+

driverToken,

82+

sutToken,

83+

} satisfies Record<string, unknown>;

84+

}

85+86+

function normalizeDiscordCredentialPayload(

87+

payload: Record<string, unknown>,

88+

createFailure: PayloadValidationFailureFactory,

89+

) {

90+

const guildId = requireDiscordSnowflakePayloadString(payload, "guildId", createFailure);

91+

const channelId = requireDiscordSnowflakePayloadString(payload, "channelId", createFailure);

92+

const sutApplicationId = requireDiscordSnowflakePayloadString(

93+

payload,

94+

"sutApplicationId",

95+

createFailure,

96+

);

97+

const driverBotToken = requirePayloadString(payload, "driverBotToken", "discord", createFailure);

98+

const sutBotToken = requirePayloadString(payload, "sutBotToken", "discord", createFailure);

99+100+

return {

101+

guildId,

102+

channelId,

103+

driverBotToken,

104+

sutBotToken,

105+

sutApplicationId,

106+

} satisfies Record<string, unknown>;

107+

}

108+109+

export function normalizeCredentialPayloadForKind(

110+

kind: string,

111+

payload: Record<string, unknown>,

112+

createFailure: PayloadValidationFailureFactory = createCredentialPayloadValidationError,

113+

) {

114+

if (kind === "telegram") {

115+

return normalizeTelegramCredentialPayload(payload, createFailure);

116+

}

117+

if (kind === "discord") {

118+

return normalizeDiscordCredentialPayload(payload, createFailure);

119+

}

120+

return payload;

121+

}