twnet_parser/tests/packet_header7_test.py

64 lines
2.1 KiB
Python

from twnet_parser.packet import *
# # packet = parse(b'\x10\x10\x00\x04\x9a\xcb9\xc9') # 0.6 close
def test_parse_7_close():
packet = parse(b'\x04\x0a\x00\xcf\x2e\xde\x1d\04') # 0.7 close
assert packet.version == '0.7'
assert packet.header.size == 0
assert packet.header.ack == 10
assert packet.header.token == b'\xcf.\xde\x1d'
assert packet.header.num_chunks == 0
assert packet.header.flags.control == True
assert packet.header.flags.resend == False
assert packet.header.flags.compression == False
assert packet.header.flags.connless == False
assert packet.messages[0].name == 'close'
assert len(packet.messages) == 1
def test_parse_7_close_fake_resend():
packet = parse(b'\x0c\x0a\x00\xaa\xbb\xcc\xdd\04') # 0.7 close
# ^
# resending ctrl close
# probably never happens
assert packet.version == '0.7'
assert packet.header.size == 0
assert packet.header.ack == 10
assert packet.header.token == b'\xaa\xbb\xcc\xdd'
assert packet.header.num_chunks == 0
assert packet.header.flags.control == True
assert packet.header.flags.resend == True
assert packet.header.flags.compression == False
assert packet.header.flags.connless == False
assert packet.messages[0].name == 'close'
assert len(packet.messages) == 1
def test_parse_7_close_fake_num_chunks():
packet = parse(b'\x04\x0a\x01\xcf\xee\xde\x2d\04') # 0.7 close
# ^
# 1 chunk makes no sense
# because control messages should
# always have 0 chunks
assert packet.version == '0.7'
assert packet.header.size == 0
assert packet.header.ack == 10
assert packet.header.token == b'\xcf\xee\xde\x2d'
assert packet.header.num_chunks == 1
assert packet.header.flags.control == True
assert packet.header.flags.resend == False
assert packet.header.flags.compression == False
assert packet.header.flags.connless == False
assert packet.messages[0].name == 'close'
assert len(packet.messages) == 1