mirror of
https://github.com/sshuttle/sshuttle.git
synced 2024-11-25 01:13:37 +01:00
Merge pull request #734 from mangano-ito/add-tests-for-hostname-resolution
Add tests for host name resolution
This commit is contained in:
commit
d8a07a5244
@ -12,6 +12,7 @@ identity=0x1784577F811F6EAC
|
||||
count=true
|
||||
show-source=true
|
||||
statistics=true
|
||||
max-line-length=128
|
||||
|
||||
[tool:pytest]
|
||||
addopts = --cov=sshuttle --cov-branch --cov-report=term-missing
|
||||
|
@ -1,5 +1,6 @@
|
||||
import socket
|
||||
from argparse import ArgumentTypeError as Fatal
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
@ -27,6 +28,19 @@ _ip6_reprs = {
|
||||
_ip6_swidths = (48, 64, 96, 115, 128)
|
||||
|
||||
|
||||
def _mock_getaddrinfo(host, *_):
|
||||
return {
|
||||
"example.com": [
|
||||
(socket.AF_INET6, socket.SOCK_STREAM, 0, '', ('2606:2800:220:1:248:1893:25c8:1946', 0, 0, 0)),
|
||||
(socket.AF_INET, socket.SOCK_STREAM, 0, '', ('93.184.216.34', 0)),
|
||||
],
|
||||
"my.local": [
|
||||
(socket.AF_INET6, socket.SOCK_STREAM, 0, '', ('::1', 0, 0, 0)),
|
||||
(socket.AF_INET, socket.SOCK_STREAM, 0, '', ('127.0.0.1', 0)),
|
||||
],
|
||||
}.get(host, [])
|
||||
|
||||
|
||||
def test_parse_subnetport_ip4():
|
||||
for ip_repr, ip in _ip4_reprs.items():
|
||||
assert sshuttle.options.parse_subnetport(ip_repr) \
|
||||
@ -105,3 +119,41 @@ def test_parse_subnetport_ip6_with_mask_and_port():
|
||||
def test_convert_arg_line_to_args_skips_comments():
|
||||
parser = sshuttle.options.MyArgumentParser()
|
||||
assert parser.convert_arg_line_to_args("# whatever something") == []
|
||||
|
||||
|
||||
@patch('sshuttle.options.socket.getaddrinfo', side_effect=_mock_getaddrinfo)
|
||||
def test_parse_subnetport_host(mock_getaddrinfo):
|
||||
assert set(sshuttle.options.parse_subnetport('example.com')) \
|
||||
== set([
|
||||
(socket.AF_INET6, '2606:2800:220:1:248:1893:25c8:1946', 128, 0, 0),
|
||||
(socket.AF_INET, '93.184.216.34', 32, 0, 0),
|
||||
])
|
||||
assert set(sshuttle.options.parse_subnetport('my.local')) \
|
||||
== set([
|
||||
(socket.AF_INET6, '::1', 128, 0, 0),
|
||||
(socket.AF_INET, '127.0.0.1', 32, 0, 0),
|
||||
])
|
||||
|
||||
|
||||
@patch('sshuttle.options.socket.getaddrinfo', side_effect=_mock_getaddrinfo)
|
||||
def test_parse_subnetport_host_with_port(mock_getaddrinfo):
|
||||
assert set(sshuttle.options.parse_subnetport('example.com:80')) \
|
||||
== set([
|
||||
(socket.AF_INET6, '2606:2800:220:1:248:1893:25c8:1946', 128, 80, 80),
|
||||
(socket.AF_INET, '93.184.216.34', 32, 80, 80),
|
||||
])
|
||||
assert set(sshuttle.options.parse_subnetport('example.com:80-90')) \
|
||||
== set([
|
||||
(socket.AF_INET6, '2606:2800:220:1:248:1893:25c8:1946', 128, 80, 90),
|
||||
(socket.AF_INET, '93.184.216.34', 32, 80, 90),
|
||||
])
|
||||
assert set(sshuttle.options.parse_subnetport('my.local:445')) \
|
||||
== set([
|
||||
(socket.AF_INET6, '::1', 128, 445, 445),
|
||||
(socket.AF_INET, '127.0.0.1', 32, 445, 445),
|
||||
])
|
||||
assert set(sshuttle.options.parse_subnetport('my.local:445-450')) \
|
||||
== set([
|
||||
(socket.AF_INET6, '::1', 128, 445, 450),
|
||||
(socket.AF_INET, '127.0.0.1', 32, 445, 450),
|
||||
])
|
||||
|
Loading…
Reference in New Issue
Block a user