Skip to content

Commit

Permalink
Fix crash on invalid packet type. Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
voronin-opensoft authored and voronind committed Feb 13, 2017
1 parent c39a775 commit 7eacdd9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion engineio/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ def poll(self):

def receive(self, pkt):
"""Receive packet from the client."""
packet_name = packet.packet_names[pkt.packet_type] \
if pkt.packet_type < len(packet.packet_names) else 'UNKNOWN'
self.server.logger.info('%s: Received packet %s data %s',
self.sid, packet.packet_names[pkt.packet_type],
self.sid, packet_name,
pkt.data if not isinstance(pkt.data, bytes)
else '<binary>')
if pkt.packet_type == packet.PING:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ def test_upgrade_no_upgrade_packet(self):
self.assertEqual(s.queue.get().packet_type, packet.NOOP)
self.assertFalse(s.upgraded)

def test_invalid_packet_type(self):
mock_server = self._get_mock_server()
s = socket.Socket(mock_server, 'sid')
pkt = packet.Packet(packet_type=99)
self.assertRaises(ValueError, lambda: s.receive(pkt))

def test_upgrade_not_supported(self):
mock_server = self._get_mock_server()
mock_server._async['websocket'] = None
Expand Down

0 comments on commit 7eacdd9

Please sign in to comment.