Skip to content

Commit

Permalink
Bugfix IPv6 netloc parsing
Browse files Browse the repository at this point in the history
This bug was introduced in a723b61; if IPv6 worked in the CI environment, it
would've been caught earlier... but it didn't in Travis-CI, so I removed
the one IPv6 test target in 0926711.

Let's add it back and see if it works with GitHub-CI workflows?
  • Loading branch information
dlenski committed May 29, 2024
1 parent e4380a9 commit c44bfce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions tests/test_sniffers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@
('vpn.sgh.waw.pl', sn.global_protect), # portal
('vpn-gw.sgh.waw.pl', sn.global_protect), # gateway
('jvpn.tn.gov', sn.juniper_pulse),
('174.127.47.193', sn.check_point), # no DNS?
('174.127.47.193', sn.check_point), # no DNS?
('nomad.sandiego.edu', sn.aruba_via),
('viavpn.luther.edu', sn.aruba_via),
('vpn.wdc.softlayer.com', sn.array_networks),
('166.111.32.74:10443', sn.h3c), # no DNS? tsinghua.edu.cn
('58.246.39.91:8899', sn.huawei), # no DNS? China, non-edu
('166.111.32.74:10443', sn.h3c), # no DNS? tsinghua.edu.cn
('58.246.39.91:8899', sn.huawei), # no DNS? China, non-edu
('[2620:0:e00:17::2]', sn.anyconnect) # address changes sometimes (https://dns.google/query?name=vpn.cites.illinois.edu&type=AAA)
]

unmatched_vpns = ['vpn.{}.edu'.format(d) for d in (
Expand Down Expand Up @@ -101,3 +102,16 @@ def test_unmatched_vpns(self):
for domain in unmatched_vpns:
shuffle(self.sniffers)
yield self.check_hits, domain, None


def test_server_split():
def check_server_split(netloc, expected):
assert sn.server_split(netloc) == expected

for netloc, expected in (
('foo.bar.com:123', ('foo.bar.com', 123)),
('foo.bar.com', ('foo.bar.com', 443)),
('[dead:beef::f00f]', ('[dead:beef::f00f]', 443)),
('[dead:beef::f00f]:789', ('[dead:beef::f00f]', 789)),
):
yield check_server_split, netloc, expected
2 changes: 1 addition & 1 deletion what_vpn/sniffers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def server_split(host_and_maybe_port):
rest, *last = host_and_maybe_port.rsplit(':', 1)
if not last:
host, port = rest, 443
elif ']' in last: # we mis-split an IPv6 address, something like '[2601::1234]':
elif ']' in last[0]: # we mis-split an IPv6 address, something like '[2601::1234]':
host, port = host_and_maybe_port, 443
else:
host, port = rest, int(last[0])
Expand Down

0 comments on commit c44bfce

Please sign in to comment.