tests: Explicit str/bytes conversion for socket operations for python3
Signed-off-by: Masashi Honma <masashi.honma@gmail.com> Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
6395b9eb3e
commit
cc02ce96cf
4 changed files with 76 additions and 72 deletions
|
@ -5994,15 +5994,15 @@ def test_ap_wpa2_eap_sim_db(dev, apdev, params):
|
||||||
|
|
||||||
class test_handler(SocketServer.DatagramRequestHandler):
|
class test_handler(SocketServer.DatagramRequestHandler):
|
||||||
def handle(self):
|
def handle(self):
|
||||||
data = self.request[0].strip()
|
data = self.request[0].decode().strip()
|
||||||
socket = self.request[1]
|
socket = self.request[1]
|
||||||
logger.debug("Received hlr_auc_gw request: " + data)
|
logger.debug("Received hlr_auc_gw request: " + data)
|
||||||
# EAP-SIM DB: Failed to parse response string
|
# EAP-SIM DB: Failed to parse response string
|
||||||
socket.sendto("FOO", self.client_address)
|
socket.sendto(b"FOO", self.client_address)
|
||||||
# EAP-SIM DB: Failed to parse response string
|
# EAP-SIM DB: Failed to parse response string
|
||||||
socket.sendto("FOO 1", self.client_address)
|
socket.sendto(b"FOO 1", self.client_address)
|
||||||
# EAP-SIM DB: Unknown external response
|
# EAP-SIM DB: Unknown external response
|
||||||
socket.sendto("FOO 1 2", self.client_address)
|
socket.sendto(b"FOO 1 2", self.client_address)
|
||||||
logger.info("No proper response - wait for pending eap_sim_db request timeout")
|
logger.info("No proper response - wait for pending eap_sim_db request timeout")
|
||||||
|
|
||||||
server = SocketServer.UnixDatagramServer(sockpath, test_handler)
|
server = SocketServer.UnixDatagramServer(sockpath, test_handler)
|
||||||
|
@ -6020,7 +6020,7 @@ def test_ap_wpa2_eap_sim_db(dev, apdev, params):
|
||||||
|
|
||||||
class test_handler2(SocketServer.DatagramRequestHandler):
|
class test_handler2(SocketServer.DatagramRequestHandler):
|
||||||
def handle(self):
|
def handle(self):
|
||||||
data = self.request[0].strip()
|
data = self.request[0].decode().strip()
|
||||||
socket = self.request[1]
|
socket = self.request[1]
|
||||||
logger.debug("Received hlr_auc_gw request: " + data)
|
logger.debug("Received hlr_auc_gw request: " + data)
|
||||||
fname = os.path.join(params['logdir'],
|
fname = os.path.join(params['logdir'],
|
||||||
|
@ -6031,7 +6031,7 @@ def test_ap_wpa2_eap_sim_db(dev, apdev, params):
|
||||||
res = cmd.stdout.read().decode().strip()
|
res = cmd.stdout.read().decode().strip()
|
||||||
cmd.stdout.close()
|
cmd.stdout.close()
|
||||||
logger.debug("hlr_auc_gw response: " + res)
|
logger.debug("hlr_auc_gw response: " + res)
|
||||||
socket.sendto(res, self.client_address)
|
socket.sendto(res.encode(), self.client_address)
|
||||||
|
|
||||||
server.RequestHandlerClass = test_handler2
|
server.RequestHandlerClass = test_handler2
|
||||||
|
|
||||||
|
|
|
@ -2486,10 +2486,10 @@ def ssdp_send(msg, no_recv=False):
|
||||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
|
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
|
||||||
sock.bind(("127.0.0.1", 0))
|
sock.bind(("127.0.0.1", 0))
|
||||||
sock.sendto(msg, ("239.255.255.250", 1900))
|
sock.sendto(msg.encode(), ("239.255.255.250", 1900))
|
||||||
if no_recv:
|
if no_recv:
|
||||||
return None
|
return None
|
||||||
return sock.recv(1000)
|
return sock.recv(1000).decode()
|
||||||
|
|
||||||
def ssdp_send_msearch(st, no_recv=False):
|
def ssdp_send_msearch(st, no_recv=False):
|
||||||
msg = '\r\n'.join([
|
msg = '\r\n'.join([
|
||||||
|
@ -2557,7 +2557,7 @@ def test_ap_wps_ssdp_invalid_msearch(dev, apdev):
|
||||||
'MAN: "ssdp:discover"',
|
'MAN: "ssdp:discover"',
|
||||||
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
||||||
'', ''])
|
'', ''])
|
||||||
sock.sendto(msg, ("239.255.255.250", 1900))
|
sock.sendto(msg.encode(), ("239.255.255.250", 1900))
|
||||||
|
|
||||||
logger.debug("Negative MX")
|
logger.debug("Negative MX")
|
||||||
msg = '\r\n'.join([
|
msg = '\r\n'.join([
|
||||||
|
@ -2567,7 +2567,7 @@ def test_ap_wps_ssdp_invalid_msearch(dev, apdev):
|
||||||
'MAN: "ssdp:discover"',
|
'MAN: "ssdp:discover"',
|
||||||
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
||||||
'', ''])
|
'', ''])
|
||||||
sock.sendto(msg, ("239.255.255.250", 1900))
|
sock.sendto(msg.encode(), ("239.255.255.250", 1900))
|
||||||
|
|
||||||
logger.debug("Invalid MX")
|
logger.debug("Invalid MX")
|
||||||
msg = '\r\n'.join([
|
msg = '\r\n'.join([
|
||||||
|
@ -2577,7 +2577,7 @@ def test_ap_wps_ssdp_invalid_msearch(dev, apdev):
|
||||||
'MAN: "ssdp:discover"',
|
'MAN: "ssdp:discover"',
|
||||||
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
||||||
'', ''])
|
'', ''])
|
||||||
sock.sendto(msg, ("239.255.255.250", 1900))
|
sock.sendto(msg.encode(), ("239.255.255.250", 1900))
|
||||||
|
|
||||||
logger.debug("Missing MAN")
|
logger.debug("Missing MAN")
|
||||||
msg = '\r\n'.join([
|
msg = '\r\n'.join([
|
||||||
|
@ -2586,7 +2586,7 @@ def test_ap_wps_ssdp_invalid_msearch(dev, apdev):
|
||||||
'MX: 1',
|
'MX: 1',
|
||||||
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
||||||
'', ''])
|
'', ''])
|
||||||
sock.sendto(msg, ("239.255.255.250", 1900))
|
sock.sendto(msg.encode(), ("239.255.255.250", 1900))
|
||||||
|
|
||||||
logger.debug("Invalid MAN")
|
logger.debug("Invalid MAN")
|
||||||
msg = '\r\n'.join([
|
msg = '\r\n'.join([
|
||||||
|
@ -2596,7 +2596,7 @@ def test_ap_wps_ssdp_invalid_msearch(dev, apdev):
|
||||||
'MAN: foo',
|
'MAN: foo',
|
||||||
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
||||||
'', ''])
|
'', ''])
|
||||||
sock.sendto(msg, ("239.255.255.250", 1900))
|
sock.sendto(msg.encode(), ("239.255.255.250", 1900))
|
||||||
msg = '\r\n'.join([
|
msg = '\r\n'.join([
|
||||||
'M-SEARCH * HTTP/1.1',
|
'M-SEARCH * HTTP/1.1',
|
||||||
'HOST: 239.255.255.250:1900',
|
'HOST: 239.255.255.250:1900',
|
||||||
|
@ -2604,7 +2604,7 @@ def test_ap_wps_ssdp_invalid_msearch(dev, apdev):
|
||||||
'MAN; "ssdp:discover"',
|
'MAN; "ssdp:discover"',
|
||||||
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
||||||
'', ''])
|
'', ''])
|
||||||
sock.sendto(msg, ("239.255.255.250", 1900))
|
sock.sendto(msg.encode(), ("239.255.255.250", 1900))
|
||||||
|
|
||||||
logger.debug("Missing HOST")
|
logger.debug("Missing HOST")
|
||||||
msg = '\r\n'.join([
|
msg = '\r\n'.join([
|
||||||
|
@ -2613,7 +2613,7 @@ def test_ap_wps_ssdp_invalid_msearch(dev, apdev):
|
||||||
'MX: 1',
|
'MX: 1',
|
||||||
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
||||||
'', ''])
|
'', ''])
|
||||||
sock.sendto(msg, ("239.255.255.250", 1900))
|
sock.sendto(msg.encode(), ("239.255.255.250", 1900))
|
||||||
|
|
||||||
logger.debug("Missing ST")
|
logger.debug("Missing ST")
|
||||||
msg = '\r\n'.join([
|
msg = '\r\n'.join([
|
||||||
|
@ -2622,7 +2622,7 @@ def test_ap_wps_ssdp_invalid_msearch(dev, apdev):
|
||||||
'MAN: "ssdp:discover"',
|
'MAN: "ssdp:discover"',
|
||||||
'MX: 1',
|
'MX: 1',
|
||||||
'', ''])
|
'', ''])
|
||||||
sock.sendto(msg, ("239.255.255.250", 1900))
|
sock.sendto(msg.encode(), ("239.255.255.250", 1900))
|
||||||
|
|
||||||
logger.debug("Mismatching ST")
|
logger.debug("Mismatching ST")
|
||||||
msg = '\r\n'.join([
|
msg = '\r\n'.join([
|
||||||
|
@ -2632,7 +2632,7 @@ def test_ap_wps_ssdp_invalid_msearch(dev, apdev):
|
||||||
'MX: 1',
|
'MX: 1',
|
||||||
'ST: uuid:16d5f8a9-4ee4-4f5e-81f9-cc6e2f47f42d',
|
'ST: uuid:16d5f8a9-4ee4-4f5e-81f9-cc6e2f47f42d',
|
||||||
'', ''])
|
'', ''])
|
||||||
sock.sendto(msg, ("239.255.255.250", 1900))
|
sock.sendto(msg.encode(), ("239.255.255.250", 1900))
|
||||||
msg = '\r\n'.join([
|
msg = '\r\n'.join([
|
||||||
'M-SEARCH * HTTP/1.1',
|
'M-SEARCH * HTTP/1.1',
|
||||||
'HOST: 239.255.255.250:1900',
|
'HOST: 239.255.255.250:1900',
|
||||||
|
@ -2640,7 +2640,7 @@ def test_ap_wps_ssdp_invalid_msearch(dev, apdev):
|
||||||
'MX: 1',
|
'MX: 1',
|
||||||
'ST: foo:bar',
|
'ST: foo:bar',
|
||||||
'', ''])
|
'', ''])
|
||||||
sock.sendto(msg, ("239.255.255.250", 1900))
|
sock.sendto(msg.encode(), ("239.255.255.250", 1900))
|
||||||
msg = '\r\n'.join([
|
msg = '\r\n'.join([
|
||||||
'M-SEARCH * HTTP/1.1',
|
'M-SEARCH * HTTP/1.1',
|
||||||
'HOST: 239.255.255.250:1900',
|
'HOST: 239.255.255.250:1900',
|
||||||
|
@ -2648,7 +2648,7 @@ def test_ap_wps_ssdp_invalid_msearch(dev, apdev):
|
||||||
'MX: 1',
|
'MX: 1',
|
||||||
'ST: foobar',
|
'ST: foobar',
|
||||||
'', ''])
|
'', ''])
|
||||||
sock.sendto(msg, ("239.255.255.250", 1900))
|
sock.sendto(msg.encode(), ("239.255.255.250", 1900))
|
||||||
|
|
||||||
logger.debug("Invalid ST")
|
logger.debug("Invalid ST")
|
||||||
msg = '\r\n'.join([
|
msg = '\r\n'.join([
|
||||||
|
@ -2658,7 +2658,7 @@ def test_ap_wps_ssdp_invalid_msearch(dev, apdev):
|
||||||
'MX: 1',
|
'MX: 1',
|
||||||
'ST; urn:schemas-wifialliance-org:device:WFADevice:1',
|
'ST; urn:schemas-wifialliance-org:device:WFADevice:1',
|
||||||
'', ''])
|
'', ''])
|
||||||
sock.sendto(msg, ("239.255.255.250", 1900))
|
sock.sendto(msg.encode(), ("239.255.255.250", 1900))
|
||||||
|
|
||||||
logger.debug("Invalid M-SEARCH")
|
logger.debug("Invalid M-SEARCH")
|
||||||
msg = '\r\n'.join([
|
msg = '\r\n'.join([
|
||||||
|
@ -2668,7 +2668,7 @@ def test_ap_wps_ssdp_invalid_msearch(dev, apdev):
|
||||||
'MX: 1',
|
'MX: 1',
|
||||||
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
||||||
'', ''])
|
'', ''])
|
||||||
sock.sendto(msg, ("239.255.255.250", 1900))
|
sock.sendto(msg.encode(), ("239.255.255.250", 1900))
|
||||||
msg = '\r\n'.join([
|
msg = '\r\n'.join([
|
||||||
'M-SEARCH-* HTTP/1.1',
|
'M-SEARCH-* HTTP/1.1',
|
||||||
'HOST: 239.255.255.250:1900',
|
'HOST: 239.255.255.250:1900',
|
||||||
|
@ -2676,10 +2676,10 @@ def test_ap_wps_ssdp_invalid_msearch(dev, apdev):
|
||||||
'MX: 1',
|
'MX: 1',
|
||||||
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
||||||
'', ''])
|
'', ''])
|
||||||
sock.sendto(msg, ("239.255.255.250", 1900))
|
sock.sendto(msg.encode(), ("239.255.255.250", 1900))
|
||||||
|
|
||||||
logger.debug("Invalid message format")
|
logger.debug("Invalid message format")
|
||||||
sock.sendto("NOTIFY * HTTP/1.1", ("239.255.255.250", 1900))
|
sock.sendto(b"NOTIFY * HTTP/1.1", ("239.255.255.250", 1900))
|
||||||
msg = '\r'.join([
|
msg = '\r'.join([
|
||||||
'M-SEARCH * HTTP/1.1',
|
'M-SEARCH * HTTP/1.1',
|
||||||
'HOST: 239.255.255.250:1900',
|
'HOST: 239.255.255.250:1900',
|
||||||
|
@ -2687,7 +2687,7 @@ def test_ap_wps_ssdp_invalid_msearch(dev, apdev):
|
||||||
'MX: 1',
|
'MX: 1',
|
||||||
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
||||||
'', ''])
|
'', ''])
|
||||||
sock.sendto(msg, ("239.255.255.250", 1900))
|
sock.sendto(msg.encode(), ("239.255.255.250", 1900))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = sock.recv(1000)
|
r = sock.recv(1000)
|
||||||
|
@ -2703,7 +2703,7 @@ def test_ap_wps_ssdp_invalid_msearch(dev, apdev):
|
||||||
'MX: 1',
|
'MX: 1',
|
||||||
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
|
||||||
'', ''])
|
'', ''])
|
||||||
sock.sendto(msg, ("239.255.255.250", 1900))
|
sock.sendto(msg.encode(), ("239.255.255.250", 1900))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = sock.recv(1000)
|
r = sock.recv(1000)
|
||||||
|
@ -2729,11 +2729,11 @@ def test_ap_wps_ssdp_burst(dev, apdev):
|
||||||
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
|
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
|
||||||
sock.bind(("127.0.0.1", 0))
|
sock.bind(("127.0.0.1", 0))
|
||||||
for i in range(0, 25):
|
for i in range(0, 25):
|
||||||
sock.sendto(msg, ("239.255.255.250", 1900))
|
sock.sendto(msg.encode(), ("239.255.255.250", 1900))
|
||||||
resp = 0
|
resp = 0
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
r = sock.recv(1000)
|
r = sock.recv(1000).decode()
|
||||||
if not r.startswith("HTTP/1.1 200 OK\r\n"):
|
if not r.startswith("HTTP/1.1 200 OK\r\n"):
|
||||||
raise Exception("Unexpected message: " + r)
|
raise Exception("Unexpected message: " + r)
|
||||||
resp += 1
|
resp += 1
|
||||||
|
@ -2747,10 +2747,10 @@ def test_ap_wps_ssdp_burst(dev, apdev):
|
||||||
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
|
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
|
||||||
sock.bind(("127.0.0.1", 0))
|
sock.bind(("127.0.0.1", 0))
|
||||||
for i in range(0, 25):
|
for i in range(0, 25):
|
||||||
sock.sendto(msg, ("239.255.255.250", 1900))
|
sock.sendto(msg.encode(), ("239.255.255.250", 1900))
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
r = sock.recv(1000)
|
r = sock.recv(1000).decode()
|
||||||
if ap_uuid in r:
|
if ap_uuid in r:
|
||||||
break
|
break
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
|
@ -3434,10 +3434,10 @@ def test_ap_wps_upnp_http_proto_chunked(dev, apdev):
|
||||||
conn.putrequest("POST", "hello")
|
conn.putrequest("POST", "hello")
|
||||||
conn.putheader('Transfer-Encoding', 'chunked')
|
conn.putheader('Transfer-Encoding', 'chunked')
|
||||||
conn.endheaders()
|
conn.endheaders()
|
||||||
conn.send("a\r\nabcdefghij\r\n")
|
conn.send(b"a\r\nabcdefghij\r\n")
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
conn.send("2\r\nkl\r\n")
|
conn.send(b"2\r\nkl\r\n")
|
||||||
conn.send("0\r\n\r\n")
|
conn.send(b"0\r\n\r\n")
|
||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
if resp.status != 404:
|
if resp.status != 404:
|
||||||
raise Exception("Unexpected HTTP response: %d" % resp.status)
|
raise Exception("Unexpected HTTP response: %d" % resp.status)
|
||||||
|
@ -3449,8 +3449,8 @@ def test_ap_wps_upnp_http_proto_chunked(dev, apdev):
|
||||||
completed = False
|
completed = False
|
||||||
try:
|
try:
|
||||||
for i in range(20000):
|
for i in range(20000):
|
||||||
conn.send("1\r\nZ\r\n")
|
conn.send(b"1\r\nZ\r\n")
|
||||||
conn.send("0\r\n\r\n")
|
conn.send(b"0\r\n\r\n")
|
||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
completed = True
|
completed = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -3957,49 +3957,51 @@ def _test_ap_wps_er_ssdp_proto(dev, apdev):
|
||||||
if "OK" not in dev[0].request("WPS_ER_START ifname=lo 1.2.3.4"):
|
if "OK" not in dev[0].request("WPS_ER_START ifname=lo 1.2.3.4"):
|
||||||
raise Exception("WPS_ER_START with filter failed")
|
raise Exception("WPS_ER_START with filter failed")
|
||||||
(msg,addr) = sock.recvfrom(1000)
|
(msg,addr) = sock.recvfrom(1000)
|
||||||
|
msg = msg.decode()
|
||||||
logger.debug("Received SSDP message from %s: %s" % (str(addr), msg))
|
logger.debug("Received SSDP message from %s: %s" % (str(addr), msg))
|
||||||
if "M-SEARCH" not in msg:
|
if "M-SEARCH" not in msg:
|
||||||
raise Exception("Not an M-SEARCH")
|
raise Exception("Not an M-SEARCH")
|
||||||
sock.sendto("FOO", addr)
|
sock.sendto(b"FOO", addr)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
dev[0].request("WPS_ER_STOP")
|
dev[0].request("WPS_ER_STOP")
|
||||||
|
|
||||||
dev[0].request("WPS_ER_START ifname=lo")
|
dev[0].request("WPS_ER_START ifname=lo")
|
||||||
(msg,addr) = sock.recvfrom(1000)
|
(msg,addr) = sock.recvfrom(1000)
|
||||||
|
msg = msg.decode()
|
||||||
logger.debug("Received SSDP message from %s: %s" % (str(addr), msg))
|
logger.debug("Received SSDP message from %s: %s" % (str(addr), msg))
|
||||||
if "M-SEARCH" not in msg:
|
if "M-SEARCH" not in msg:
|
||||||
raise Exception("Not an M-SEARCH")
|
raise Exception("Not an M-SEARCH")
|
||||||
sock.sendto("FOO", addr)
|
sock.sendto(b"FOO", addr)
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nFOO\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\nFOO\r\n\r\n", addr)
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nNTS:foo\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\nNTS:foo\r\n\r\n", addr)
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nNTS:ssdp:byebye\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\nNTS:ssdp:byebye\r\n\r\n", addr)
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\ncache-control: foo=1\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\ncache-control: foo=1\r\n\r\n", addr)
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\ncache-control: max-age=1\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\ncache-control: max-age=1\r\n\r\n", addr)
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nusn:\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\nusn:\r\n\r\n", addr)
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nusn:foo\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\nusn:foo\r\n\r\n", addr)
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nusn: uuid:\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\nusn: uuid:\r\n\r\n", addr)
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nusn: uuid: \r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\nusn: uuid: \r\n\r\n", addr)
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nusn: uuid: foo\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\nusn: uuid: foo\r\n\r\n", addr)
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\n\r\n", addr)
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nNTS:ssdp:byebye\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nNTS:ssdp:byebye\r\n\r\n", addr)
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:foo\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:foo\r\n\r\n", addr)
|
||||||
with alloc_fail(dev[0], 1, "wps_er_ap_add"):
|
with alloc_fail(dev[0], 1, "wps_er_ap_add"):
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:foo\r\ncache-control:max-age=1\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:foo\r\ncache-control:max-age=1\r\n\r\n", addr)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
with alloc_fail(dev[0], 2, "wps_er_ap_add"):
|
with alloc_fail(dev[0], 2, "wps_er_ap_add"):
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:foo\r\ncache-control:max-age=1\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:foo\r\ncache-control:max-age=1\r\n\r\n", addr)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
# Add an AP with bogus URL
|
# Add an AP with bogus URL
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:foo\r\ncache-control:max-age=1\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:foo\r\ncache-control:max-age=1\r\n\r\n", addr)
|
||||||
# Update timeout on AP without updating URL
|
# Update timeout on AP without updating URL
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:http://127.0.0.1:12345/foo.xml\r\ncache-control:max-age=1\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:http://127.0.0.1:12345/foo.xml\r\ncache-control:max-age=1\r\n\r\n", addr)
|
||||||
ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=5)
|
ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=5)
|
||||||
if ev is None:
|
if ev is None:
|
||||||
raise Exception("No WPS-ER-AP-REMOVE event on max-age timeout")
|
raise Exception("No WPS-ER-AP-REMOVE event on max-age timeout")
|
||||||
|
|
||||||
# Add an AP with a valid URL (but no server listing to it)
|
# Add an AP with a valid URL (but no server listing to it)
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:http://127.0.0.1:12345/foo.xml\r\ncache-control:max-age=1\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:http://127.0.0.1:12345/foo.xml\r\ncache-control:max-age=1\r\n\r\n", addr)
|
||||||
ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=5)
|
ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=5)
|
||||||
if ev is None:
|
if ev is None:
|
||||||
raise Exception("No WPS-ER-AP-REMOVE event on max-age timeout")
|
raise Exception("No WPS-ER-AP-REMOVE event on max-age timeout")
|
||||||
|
@ -4138,6 +4140,7 @@ def wps_er_start(dev, http_server, max_age=1, wait_m_search=False,
|
||||||
dev.request("WPS_ER_START ifname=lo")
|
dev.request("WPS_ER_START ifname=lo")
|
||||||
for i in range(100):
|
for i in range(100):
|
||||||
(msg,addr) = sock.recvfrom(1000)
|
(msg,addr) = sock.recvfrom(1000)
|
||||||
|
msg = msg.decode()
|
||||||
logger.debug("Received SSDP message from %s: %s" % (str(addr), msg))
|
logger.debug("Received SSDP message from %s: %s" % (str(addr), msg))
|
||||||
if "M-SEARCH" in msg:
|
if "M-SEARCH" in msg:
|
||||||
break
|
break
|
||||||
|
@ -4150,7 +4153,7 @@ def wps_er_start(dev, http_server, max_age=1, wait_m_search=False,
|
||||||
server = MyTCPServer(("127.0.0.1", 12345), http_server)
|
server = MyTCPServer(("127.0.0.1", 12345), http_server)
|
||||||
if not location_url:
|
if not location_url:
|
||||||
location_url = 'http://127.0.0.1:12345/foo.xml'
|
location_url = 'http://127.0.0.1:12345/foo.xml'
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:%s\r\ncache-control:max-age=%d\r\n\r\n" % (location_url, max_age), addr)
|
sock.sendto(("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:%s\r\ncache-control:max-age=%d\r\n\r\n" % (location_url, max_age)).encode(), addr)
|
||||||
server.timeout = 1
|
server.timeout = 1
|
||||||
return server,sock
|
return server,sock
|
||||||
|
|
||||||
|
@ -4488,11 +4491,11 @@ RGV2aWNlIEEQSQAGADcqAAEg
|
||||||
socks[i].settimeout(10)
|
socks[i].settimeout(10)
|
||||||
socks[i].connect(addr)
|
socks[i].connect(addr)
|
||||||
for i in range(20):
|
for i in range(20):
|
||||||
socks[i].send("GET / HTTP/1.1\r\n\r\n")
|
socks[i].send(b"GET / HTTP/1.1\r\n\r\n")
|
||||||
count = 0
|
count = 0
|
||||||
for i in range(20):
|
for i in range(20):
|
||||||
try:
|
try:
|
||||||
res = socks[i].recv(100)
|
res = socks[i].recv(100).decode()
|
||||||
if "HTTP/1" in res:
|
if "HTTP/1" in res:
|
||||||
count += 1
|
count += 1
|
||||||
else:
|
else:
|
||||||
|
@ -4513,7 +4516,7 @@ RGV2aWNlIEEQSQAGADcqAAEg
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
|
||||||
socket.IPPROTO_TCP)
|
socket.IPPROTO_TCP)
|
||||||
sock.connect(addr)
|
sock.connect(addr)
|
||||||
sock.send("GET / HTTP/1.1\r\n\r\n")
|
sock.send(b"GET / HTTP/1.1\r\n\r\n")
|
||||||
try:
|
try:
|
||||||
sock.recv(100)
|
sock.recv(100)
|
||||||
except:
|
except:
|
||||||
|
@ -4536,7 +4539,7 @@ RGV2aWNlIEEQSQAGADcqAAEg
|
||||||
socket.IPPROTO_TCP)
|
socket.IPPROTO_TCP)
|
||||||
sock.settimeout(0.1)
|
sock.settimeout(0.1)
|
||||||
sock.connect(addr)
|
sock.connect(addr)
|
||||||
sock.send(req)
|
sock.send(req.encode())
|
||||||
try:
|
try:
|
||||||
sock.recv(100)
|
sock.recv(100)
|
||||||
except:
|
except:
|
||||||
|
@ -4547,7 +4550,7 @@ RGV2aWNlIEEQSQAGADcqAAEg
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
|
||||||
socket.IPPROTO_TCP)
|
socket.IPPROTO_TCP)
|
||||||
sock.connect(addr)
|
sock.connect(addr)
|
||||||
sock.send("NOTIFY / HTTP/1.1\r\n\r\n" + 4500*'a')
|
sock.send(b"NOTIFY / HTTP/1.1\r\n\r\n" + 4500 * b'a')
|
||||||
try:
|
try:
|
||||||
sock.recv(100)
|
sock.recv(100)
|
||||||
except:
|
except:
|
||||||
|
@ -4839,7 +4842,7 @@ def _test_ap_wps_http_timeout(dev, apdev):
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
|
||||||
socket.IPPROTO_TCP)
|
socket.IPPROTO_TCP)
|
||||||
sock.connect(addr)
|
sock.connect(addr)
|
||||||
sock.send("G")
|
sock.send(b"G")
|
||||||
|
|
||||||
class DummyServer(StreamRequestHandler):
|
class DummyServer(StreamRequestHandler):
|
||||||
def handle(self):
|
def handle(self):
|
||||||
|
@ -4877,14 +4880,15 @@ def _test_ap_wps_er_url_parse(dev, apdev):
|
||||||
sock.bind(("239.255.255.250", 1900))
|
sock.bind(("239.255.255.250", 1900))
|
||||||
dev[0].request("WPS_ER_START ifname=lo")
|
dev[0].request("WPS_ER_START ifname=lo")
|
||||||
(msg,addr) = sock.recvfrom(1000)
|
(msg,addr) = sock.recvfrom(1000)
|
||||||
|
msg = msg.decode()
|
||||||
logger.debug("Received SSDP message from %s: %s" % (str(addr), msg))
|
logger.debug("Received SSDP message from %s: %s" % (str(addr), msg))
|
||||||
if "M-SEARCH" not in msg:
|
if "M-SEARCH" not in msg:
|
||||||
raise Exception("Not an M-SEARCH")
|
raise Exception("Not an M-SEARCH")
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:http://127.0.0.1\r\ncache-control:max-age=1\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:http://127.0.0.1\r\ncache-control:max-age=1\r\n\r\n", addr)
|
||||||
ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=2)
|
ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=2)
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:http://127.0.0.1/:foo\r\ncache-control:max-age=1\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:http://127.0.0.1/:foo\r\ncache-control:max-age=1\r\n\r\n", addr)
|
||||||
ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=2)
|
ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=2)
|
||||||
sock.sendto("HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:http://255.255.255.255:0/foo.xml\r\ncache-control:max-age=1\r\n\r\n", addr)
|
sock.sendto(b"HTTP/1.1 200 OK\r\nST: urn:schemas-wifialliance-org:device:WFADevice:1\r\nlocation:http://255.255.255.255:0/foo.xml\r\ncache-control:max-age=1\r\n\r\n", addr)
|
||||||
ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=2)
|
ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"], timeout=2)
|
||||||
|
|
||||||
sock.close()
|
sock.close()
|
||||||
|
|
|
@ -33,9 +33,9 @@ def sigma_dut_cmd(cmd, port=9000, timeout=2):
|
||||||
sock.settimeout(timeout)
|
sock.settimeout(timeout)
|
||||||
addr = ('127.0.0.1', port)
|
addr = ('127.0.0.1', port)
|
||||||
sock.connect(addr)
|
sock.connect(addr)
|
||||||
sock.send(cmd + "\r\n")
|
sock.send(cmd.encode() + b"\r\n")
|
||||||
try:
|
try:
|
||||||
res = sock.recv(1000)
|
res = sock.recv(1000).decode()
|
||||||
running = False
|
running = False
|
||||||
done = False
|
done = False
|
||||||
for line in res.splitlines():
|
for line in res.splitlines():
|
||||||
|
@ -49,7 +49,7 @@ def sigma_dut_cmd(cmd, port=9000, timeout=2):
|
||||||
done = True
|
done = True
|
||||||
if running and not done:
|
if running and not done:
|
||||||
# Read the actual response
|
# Read the actual response
|
||||||
res = sock.recv(1000)
|
res = sock.recv(1000).decode()
|
||||||
except:
|
except:
|
||||||
res = ''
|
res = ''
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -1826,7 +1826,7 @@ def test_wpas_ctrl_socket_full(dev, apdev, test_params):
|
||||||
for i in range(20):
|
for i in range(20):
|
||||||
logger.debug("Command %d" % i)
|
logger.debug("Command %d" % i)
|
||||||
try:
|
try:
|
||||||
s.send("MIB")
|
s.send(b"MIB")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info("Could not send command %d: %s" % (i, str(e)))
|
logger.info("Could not send command %d: %s" % (i, str(e)))
|
||||||
break
|
break
|
||||||
|
@ -1845,7 +1845,7 @@ def test_wpas_ctrl_socket_full(dev, apdev, test_params):
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
logger.debug("Command %d [2]" % i)
|
logger.debug("Command %d [2]" % i)
|
||||||
try:
|
try:
|
||||||
s2.send("MIB")
|
s2.send(b"MIB")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info("Could not send command %d [2]: %s" % (i, str(e)))
|
logger.info("Could not send command %d [2]: %s" % (i, str(e)))
|
||||||
break
|
break
|
||||||
|
@ -1858,7 +1858,7 @@ def test_wpas_ctrl_socket_full(dev, apdev, test_params):
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
logger.debug("Command %d [3]" % i)
|
logger.debug("Command %d [3]" % i)
|
||||||
try:
|
try:
|
||||||
s2.send("MIB")
|
s2.send(b"MIB")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info("Could not send command %d [3]: %s" % (i, str(e)))
|
logger.info("Could not send command %d [3]: %s" % (i, str(e)))
|
||||||
break
|
break
|
||||||
|
@ -1877,8 +1877,8 @@ def test_wpas_ctrl_socket_full(dev, apdev, test_params):
|
||||||
counter += 1
|
counter += 1
|
||||||
s.bind(local)
|
s.bind(local)
|
||||||
s.connect("/var/run/wpa_supplicant/wlan0")
|
s.connect("/var/run/wpa_supplicant/wlan0")
|
||||||
s.send("ATTACH")
|
s.send(b"ATTACH")
|
||||||
res = s.recv(100)
|
res = s.recv(100).decode()
|
||||||
if "OK" not in res:
|
if "OK" not in res:
|
||||||
raise Exception("Could not attach a test socket")
|
raise Exception("Could not attach a test socket")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue