Skip to content

Commit

Permalink
Fixed tests after adding support for iproute2
Browse files Browse the repository at this point in the history
  • Loading branch information
vieira authored and brianmay committed Feb 10, 2017
1 parent d7d24f9 commit 9a9015a
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions sshuttle/tests/server/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ def test__maskbits():
sshuttle.server._maskbits(netmask)


@patch('sshuttle.server.which', side_effect=lambda x: x == 'netstat')
@patch('sshuttle.server.ssubprocess.Popen')
def test__listroutes(mock_popen):
def test_listroutes_netstat(mock_popen, mock_which):
mock_pobj = Mock()
mock_pobj.stdout = io.BytesIO(b"""
Kernel IP routing table
Expand All @@ -33,30 +34,20 @@ def test__listroutes(mock_popen):
mock_pobj.wait.return_value = 0
mock_popen.return_value = mock_pobj

routes = sshuttle.server._list_routes()
routes = sshuttle.server.list_routes()

env = {
'PATH': os.environ['PATH'],
'LC_ALL': "C",
}
assert mock_popen.mock_calls == [
call(['netstat', '-rn'], stdout=-1, env=env),
call().wait()
]
assert routes == [
(socket.AF_INET, '0.0.0.0', 0),
assert list(routes) == [
(socket.AF_INET, '192.168.1.0', 24)
]


@patch('sshuttle.server.which', side_effect=lambda x: x == 'ip')
@patch('sshuttle.server.ssubprocess.Popen')
def test_listroutes(mock_popen):
def test_listroutes_iproute(mock_popen, mock_which):
mock_pobj = Mock()
mock_pobj.stdout = io.BytesIO(b"""
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 wlan0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
default via 192.168.1.1 dev wlan0 proto static
192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.1
""")
mock_pobj.wait.return_value = 0
mock_popen.return_value = mock_pobj
Expand Down

0 comments on commit 9a9015a

Please sign in to comment.