mirror of
https://github.com/sshuttle/sshuttle.git
synced 2024-11-25 17:33:15 +01:00
3bfb975ed9
* re-organized imports according to pep8 * fixed all remaining pep8 issues * moved common config into setup.cfg, additionally test `tests` * removed --select=X -- the errors selected where by default not in flake8's --ignore list so effectively had no effect * update .travis.yml to reflect changes in tox.ini * make travis just use tox in order to avoid code duplaction * replace py.test with pytest * fixed .travis.yml * try different pypy toxenv * hopefully fixed testenv for pypy * added pypy basepython, removed unused python2.6 * install dev package before testing (fixes missing coverage) * fixed empty exception pass blocks with noqa * Added dummy log message on empty try-except-pass blocks to make dodacy happy :( * Replaced Exception with BaseException
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
import io
|
|
import socket
|
|
|
|
from mock import patch, Mock
|
|
|
|
import sshuttle.server
|
|
|
|
|
|
def test__ipmatch():
|
|
assert sshuttle.server._ipmatch("1.2.3.4") is not None
|
|
assert sshuttle.server._ipmatch("::1") is None # ipv6 not supported
|
|
assert sshuttle.server._ipmatch("42 Example Street, Melbourne") is None
|
|
|
|
|
|
def test__ipstr():
|
|
assert sshuttle.server._ipstr("1.2.3.4", 24) == "1.2.3.4/24"
|
|
assert sshuttle.server._ipstr("1.2.3.4", 32) == "1.2.3.4"
|
|
|
|
|
|
def test__maskbits():
|
|
netmask = sshuttle.server._ipmatch("255.255.255.0")
|
|
sshuttle.server._maskbits(netmask)
|
|
|
|
|
|
@patch('sshuttle.server.which', side_effect=lambda x: x == 'netstat')
|
|
@patch('sshuttle.server.ssubprocess.Popen')
|
|
def test_listroutes_netstat(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
|
|
""")
|
|
mock_pobj.wait.return_value = 0
|
|
mock_popen.return_value = mock_pobj
|
|
|
|
routes = sshuttle.server.list_routes()
|
|
|
|
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_iproute(mock_popen, mock_which):
|
|
mock_pobj = Mock()
|
|
mock_pobj.stdout = io.BytesIO(b"""
|
|
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
|
|
|
|
routes = sshuttle.server.list_routes()
|
|
|
|
assert list(routes) == [
|
|
(socket.AF_INET, '192.168.1.0', 24)
|
|
]
|