From f5467cec11a031d5478c233928befc1f39cfbed8 Mon Sep 17 00:00:00 2001 From: lwthiker Date: Tue, 12 Apr 2022 16:51:51 +0300 Subject: [PATCH] Use configurable tcpdump interface in the tests And add support for capturing the Client Hello message when sent over IPv6. --- tests/test_impersonate.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/test_impersonate.py b/tests/test_impersonate.py index 9446b44..ffc4bbb 100644 --- a/tests/test_impersonate.py +++ b/tests/test_impersonate.py @@ -214,15 +214,17 @@ class TestImpersonation: ] @pytest.fixture - def tcpdump(self): + def tcpdump(self, pytestconfig): """Initialize a sniffer to capture curl's traffic.""" + interface = pytestconfig.getoption("capture_interface") + logging.debug( - f"Running tcpdump on interface {self.TCPDUMP_CAPTURE_INTERFACE}" + f"Running tcpdump on interface {interface}" ) p = subprocess.Popen([ "tcpdump", "-n", - "-i", self.TCPDUMP_CAPTURE_INTERFACE, + "-i", interface, "-s", "0", "-w", "-", "-U", # Important, makes tcpdump unbuffered @@ -282,7 +284,7 @@ class TestImpersonation: """ for ts, buf in dpkt.pcap.Reader(io.BytesIO(pcap)): 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 ip = eth.data if not isinstance(ip.data, dpkt.tcp.TCP):