Exemplo n.º 1
0
def test_welcome_decode():
    packet = b'\xef\xbe\xad\xde+\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\xda\xb3\x04m\x0f\x00\x00\x00Welcome to eyes'
    decoded, trailer = p.decode(packet)
    eq_(len(decoded), 1)
    decoded = decoded[0]
    assert isinstance(decoded, p.WelcomePacket)
    eq_(decoded.message, 'Welcome to eyes')
Exemplo n.º 2
0
def test_welcome_decode():
    packet = b'\xef\xbe\xad\xde+\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\xda\xb3\x04m\x0f\x00\x00\x00Welcome to eyes'
    decoded, trailer = p.decode(packet)
    eq_(len(decoded), 1)
    decoded = decoded[0]
    assert isinstance(decoded, p.WelcomePacket)
    eq_(decoded.message, 'Welcome to eyes')
Exemplo n.º 3
0
def test_version_decode():
    packet = b'\xef\xbe\xad\xde\x2c\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x18\x00\x00\x00\x4a\xe7\x48\xe5\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00'
    decoded, trailer = p.decode(packet)
    eq_(len(decoded), 1)
    decoded = decoded[0]
    assert isinstance(decoded, p.VersionPacket)
    eq_(decoded.major, 2)
    eq_(decoded.minor, 1)
    eq_(decoded.patch, 1)
Exemplo n.º 4
0
def test_version_decode():
    packet = b'\xef\xbe\xad\xde\x2c\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x18\x00\x00\x00\x4a\xe7\x48\xe5\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00'
    decoded, trailer = p.decode(packet)
    eq_(len(decoded), 1)
    decoded = decoded[0]
    assert isinstance(decoded, p.VersionPacket)
    eq_(decoded.major, 2)
    eq_(decoded.minor, 1)
    eq_(decoded.patch, 1)
Exemplo n.º 5
0
def test_undecoded_round_trip():
    packet = (b'\xef\xbe\xad\xde' # packet heading
              b'\x1c\x00\x00\x00' # total packet length
              b'\x02\x00\x00\x00' # origin
              b'\x00\x00\x00\x00' # padding
              b'\x08\x00\x00\x00' # remaining length
              b'\xdd\xcc\xbb\xaa' # packet type
              b'\xfe\x83\x4c\x00') # packet data
    decoded, rest = p.decode(packet, provenance=p.PacketProvenance.client)
    eq_(len(decoded), 1)
    eq_(rest, b'')
    encoded = p.encode(decoded[0], provenance=p.PacketProvenance.client)
    eq_(packet, encoded)
Exemplo n.º 6
0
def test_undecoded_round_trip():
    packet = (
        b'\xef\xbe\xad\xde'  # packet heading
        b'\x1c\x00\x00\x00'  # total packet length
        b'\x02\x00\x00\x00'  # origin
        b'\x00\x00\x00\x00'  # padding
        b'\x08\x00\x00\x00'  # remaining length
        b'\xdd\xcc\xbb\xaa'  # packet type
        b'\xfe\x83\x4c\x00')  # packet data
    decoded, rest = p.decode(packet, provenance=p.PacketProvenance.client)
    eq_(len(decoded), 1)
    eq_(rest, b'')
    encoded = p.encode(decoded[0], provenance=p.PacketProvenance.client)
    eq_(packet, encoded)
Exemplo n.º 7
0
 def eat(self, data):
     self.buffer += data
     packets, self.buffer = packet.decode(self.buffer,
                                          provenance=self.provenance)
     return packets
Exemplo n.º 8
0
 def eat(self, data):
     self.buffer += data
     packets, self.buffer = packet.decode(self.buffer, provenance=self.provenance)
     return packets
Exemplo n.º 9
0
def test_double_decode():
    packet = b'\xef\xbe\xad\xde+\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\xda\xb3\x04m\x0f\x00\x00\x00Welcome to eyes'
    packet = packet + packet
    decoded, trailer = p.decode(packet)
    eq_(len(decoded), 2)
    eq_(trailer, b'')
Exemplo n.º 10
0
def test_overflow_payload():
    packet = b'\xef\xbe\xad\xde+\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\xda\xb3\x04m\x0f\x00\x00\x00Welcome to eyes\xef'
    decoded, trailer = p.decode(packet)
    eq_(trailer, b'\xef')
Exemplo n.º 11
0
def test_truncated_payload():
    packet = b'\xef\xbe\xad\xde\x27\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x13\x00\x00\x00\xda\xb3\x04\x6dWelcome to '
    decoded, trailer = p.decode(packet)
    eq_(decoded, [])
    eq_(trailer, packet)
Exemplo n.º 12
0
def test_truncated_header():
    packet = b'\xef\xbe\xad\xde\x27\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00'
    decoded, trailer = p.decode(packet)
    eq_(decoded, [])
    eq_(trailer, packet)
Exemplo n.º 13
0
def test_double_decode():
    packet = b'\xef\xbe\xad\xde+\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\xda\xb3\x04m\x0f\x00\x00\x00Welcome to eyes'
    packet = packet + packet
    decoded, trailer = p.decode(packet)
    eq_(len(decoded), 2)
    eq_(trailer, b'')
Exemplo n.º 14
0
def test_overflow_payload():
    packet = b'\xef\xbe\xad\xde+\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\xda\xb3\x04m\x0f\x00\x00\x00Welcome to eyes\xef'
    decoded, trailer = p.decode(packet)
    eq_(trailer, b'\xef')
Exemplo n.º 15
0
def test_truncated_payload():
    packet = b'\xef\xbe\xad\xde\x27\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x13\x00\x00\x00\xda\xb3\x04\x6dWelcome to '
    decoded, trailer = p.decode(packet)
    eq_(decoded, [])
    eq_(trailer, packet)
Exemplo n.º 16
0
def test_truncated_header():
    packet = b'\xef\xbe\xad\xde\x27\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00'
    decoded, trailer = p.decode(packet)
    eq_(decoded, [])
    eq_(trailer, packet)