fix(qzone): delete_v6 uses format=fs, drop bogus json param, harden success check
Adversarial review (NEEDS-FIXES) — two wrong-constant defects (same family as the publish t1_tid bug) + a destructive-write hardening: - format=json → format=fs. Every working reference (silica-github/ qq_zone_delete, zhihu, daimagongfang) uses fs for the delete CGI; the tests re-codified the wrong value. - Removed the invented json=1 body param (no source includes it); test now asserts it's absent. - Also throw on a non-zero subcode (not just code), and documented that the code/subcode success signal is EXTRAPOLATED from sibling CGIs pending a live capture (public delete impls only check HTTP 2xx). Added subcode-throw and code-absent-resolves tests to lock the branch.
This commit is contained in:
2 files changed
+31
-4
No files matched your search
@@ -428,13 +428,15 @@ export async function deleteQzoneMsg(
|
|||||||
|
|
||||||
const bkn = getBknFromCookie(cookieObject);
|
const bkn = getBknFromCookie(cookieObject);
|
||||||
const url = `https://h5.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_delete_v6?g_tk=${bkn}`;
|
const url = `https://h5.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_delete_v6?g_tk=${bkn}`;
|
||||||
|
// The canonical delete request uses `format=fs` (NOT json) and the exact
|
||||||
|
// param set below — confirmed across the silica-github/qq_zone_delete
|
||||||
|
// working script and community docs.
|
||||||
const body = new URLSearchParams({
|
const body = new URLSearchParams({
|
||||||
hostuin: hostUin,
|
hostuin: hostUin,
|
||||||
tid,
|
tid,
|
||||||
t1_source: '1',
|
t1_source: '1',
|
||||||
code_version: '1',
|
code_version: '1',
|
||||||
format: 'json',
|
format: 'fs',
|
||||||
json: '1',
|
|
||||||
qzreferrer: `https://user.qzone.qq.com/${hostUin}`,
|
qzreferrer: `https://user.qzone.qq.com/${hostUin}`,
|
||||||
}).toString();
|
}).toString();
|
||||||
|
|
||||||
@@ -444,8 +446,18 @@ export async function deleteQzoneMsg(
|
|||||||
});
|
});
|
||||||
const data = parseQzoneJson<RawDeleteResponse>(text);
|
const data = parseQzoneJson<RawDeleteResponse>(text);
|
||||||
|
|
||||||
|
// Success signal: delete has no positive payload, so we throw on a
|
||||||
|
// non-zero code OR sub-code. NOTE: that `code`/`subcode` is delete's
|
||||||
|
// success field is EXTRAPOLATED from the sibling CGIs (publish/msglist)
|
||||||
|
// — public delete impls only check HTTP 2xx — so this is pending a live
|
||||||
|
// capture to confirm the exact failure envelope (same posture as the
|
||||||
|
// other helpers in this file).
|
||||||
if (typeof data.code === 'number' && data.code !== 0) {
|
if (typeof data.code === 'number' && data.code !== 0) {
|
||||||
log.warn('deleteQzoneMsg: non-zero code (uin=%s tid=%s) code=%d msg=%s', hostUin, tid, data.code, data.message);
|
log.warn('deleteQzoneMsg: non-zero code (uin=%s tid=%s) code=%d msg=%s', hostUin, tid, data.code, data.message);
|
||||||
throw new Error(`qzone delete failed: code=${data.code} ${data.message ?? ''}`.trim());
|
throw new Error(`qzone delete failed: code=${data.code} ${data.message ?? ''}`.trim());
|
||||||
}
|
}
|
||||||
|
if (typeof data.subcode === 'number' && data.subcode !== 0) {
|
||||||
|
log.warn('deleteQzoneMsg: non-zero subcode (uin=%s tid=%s) subcode=%d msg=%s', hostUin, tid, data.subcode, data.message);
|
||||||
|
throw new Error(`qzone delete failed: subcode=${data.subcode} ${data.message ?? ''}`.trim());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -247,7 +247,10 @@ describe('qzone / publishQzoneMsg (HTTP layer)', () => {
|
|||||||
describe('qzone / deleteQzoneMsg (HTTP layer)', () => {
|
describe('qzone / deleteQzoneMsg (HTTP layer)', () => {
|
||||||
afterEach(() => vi.restoreAllMocks());
|
afterEach(() => vi.restoreAllMocks());
|
||||||
|
|
||||||
it('POSTs the tid form body to the proxied delete CGI and resolves on code 0', async () => {
|
it('POSTs the tid form body (format=fs) to the proxied delete CGI and resolves on code 0', async () => {
|
||||||
|
// NB: the success-body shape is a guess extrapolated from sibling CGIs —
|
||||||
|
// no public delete impl parses the response — so this mock pins our
|
||||||
|
// success contract, not a verified server envelope (see helper comment).
|
||||||
const spy = vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":0,"subcode":0,"message":""}');
|
const spy = vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":0,"subcode":0,"message":""}');
|
||||||
|
|
||||||
await expect(deleteQzoneMsg(cookies, '10000', 'TID123')).resolves.toBeUndefined();
|
await expect(deleteQzoneMsg(cookies, '10000', 'TID123')).resolves.toBeUndefined();
|
||||||
@@ -263,7 +266,9 @@ describe('qzone / deleteQzoneMsg (HTTP layer)', () => {
|
|||||||
const form = new URLSearchParams(body as string);
|
const form = new URLSearchParams(body as string);
|
||||||
expect(form.get('tid')).toBe('TID123');
|
expect(form.get('tid')).toBe('TID123');
|
||||||
expect(form.get('hostuin')).toBe('10000');
|
expect(form.get('hostuin')).toBe('10000');
|
||||||
expect(form.get('format')).toBe('json');
|
// delete_v6 wants format=fs (NOT json), per the working community script
|
||||||
|
expect(form.get('format')).toBe('fs');
|
||||||
|
expect(form.get('json')).toBeNull(); // no bogus json param
|
||||||
});
|
});
|
||||||
|
|
||||||
it('rejects an empty tid before any request', async () => {
|
it('rejects an empty tid before any request', async () => {
|
||||||
@@ -276,4 +281,14 @@ describe('qzone / deleteQzoneMsg (HTTP layer)', () => {
|
|||||||
vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":-4001,"message":"no permission"}');
|
vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":-4001,"message":"no permission"}');
|
||||||
await expect(deleteQzoneMsg(cookies, '10000', 'TID123')).rejects.toThrow('code=-4001');
|
await expect(deleteQzoneMsg(cookies, '10000', 'TID123')).rejects.toThrow('code=-4001');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws on a non-zero subcode even when code is 0', async () => {
|
||||||
|
vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":0,"subcode":-12,"message":"sub error"}');
|
||||||
|
await expect(deleteQzoneMsg(cookies, '10000', 'TID123')).rejects.toThrow('subcode=-12');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resolves when neither code nor subcode is present (extrapolated success branch)', async () => {
|
||||||
|
vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"message":""}');
|
||||||
|
await expect(deleteQzoneMsg(cookies, '10000', 'TID123')).resolves.toBeUndefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user