Files
WoW-Hybrid-gateway/tests/party_invite_serializer_fixture.py

28 lines
1.5 KiB
Python

"""Independent expected wire for the original PartyInvite writer."""
import struct
import subprocess
import sys
from native_codec_driver import require_optional_cli
codec = sys.argv[1]
require_optional_cli(codec)
name = b'Gatewayref'
realm, address, guid = 70, 0x10046, 4514
realm_name, normalized = b'Local Realm', b'LocalRealm'
wire = struct.pack('<HIQ', realm, address, guid) + name + b'\0' + realm_name + b'\0'
raw_guid = struct.pack('<QQ', guid, (2 << 58) | (realm << 42))
mask = sum((v != 0) << i for i, v in enumerate(raw_guid))
packed_guid = struct.pack('<H', mask) + bytes(x for x in raw_guid if x)
bits = '100000' + f'{len(name):06b}' + '0' * 9 + '0'
bits += '0' * (-len(bits) % 8)
header = bytes(int(bits[i:i + 8], 2) for i in range(0, len(bits), 8))
realm_bits = '10' + f'{len(realm_name):08b}' + f'{len(normalized):08b}' + '000000'
realm_header = bytes(int(realm_bits[i:i+8], 2) for i in range(0, 24, 8))
expected = (header + packed_guid + b'\0\0' + b'\0\0' + struct.pack('<I', address)
+ realm_header + realm_name + normalized + b'\0' + b'\0' * 8 + name)
p = subprocess.run([codec, '--party-invite'], input=wire, capture_output=True, timeout=15)
assert p.returncode == 0 and p.stdout == expected, (p.returncode, p.stderr, p.stdout.hex(), expected.hex())
for data in [wire[:-1], wire + b'\0', struct.pack('<HIQ', 0, address, guid) + name + b'\0']:
assert subprocess.run([codec, '--party-invite'], input=data, capture_output=True, timeout=15).returncode != 0
print('PASS original PartyInvite writer framing and bounds')