handle blank ssdp packets and those with only one line
This commit is contained in:
parent
e175e7d4e3
commit
cfce30fa3a
3 changed files with 14 additions and 2 deletions
|
@ -189,6 +189,8 @@ class SSDPDatagram(object):
|
|||
@classmethod
|
||||
def _from_string(cls, datagram: str):
|
||||
lines = [l for l in datagram.split(line_separator) if l]
|
||||
if not lines:
|
||||
return
|
||||
if lines[0] == cls._start_lines[cls._M_SEARCH]:
|
||||
return cls._from_request(lines[1:])
|
||||
if lines[0] in [cls._start_lines[cls._NOTIFY], cls._start_lines[cls._NOTIFY] + " "]:
|
||||
|
|
|
@ -28,6 +28,18 @@ class TestSSDPDatagram(unittest.TestCase):
|
|||
with self.assertRaises(UPnPError):
|
||||
SSDPDatagram.decode(packet)
|
||||
|
||||
def test_fail_to_decode_blank(self):
|
||||
packet = b''
|
||||
|
||||
with self.assertRaises(UPnPError):
|
||||
SSDPDatagram.decode(packet)
|
||||
|
||||
def test_fail_to_decode_one_line(self):
|
||||
packet = b'M-SEARCH * HTTP/1.1'
|
||||
|
||||
with self.assertRaises(UPnPError):
|
||||
SSDPDatagram.decode(packet)
|
||||
|
||||
def test_cli_args(self):
|
||||
datagram_args = OrderedDict([
|
||||
('Host', "{}:{}".format('239.255.255.250', 1900)),
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
from aioupnp.fault import UPnPError
|
||||
from aioupnp.protocols.scpd import scpd_post, scpd_get
|
||||
from tests import TestBase
|
||||
from tests.mocks import mock_tcp_endpoint_factory
|
||||
from collections import OrderedDict
|
||||
|
|
Loading…
Reference in a new issue