feat: gate WeChat media analysis by user
This commit is contained in:
+40
-1
@@ -3702,6 +3702,7 @@ test('wechat mp service persists image and routes image url into agent prompt',
|
||||
unboundTextPrefix: '请先绑定',
|
||||
progressDelayMs: 0,
|
||||
maxImageBytes: 1024 * 1024,
|
||||
mediaAnalysisGrayUsers: [testUserId],
|
||||
},
|
||||
userAuth: {
|
||||
async findWechatUserByOpenid() {
|
||||
@@ -3831,6 +3832,7 @@ test('wechat mp service persists Word and Excel files in user public area and re
|
||||
config: {
|
||||
maxFileBytes: 1024 * 1024,
|
||||
acceptFile: true,
|
||||
mediaAnalysisGrayUsers: [testUserId],
|
||||
},
|
||||
userAuth: {
|
||||
async findWechatUserByOpenid() {
|
||||
@@ -3939,7 +3941,7 @@ test('wechat mp service rejects unsupported public file types without entering t
|
||||
let mediaDownloads = 0;
|
||||
let sessionCalls = 0;
|
||||
const service = createBoundWechatService({
|
||||
config: { acceptFile: true },
|
||||
config: { acceptFile: true, mediaAnalysisGrayUsers: ['user-1'] },
|
||||
sessionApiFetch: async () => {
|
||||
sessionCalls += 1;
|
||||
throw new Error('session should not be called');
|
||||
@@ -3975,6 +3977,43 @@ test('wechat mp service rejects unsupported public file types without entering t
|
||||
assert.equal(sessionCalls, 0);
|
||||
});
|
||||
|
||||
test('wechat mp service keeps file analysis disabled outside the media gray allowlist', async () => {
|
||||
let mediaDownloads = 0;
|
||||
let sessionCalls = 0;
|
||||
const service = createBoundWechatService({
|
||||
config: {
|
||||
acceptFile: true,
|
||||
mediaAnalysisGrayUsers: ['唐'],
|
||||
},
|
||||
sessionApiFetch: async () => {
|
||||
sessionCalls += 1;
|
||||
throw new Error('session should not be called');
|
||||
},
|
||||
wechatFetch: async (url) => {
|
||||
if (String(url).includes('/cgi-bin/media/get')) mediaDownloads += 1;
|
||||
throw new Error(`unexpected wechat url: ${url}`);
|
||||
},
|
||||
});
|
||||
|
||||
const result = await service.handleInboundMessage(
|
||||
inboundXml({
|
||||
msgType: 'file',
|
||||
content: '',
|
||||
extraFields: { MediaId: 'file-media-gray', FileName: '测试.docx' },
|
||||
}),
|
||||
{
|
||||
timestamp: '1710000000',
|
||||
nonce: 'nonce',
|
||||
signature: signatureFor('token', '1710000000', 'nonce'),
|
||||
},
|
||||
);
|
||||
|
||||
assert.equal(result.status, 200);
|
||||
assert.match(result.body, /尚未开启服务号文件分析灰度/);
|
||||
assert.equal(mediaDownloads, 0);
|
||||
assert.equal(sessionCalls, 0);
|
||||
});
|
||||
|
||||
test('wechat mp service accepts full voice xml payload and routes recognition text into agent', async () => {
|
||||
const token = 'token';
|
||||
const timestamp = '1710000000';
|
||||
|
||||
Reference in New Issue
Block a user