Skip to content

Commit 22d15fd

Browse files
authored
Merge pull request #2783 from guedou/ut_PR#2782
Mock read_routes() on FreeBSD 13.0
2 parents f87491f + f74145a commit 22d15fd

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/regression.uts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8928,6 +8928,44 @@ ff02::%lo0/32 ::1 U lo0
89288928
test_freebsd_10_2()
89298929

89308930

8931+
= FreeBSD 13.0
8932+
~ mock_read_routes_bsd
8933+
8934+
import mock
8935+
from io import StringIO
8936+
8937+
@mock.patch("scapy.arch.unix.os")
8938+
def test_freebsd_13(mock_os):
8939+
"""Test read_routes() on FreeBSD 13"""
8940+
# 'netstat -rnW -f inet' output
8941+
netstat_output = u"""
8942+
Routing tables
8943+
8944+
Internet:
8945+
Destination Gateway Flags Nhop# Mtu Netif Expire
8946+
default 10.0.0.1 UGS 3 1500 vtnet0
8947+
10.0.0.0/24 link#1 U 2 1500 vtnet0
8948+
10.0.0.8 link#2 UHS 1 16384 lo0
8949+
127.0.0.1 link#2 UH 1 16384 lo0
8950+
"""
8951+
# Mocked file descriptor
8952+
strio = StringIO(netstat_output)
8953+
mock_os.popen = mock.MagicMock(return_value=strio)
8954+
# Test the function
8955+
from scapy.arch.unix import read_routes
8956+
routes = read_routes()
8957+
scapy.arch.unix.DARWIN = False
8958+
scapy.arch.unix.FREEBSD = True
8959+
scapy.arch.unix.NETBSD = False
8960+
scapy.arch.unix.OPENBSD = False
8961+
for r in routes:
8962+
print(r)
8963+
assert(r[3] in ["vtnet0", "lo0"])
8964+
assert(len(routes) == 4)
8965+
8966+
test_freebsd_13()
8967+
8968+
89318969
= OpenBSD 5.5
89328970
~ mock_read_routes_bsd
89338971

0 commit comments

Comments
 (0)