mirror of https://github.com/secdev/scapy.git
test proper error handling if lo is missing or has no address #957
This commit is contained in:
parent
963e8141d7
commit
254975b357
|
@ -125,3 +125,50 @@ assert(conf.route.route("192.0.2.43") == ("scapy0.42", "203.0.113.42", "203.0.11
|
|||
route_specific = (3221226027, 4294967295, "203.0.113.41", "scapy0.42", "203.0.113.42", 0)
|
||||
assert(route_specific in conf.route.routes)
|
||||
exit_status = os.system("ip link del name dev scapy0")
|
||||
|
||||
= catch looback device missing
|
||||
~ linux needs_root
|
||||
|
||||
from mock import patch
|
||||
|
||||
# can't remove the lo device (or its address without causing trouble) - use some pseudo dummy instead
|
||||
|
||||
with patch('scapy.consts.LOOPBACK_NAME', 'scapy_lo_x'):
|
||||
_ = read_routes()
|
||||
|
||||
= catch looback device no address assigned
|
||||
~ linux needs_root
|
||||
|
||||
import os, socket
|
||||
from mock import patch
|
||||
|
||||
exit_status = os.system("ip link add name scapy_lo type dummy")
|
||||
assert(exit_status == 0)
|
||||
exit_status = os.system("ip link set dev scapy_lo up")
|
||||
assert(exit_status == 0)
|
||||
|
||||
with patch('scapy.consts.LOOPBACK_NAME', 'scapy_lo'):
|
||||
_ = read_routes()
|
||||
|
||||
exit_status = os.system("ip addr add dev scapy_lo 10.10.0.1/24")
|
||||
assert(exit_status == 0)
|
||||
|
||||
with patch('scapy.consts.LOOPBACK_NAME', 'scapy_lo'):
|
||||
routes = read_routes()
|
||||
|
||||
got_lo_device = False
|
||||
for route in routes:
|
||||
dst_int, msk_int, _, if_name, if_addr, _ = route
|
||||
if if_name == 'scapy_lo':
|
||||
got_lo_device = True
|
||||
assert(if_addr == '10.10.0.1')
|
||||
dst_addr = socket.inet_ntoa(struct.pack("!I", dst_int))
|
||||
assert(dst_addr == '10.10.0.0')
|
||||
msk = socket.inet_ntoa(struct.pack("!I", msk_int))
|
||||
assert (msk == '255.255.255.0')
|
||||
break
|
||||
|
||||
assert(got_lo_device)
|
||||
|
||||
exit_status = os.system("ip link del dev scapy_lo")
|
||||
assert(exit_status == 0)
|
||||
|
|
Loading…
Reference in New Issue