This commit is contained in:
Jack Robison 2018-10-09 11:06:39 -04:00
parent 910bb3485c
commit 1c20862b92
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 19 additions and 8 deletions

View file

@ -39,7 +39,7 @@ class SSDPProtocol(MulticastProtocol):
# D-Link works with both # D-Link works with both
# Cisco only works with quotes # Cisco only works with quotes
self.send_m_search_packet(service, address, '"%s"' % SSDP_DISCOVER) self.send_m_search_packet(service, address, '\"%s\"' % SSDP_DISCOVER)
# DD-WRT only works without quotes # DD-WRT only works without quotes
self.send_m_search_packet(service, address, SSDP_DISCOVER) self.send_m_search_packet(service, address, SSDP_DISCOVER)

View file

@ -1,16 +1,16 @@
import unittest import unittest
from aioupnp.serialization.ssdp import SSDPDatagram from aioupnp.serialization.ssdp import SSDPDatagram
from aioupnp.fault import UPnPError from aioupnp.fault import UPnPError
from aioupnp.constants import UPNP_ORG_IGD from aioupnp.constants import UPNP_ORG_IGD, SSDP_DISCOVER
class TestParseMSearchRequestWithQuotes(unittest.TestCase): class TestParseMSearchRequestWithQuotes(unittest.TestCase):
datagram = b'M-SEARCH * HTTP/1.1\r\n' \ datagram = b"M-SEARCH * HTTP/1.1\r\n" \
b'HOST: 239.255.255.250:1900\r\n' \ b"HOST: 239.255.255.250:1900\r\n" \
b'ST: urn:schemas-upnp-org:device:InternetGatewayDevice:1\r\n' \ b"ST: urn:schemas-upnp-org:device:InternetGatewayDevice:1\r\n" \
b'MAN: "ssdp:discover"\r\n' \ b"MAN: \"ssdp:discover\"\r\n" \
b'MX: 1\r\n' \ b"MX: 1\r\n" \
b'\r\n' b"\r\n"
def test_parse_m_search(self): def test_parse_m_search(self):
packet = SSDPDatagram.decode(self.datagram) packet = SSDPDatagram.decode(self.datagram)
@ -20,6 +20,17 @@ class TestParseMSearchRequestWithQuotes(unittest.TestCase):
self.assertEqual(packet.man, '"ssdp:discover"') self.assertEqual(packet.man, '"ssdp:discover"')
self.assertEqual(packet.mx, 1) self.assertEqual(packet.mx, 1)
def test_serialize_m_search(self):
packet = SSDPDatagram.decode(self.datagram)
self.assertEqual(packet.encode().encode(), self.datagram)
self.assertEqual(
self.datagram, SSDPDatagram(
SSDPDatagram._M_SEARCH, host="{}:{}".format('239.255.255.250', 1900), st=UPNP_ORG_IGD,
man='\"%s\"' % SSDP_DISCOVER, mx=1
).encode().encode()
)
class TestParseMSearchRequestWithoutQuotes(unittest.TestCase): class TestParseMSearchRequestWithoutQuotes(unittest.TestCase):
datagram = b'M-SEARCH * HTTP/1.1\r\n' \ datagram = b'M-SEARCH * HTTP/1.1\r\n' \