From 254975b357798026e91d9c5a8b406a8a69f0a7e7 Mon Sep 17 00:00:00 2001 From: speakinghedge Date: Thu, 21 Dec 2017 22:21:40 +0100 Subject: [PATCH] test proper error handling if lo is missing or has no address #957 --- test/linux.uts | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/linux.uts b/test/linux.uts index 24edecaca..ec0c0a478 100644 --- a/test/linux.uts +++ b/test/linux.uts @@ -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)