fix: recognize qdreader uid from response body
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import vm from 'node:vm';
|
||||
|
||||
const code = fs.readFileSync(new URL('../js/qdreader_cookie.js', import.meta.url), 'utf8');
|
||||
|
||||
function run({ cookie = '', body = '' }) {
|
||||
const notices = [];
|
||||
const context = {
|
||||
$request: { headers: { Cookie: cookie } },
|
||||
$response: { body },
|
||||
$notify: (...args) => notices.push(args),
|
||||
$done: () => {},
|
||||
atob: (s) => Buffer.from(s, 'base64').toString('binary'),
|
||||
encodeURIComponent,
|
||||
decodeURIComponent,
|
||||
escape,
|
||||
};
|
||||
vm.runInNewContext(code, context);
|
||||
return notices;
|
||||
}
|
||||
|
||||
{
|
||||
const qdheader = Buffer.from('123456|device|more').toString('base64').replace(/=+$/, '');
|
||||
const notices = run({ cookie: `QDHeader=${encodeURIComponent(qdheader)}; QDH=abc` });
|
||||
assert.equal(notices[0][1], '抓取成功 uid:123456');
|
||||
assert.match(notices[0][2], /^启点ck /);
|
||||
}
|
||||
|
||||
{
|
||||
const notices = run({
|
||||
cookie: 'cmfuToken=abc; QDH=def',
|
||||
body: JSON.stringify({ Data: { UserId: 987654 } }),
|
||||
});
|
||||
assert.equal(notices[0][1], '抓取成功 uid:987654');
|
||||
}
|
||||
|
||||
{
|
||||
const notices = run({
|
||||
cookie: 'cmfuToken=abc; QDH=def',
|
||||
body: JSON.stringify({ Data: { UserInfo: { UserId: 2468 } } }),
|
||||
});
|
||||
assert.equal(notices[0][1], '抓取成功 uid:2468');
|
||||
}
|
||||
|
||||
{
|
||||
const notices = run({ cookie: 'cmfuToken=abc; QDH=def', body: '{}' });
|
||||
assert.equal(notices[0][1], 'Cookie 获取失败');
|
||||
assert.match(notices[0][2], /无法识别 uid/);
|
||||
}
|
||||
|
||||
console.log('ok - qdreader qx uid parsing');
|
||||
Reference in New Issue
Block a user