Skip to content
Snippets Groups Projects
Commit 4da93c9a authored by Pierre LALET's avatar Pierre LALET
Browse files

Add tests for sniff(), send(), sendp()

parent 69250064
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,7 @@ test_script: ...@@ -27,7 +27,7 @@ test_script:
- set PATH="%APPVEYOR_BUILD_FOLDER%;C:\Program Files\Wireshark\;%PATH%" - set PATH="%APPVEYOR_BUILD_FOLDER%;C:\Program Files\Wireshark\;%PATH%"
# Main unit tests # Main unit tests
- "%PYTHON%\\python -m coverage run -a bin\\UTscapy -f text -t test\\regression.uts -F -K automaton -K mock_read_routes6_bsd || exit /b 42" - "%PYTHON%\\python -m coverage run -a bin\\UTscapy -f text -t test\\regression.uts -F -K automaton -K mock_read_routes6_bsd -K fork || exit /b 42"
- 'del test\regression.uts' - 'del test\regression.uts'
# Secondary unit tests # Secondary unit tests
......
...@@ -688,6 +688,31 @@ assert(DNS in IP(str(dns_ans2))) ...@@ -688,6 +688,31 @@ assert(DNS in IP(str(dns_ans2)))
conf.route.route("0.0.0.0")[2] conf.route.route("0.0.0.0")[2]
arping(_+"/24") arping(_+"/24")
= send() and sniff()
~ netaccess fork
import time
import os
def send_and_sniff(pkt, timeout=2, flt=None, iface=None):
"""Send a packet, sniff, and check the packet has been seen"""
pid = os.fork()
assert pid != -1
if pid == 0:
time.sleep(1)
(sendp if isinstance(pkt, (Ether, Dot3)) else send)(pkt, iface=iface)
os._exit(0)
else:
spkt = str(pkt)
pkts = sniff(
timeout=timeout, iface=iface, filter=flt,
stop_filter=lambda p: pkt.__class__ in p and str(p[pkt.__class__]) == spkt
)
os.waitpid(pid, 0)
assert str(pkt) in (str(p[pkt.__class__]) for p in pkts if pkt.__class__ in p)
send_and_sniff(IP(dst="secdev.org")/ICMP())
send_and_sniff(IP(dst="secdev.org")/ICMP(), flt="icmp")
send_and_sniff(Ether()/IP(dst="secdev.org")/ICMP())
############ ############
############ ############
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment