Fix -4/-6 crash caused by broken filter statement
In python3 filter returns a generator instead of a list. When -4 or -6 is used or if the host system has either of those address families disabled len() gets called onto this filter expression which results into a crash. This commit makes a filter expression out of this statement and also adds a test for ipv4-only downloading.
This commit is contained in:
parent
907013522c
commit
ccd01e8b6e
|
@ -849,9 +849,9 @@ class ServeFile():
|
||||||
|
|
||||||
# filter out ips we are not listening on
|
# filter out ips we are not listening on
|
||||||
if not self.listenIPv6:
|
if not self.listenIPv6:
|
||||||
ips = filter(lambda ip: ":" not in ip, ips)
|
ips = [ip for ip in ips if '.' in ip]
|
||||||
if not self.listenIPv4:
|
if not self.listenIPv4:
|
||||||
ips = filter(lambda ip: "." not in ip, ips)
|
ips = [ip for ip in ips if ':' in ip]
|
||||||
|
|
||||||
return ips
|
return ips
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -2,6 +2,7 @@ import io
|
||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import tarfile
|
import tarfile
|
||||||
import time
|
import time
|
||||||
|
@ -9,6 +10,12 @@ import urllib3
|
||||||
|
|
||||||
# crudly written to learn more about pytest and to have a base for refactoring
|
# crudly written to learn more about pytest and to have a base for refactoring
|
||||||
|
|
||||||
|
try:
|
||||||
|
ConnectionRefusedError
|
||||||
|
connrefused_exc = ConnectionRefusedError
|
||||||
|
except NameError:
|
||||||
|
connrefused_exc = socket.error
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def run_servefile():
|
def run_servefile():
|
||||||
|
@ -118,6 +125,18 @@ def test_specify_port(run_servefile, datadir):
|
||||||
check_download(data, fname='testfile', port=8081)
|
check_download(data, fname='testfile', port=8081)
|
||||||
|
|
||||||
|
|
||||||
|
def test_ipv4_only(run_servefile, datadir):
|
||||||
|
data = "NOOT NOOT"
|
||||||
|
p = datadir({'testfile': data}) / 'testfile'
|
||||||
|
run_servefile([str(p), '-4'])
|
||||||
|
|
||||||
|
check_download(data, fname='testfile', host='127.0.0.1')
|
||||||
|
|
||||||
|
sock = socket.socket(socket.AF_INET6)
|
||||||
|
with pytest.raises(connrefused_exc):
|
||||||
|
sock.connect(("::1", 8080))
|
||||||
|
|
||||||
|
|
||||||
def test_big_download(run_servefile, datadir):
|
def test_big_download(run_servefile, datadir):
|
||||||
# test with about 10 mb of data
|
# test with about 10 mb of data
|
||||||
data = "x" * (10 * 1024 ** 2)
|
data = "x" * (10 * 1024 ** 2)
|
||||||
|
|
Loading…
Reference in New Issue