mirror of
https://git.zhongyuan.online/ytke/tap.git
synced 2026-11-24 22:15:18 -08:00
23 lines
1.7 KiB
TypeScript
23 lines
1.7 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { test } from 'node:test';
|
|
import { feishuJson } from '../lib/server/feishu-config.ts';
|
|
|
|
test('Feishu diagnostics retain provider stage and numeric error codes without credentials or user fields', async () => {
|
|
const fetchBefore = globalThis.fetch;
|
|
const logBefore = console.error;
|
|
const logs: unknown[][] = [];
|
|
console.error = (...args: unknown[]) => { logs.push(args); };
|
|
try {
|
|
globalThis.fetch = async () => Response.json({ code: 20010, error: 'invalid_request', error_description: 'secret-must-never-appear', access_token: 'private-token' }, { status: 400 });
|
|
await assert.rejects(() => feishuJson('https://accounts.feishu.cn/oauth/v3/token', { method: 'POST', body: 'private-code-and-secret' }), /HTTP 400/);
|
|
assert.deepEqual(logs.at(-1), ['Feishu API failure', { stage: 'oauth-token', httpStatus: 400, providerCode: 20010 }]);
|
|
globalThis.fetch = async () => Response.json({ code: 20021, msg: 'private-user-information' });
|
|
await feishuJson('https://open.feishu.cn/open-apis/authen/v1/user_info', {});
|
|
assert.deepEqual(logs.at(-1), ['Feishu API failure', { stage: 'user-info', httpStatus: 200, providerCode: 20021 }]);
|
|
globalThis.fetch = async () => { throw new Error('https://open.feishu.cn/open-apis/bot/v2/hook/private-webhook'); };
|
|
await assert.rejects(() => feishuJson('https://open.feishu.cn/open-apis/bot/v2/hook/private-webhook', {}), /连接失败/);
|
|
const text = JSON.stringify(logs);
|
|
for (const secret of ['secret-must-never-appear', 'private-token', 'private-code', 'private-user', 'private-webhook']) assert.ok(!text.includes(secret));
|
|
} finally { globalThis.fetch = fetchBefore; console.error = logBefore; }
|
|
});
|