fix(protocol): restore unidirectional friend lookup
Read the unidirectional friend list correctly and preserve service errors instead of returning an empty list for rejected requests. Fixes #608
This commit is contained in:
4 files changed
+123
-99
No files matched your search
@@ -352,12 +352,12 @@ describe('apis/profile', () => {
|
|||||||
errorCode: 0,
|
errorCode: 0,
|
||||||
errorMessage: '',
|
errorMessage: '',
|
||||||
responseData: Buffer.from(
|
responseData: Buffer.from(
|
||||||
protobuf_encode<OidbBase<Oidb0xe17Resp>>({
|
protobuf_encode<Oidb0xe17Resp>({
|
||||||
body: {
|
jsonBody: JSON.stringify({
|
||||||
jsonBody: JSON.stringify({
|
ActionStatus: 'OK',
|
||||||
rpt_block_list: [{ uin: 10001 }, { uin: 10002 }],
|
ErrorCode: 0,
|
||||||
}),
|
rpt_block_list: [{ uin: 10001 }, { uin: 10002 }],
|
||||||
} as any,
|
}),
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -637,10 +637,13 @@ export interface Oidb0x8a7Resp {
|
|||||||
canAtAll?: pb<6, bool>;
|
canAtAll?: pb<6, bool>;
|
||||||
}
|
}
|
||||||
export interface Oidb0xe17Req {
|
export interface Oidb0xe17Req {
|
||||||
|
subCommand?: pb_optional<2, uint_32>;
|
||||||
jsonBody?: pb<3, string>;
|
jsonBody?: pb<3, string>;
|
||||||
}
|
}
|
||||||
export interface Oidb0xe17Resp {
|
export interface Oidb0xe17Resp {
|
||||||
|
errorCode?: pb<3, uint_32>;
|
||||||
jsonBody?: pb<4, string>;
|
jsonBody?: pb<4, string>;
|
||||||
|
errorMessage?: pb<5, string>;
|
||||||
}
|
}
|
||||||
export interface Oidb0x112aProfileInfo {
|
export interface Oidb0x112aProfileInfo {
|
||||||
tag?: pb<1, uint_32>;
|
tag?: pb<1, uint_32>;
|
||||||
|
|||||||
@@ -1,28 +1,22 @@
|
|||||||
// 0xE17_0 — fetch the unidirectional friend block list. Wire name is
|
// This service uses its own JSON transport rather than the standard OIDB envelope.
|
||||||
// non-standard (`MQUpdateSvc_com_qq_ti.web.OidbSvc.0xe17_0`) — uses
|
|
||||||
// the `wireName` override to bypass the default
|
|
||||||
// `OidbSvcTrpcTcp.0xNNNN_N` scheme.
|
|
||||||
//
|
|
||||||
// Request and response carry a JSON-encoded string in a single
|
|
||||||
// protobuf field, so the namespace's `serialize` / `deserialize` do
|
|
||||||
// the JSON marshalling.
|
|
||||||
|
|
||||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
|
||||||
import type { Oidb0xe17Req, Oidb0xe17Resp } from '@snowluma/proto-defs/oidb-actions/base';
|
import type { Oidb0xe17Req, Oidb0xe17Resp } from '@snowluma/proto-defs/oidb-actions/base';
|
||||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||||
import type { BridgeContext } from '../../bridge-context';
|
import type { BridgeContext } from '../../bridge-context';
|
||||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
import { OidbError, type OidbSender } from '../../oidb-service';
|
||||||
|
import { requirePacketResponse } from '../../msg-push/packet-response';
|
||||||
|
|
||||||
export interface UnidirectionalFriendEntry {
|
export interface UnidirectionalFriendEntry {
|
||||||
[key: string]: import('@snowluma/common/json').JsonValue;
|
[key: string]: import('@snowluma/common/json').JsonValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isObject(value: unknown): value is UnidirectionalFriendEntry {
|
||||||
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
||||||
|
}
|
||||||
|
|
||||||
export namespace GetUnidirectionalFriendList {
|
export namespace GetUnidirectionalFriendList {
|
||||||
export const command = 0xe17;
|
export const command = 0xe17;
|
||||||
export const subCommand = 0;
|
export const subCommand = 0;
|
||||||
|
|
||||||
/** Wire name override — this cmd lives outside the standard
|
|
||||||
* `OidbSvcTrpcTcp.0xNNNN_N` namespace. */
|
|
||||||
export const wireName = (): string => 'MQUpdateSvc_com_qq_ti.web.OidbSvc.0xe17_0';
|
export const wireName = (): string => 'MQUpdateSvc_com_qq_ti.web.OidbSvc.0xe17_0';
|
||||||
|
|
||||||
export interface Params {}
|
export interface Params {}
|
||||||
@@ -36,26 +30,45 @@ export namespace GetUnidirectionalFriendList {
|
|||||||
uint32_req_num: 99,
|
uint32_req_num: 99,
|
||||||
bytes_cookies: '',
|
bytes_cookies: '',
|
||||||
};
|
};
|
||||||
return { jsonBody: JSON.stringify(reqObj) };
|
return { subCommand, jsonBody: JSON.stringify(reqObj) };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deserialize = (_ctx: Deps, body: Oidb0xe17Resp): UnidirectionalFriendEntry[] => {
|
export const deserialize = (_ctx: Deps, body: Oidb0xe17Resp): UnidirectionalFriendEntry[] => {
|
||||||
|
if (body.errorCode) {
|
||||||
|
throw new OidbError(body.errorCode, body.errorMessage ?? '', command, subCommand);
|
||||||
|
}
|
||||||
|
|
||||||
if (!body || !body.jsonBody) {
|
if (!body || !body.jsonBody) {
|
||||||
throw new Error('get unidirectional friend list empty');
|
throw new Error('get unidirectional friend list empty');
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsed = JSON.parse(body.jsonBody) as {
|
const parsed: unknown = JSON.parse(body.jsonBody);
|
||||||
rpt_block_list?: UnidirectionalFriendEntry[];
|
|
||||||
};
|
if (!isObject(parsed)) {
|
||||||
return parsed.rpt_block_list || [];
|
throw new Error('get unidirectional friend list invalid response');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parsed.ActionStatus !== 'OK' || parsed.ErrorCode !== 0) {
|
||||||
|
const code = typeof parsed.ErrorCode === 'number' ? parsed.ErrorCode : 'missing';
|
||||||
|
const message = typeof parsed.ErrorInfo === 'string' ? parsed.ErrorInfo : '';
|
||||||
|
throw new Error(`get unidirectional friend list failed: ${code} ${message}`.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Array.isArray(parsed.rpt_block_list) || !parsed.rpt_block_list.every(isObject)) {
|
||||||
|
throw new Error('get unidirectional friend list invalid block list');
|
||||||
|
}
|
||||||
|
|
||||||
|
return parsed.rpt_block_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const encode = (env: OidbBase<Oidb0xe17Req>): Uint8Array =>
|
export const encode = (request: Oidb0xe17Req): Uint8Array =>
|
||||||
protobuf_encode<OidbBase<Oidb0xe17Req>>(env);
|
protobuf_encode<Oidb0xe17Req>(request);
|
||||||
|
|
||||||
export const decode = (bytes: Uint8Array): OidbBase<Oidb0xe17Resp> =>
|
export const decode = (bytes: Uint8Array): Oidb0xe17Resp =>
|
||||||
protobuf_decode<OidbBase<Oidb0xe17Resp>>(bytes);
|
protobuf_decode<Oidb0xe17Resp>(bytes);
|
||||||
|
|
||||||
export const invoke = (deps: Deps): Promise<UnidirectionalFriendEntry[]> =>
|
export const invoke = async (deps: Deps): Promise<UnidirectionalFriendEntry[]> => {
|
||||||
invokeOidb(deps, GetUnidirectionalFriendList, {});
|
const result = await deps.sendRawPacket(wireName(), encode(serialize(deps, {})));
|
||||||
|
return deserialize(deps, decode(requirePacketResponse(result, wireName())));
|
||||||
|
};
|
||||||
}
|
}
|
||||||
+77
-69
@@ -1,93 +1,101 @@
|
|||||||
import { describe, expect, it, vi } from 'vitest';
|
import { describe, expect, it, vi } from 'vitest';
|
||||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
|
||||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
|
||||||
import type { Oidb0xe17Req, Oidb0xe17Resp } from '@snowluma/proto-defs/oidb-actions/base';
|
|
||||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||||
|
import type { IdentityService } from '../../../src/identity-service';
|
||||||
import { GetUnidirectionalFriendList } from '../../../src/oidb-services/profile/get-unidirectional-friend-list';
|
import { GetUnidirectionalFriendList } from '../../../src/oidb-services/profile/get-unidirectional-friend-list';
|
||||||
|
import { s, v } from '../_pb-oracle';
|
||||||
|
|
||||||
function makeDeps(responseJson?: unknown) {
|
function makeDeps(json: unknown = { ActionStatus: 'OK', ErrorCode: 0, rpt_block_list: [] }) {
|
||||||
const responseData =
|
const result: SendPacketResult = {
|
||||||
responseJson !== undefined
|
|
||||||
? Buffer.from(
|
|
||||||
protobuf_encode<OidbBase<Oidb0xe17Resp>>({
|
|
||||||
body: { jsonBody: JSON.stringify(responseJson) },
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
: Buffer.alloc(0);
|
|
||||||
const r: SendPacketResult = {
|
|
||||||
success: true,
|
success: true,
|
||||||
gotResponse: true,
|
gotResponse: true,
|
||||||
errorCode: 0,
|
errorCode: 0,
|
||||||
errorMessage: '',
|
errorMessage: '',
|
||||||
responseData,
|
responseData: Buffer.from([
|
||||||
|
...v(1, 0xe17),
|
||||||
|
...v(2, 0),
|
||||||
|
...v(3, 0),
|
||||||
|
...s(4, JSON.stringify(json)),
|
||||||
|
]),
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
sendRawPacket: vi.fn(async () => r),
|
sendRawPacket: vi.fn(async (_cmd: string, _body: Uint8Array) => result),
|
||||||
identity: { uin: '10001' } as any,
|
identity: { uin: '10001' } as IdentityService,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('GetUnidirectionalFriendList namespace', () => {
|
describe('GetUnidirectionalFriendList', () => {
|
||||||
it('declares 0xE17_0', () => {
|
it('uses the direct JSON request and response captured for this service', async () => {
|
||||||
expect(GetUnidirectionalFriendList.command).toBe(0xe17);
|
const list = [{ uint64_uin: '20002', extra: { keep: true } }];
|
||||||
expect(GetUnidirectionalFriendList.subCommand).toBe(0);
|
const deps = makeDeps({ ActionStatus: 'OK', ErrorCode: 0, rpt_block_list: list });
|
||||||
});
|
await expect(GetUnidirectionalFriendList.invoke(deps)).resolves.toEqual(list);
|
||||||
|
const [command, bytes] = deps.sendRawPacket.mock.calls[0]!;
|
||||||
it('overrides the wire name to MQUpdateSvc.OidbSvc.0xe17_0', async () => {
|
expect(command).toBe('MQUpdateSvc_com_qq_ti.web.OidbSvc.0xe17_0');
|
||||||
const deps = makeDeps({ rpt_block_list: [] });
|
expect(Buffer.from(bytes)).toEqual(
|
||||||
await GetUnidirectionalFriendList.invoke(deps);
|
Buffer.from([
|
||||||
expect(deps.sendRawPacket.mock.calls[0]![0]).toBe(
|
...v(2, 0),
|
||||||
'MQUpdateSvc_com_qq_ti.web.OidbSvc.0xe17_0',
|
...s(
|
||||||
|
3,
|
||||||
|
JSON.stringify({
|
||||||
|
uint64_uin: '10001',
|
||||||
|
uint64_top: 0,
|
||||||
|
uint32_req_num: 99,
|
||||||
|
bytes_cookies: '',
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
]),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('serialize', () => {
|
it('returns a verified empty list', async () => {
|
||||||
it('JSON-encodes the request body with the bot uin and fixed pagination', async () => {
|
await expect(GetUnidirectionalFriendList.invoke(makeDeps())).resolves.toEqual([]);
|
||||||
const deps = makeDeps({ rpt_block_list: [] });
|
|
||||||
await GetUnidirectionalFriendList.invoke(deps);
|
|
||||||
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
|
|
||||||
const env = protobuf_decode<OidbBase<Oidb0xe17Req>>(bytes);
|
|
||||||
const parsed = JSON.parse(env.body?.jsonBody ?? '{}');
|
|
||||||
expect(parsed).toEqual({
|
|
||||||
uint64_uin: '10001',
|
|
||||||
uint64_top: 0,
|
|
||||||
uint32_req_num: 99,
|
|
||||||
bytes_cookies: '',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('deserialize', () => {
|
it('surfaces JSON business failures instead of returning an empty list', async () => {
|
||||||
it('parses the embedded JSON body and returns rpt_block_list', () => {
|
const deps = makeDeps({
|
||||||
const out = GetUnidirectionalFriendList.deserialize({} as any, {
|
ActionStatus: 'FAIL',
|
||||||
jsonBody: JSON.stringify({ rpt_block_list: [{ uin: 10001 }, { uin: 10002 }] }),
|
ErrorCode: 302,
|
||||||
});
|
ErrorInfo: 'parse json failed',
|
||||||
expect(out).toEqual([{ uin: 10001 }, { uin: 10002 }]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns [] when rpt_block_list is absent', () => {
|
|
||||||
const out = GetUnidirectionalFriendList.deserialize({} as any, {
|
|
||||||
jsonBody: JSON.stringify({}),
|
|
||||||
});
|
|
||||||
expect(out).toEqual([]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('throws when jsonBody is empty / missing', () => {
|
|
||||||
expect(() => GetUnidirectionalFriendList.deserialize({} as any, {})).toThrow(
|
|
||||||
'get unidirectional friend list empty',
|
|
||||||
);
|
|
||||||
expect(() =>
|
|
||||||
GetUnidirectionalFriendList.deserialize({} as any, { jsonBody: '' }),
|
|
||||||
).toThrow('get unidirectional friend list empty');
|
|
||||||
});
|
});
|
||||||
|
await expect(GetUnidirectionalFriendList.invoke(deps)).rejects.toThrow(
|
||||||
|
'302 parse json failed',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('invoke (e2e)', () => {
|
it.each([
|
||||||
it('returns the parsed block list', async () => {
|
null,
|
||||||
const deps = makeDeps({ rpt_block_list: [{ uin: 999 }] });
|
{},
|
||||||
const out = await GetUnidirectionalFriendList.invoke(deps);
|
{ ActionStatus: 'OK', ErrorCode: 0 },
|
||||||
expect(out).toEqual([{ uin: 999 }]);
|
{ ActionStatus: 'OK', ErrorCode: 0, rpt_block_list: [null] },
|
||||||
|
{ ActionStatus: 'OK', ErrorCode: 0, rpt_block_list: {} },
|
||||||
|
])('rejects malformed response data (%j)', async (json) => {
|
||||||
|
await expect(GetUnidirectionalFriendList.invoke(makeDeps(json))).rejects.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('surfaces outer errors, invalid JSON, empty replies and transport failures', async () => {
|
||||||
|
const deps = makeDeps();
|
||||||
|
|
||||||
|
for (const [responseData, message] of [
|
||||||
|
[Buffer.from([...v(3, 5), ...s(5, 'denied')]), 'denied'],
|
||||||
|
[Buffer.from(s(4, '{')), 'JSON'],
|
||||||
|
[Buffer.from(v(1, 0xe17)), 'empty'],
|
||||||
|
[Buffer.alloc(0), 'empty'],
|
||||||
|
] as const) {
|
||||||
|
deps.sendRawPacket.mockResolvedValue({
|
||||||
|
success: true,
|
||||||
|
gotResponse: true,
|
||||||
|
errorCode: 0,
|
||||||
|
errorMessage: '',
|
||||||
|
responseData,
|
||||||
|
});
|
||||||
|
await expect(GetUnidirectionalFriendList.invoke(deps)).rejects.toThrow(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
deps.sendRawPacket.mockResolvedValue({
|
||||||
|
success: false,
|
||||||
|
gotResponse: false,
|
||||||
|
errorCode: 5,
|
||||||
|
errorMessage: 'disconnected',
|
||||||
});
|
});
|
||||||
|
await expect(GetUnidirectionalFriendList.invoke(deps)).rejects.toThrow('disconnected');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user