Use configurable tcpdump interface in the tests

And add support for capturing the Client Hello message when sent over
IPv6.
This commit is contained in:
lwthiker
2022-04-12 16:51:51 +03:00
parent facd6e5551
commit f5467cec11

View File

@@ -214,15 +214,17 @@ class TestImpersonation:
] ]
@pytest.fixture @pytest.fixture
def tcpdump(self): def tcpdump(self, pytestconfig):
"""Initialize a sniffer to capture curl's traffic.""" """Initialize a sniffer to capture curl's traffic."""
interface = pytestconfig.getoption("capture_interface")
logging.debug( logging.debug(
f"Running tcpdump on interface {self.TCPDUMP_CAPTURE_INTERFACE}" f"Running tcpdump on interface {interface}"
) )
p = subprocess.Popen([ p = subprocess.Popen([
"tcpdump", "-n", "tcpdump", "-n",
"-i", self.TCPDUMP_CAPTURE_INTERFACE, "-i", interface,
"-s", "0", "-s", "0",
"-w", "-", "-w", "-",
"-U", # Important, makes tcpdump unbuffered "-U", # Important, makes tcpdump unbuffered
@@ -282,7 +284,7 @@ class TestImpersonation:
""" """
for ts, buf in dpkt.pcap.Reader(io.BytesIO(pcap)): for ts, buf in dpkt.pcap.Reader(io.BytesIO(pcap)):
eth = dpkt.ethernet.Ethernet(buf) eth = dpkt.ethernet.Ethernet(buf)
if not isinstance(eth.data, dpkt.ip.IP): if not isinstance(eth.data, dpkt.ip.IP) and not isinstance(eth.data, dpkt.ip6.IP6):
continue continue
ip = eth.data ip = eth.data
if not isinstance(ip.data, dpkt.tcp.TCP): if not isinstance(ip.data, dpkt.tcp.TCP):