Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sshuttle
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pub
sshuttle
Commits
9c5f1f5b
Commit
9c5f1f5b
authored
Aug 12, 2020
by
Brian May
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix parse_hostport to always return string for host
This fixes #488 and provides an alternative solution for #489.
parent
c5dcc918
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
2 deletions
+22
-2
ssh.py
sshuttle/ssh.py
+2
-2
test_parse_hostport.py
tests/ssh/test_parse_hostport.py
+20
-0
No files found.
sshuttle/ssh.py
View file @
9c5f1f5b
...
@@ -65,12 +65,12 @@ def parse_hostport(rhostport):
...
@@ -65,12 +65,12 @@ def parse_hostport(rhostport):
try
:
try
:
# try to parse host as an IP adress,
# try to parse host as an IP adress,
# if that works it is an IPv6 address
# if that works it is an IPv6 address
host
=
ipaddress
.
ip_address
(
host
)
host
=
str
(
ipaddress
.
ip_address
(
host
)
)
except
ValueError
:
except
ValueError
:
# if that fails parse as URL to get the port
# if that fails parse as URL to get the port
parsed
=
urlparse
(
'//{}'
.
format
(
host
))
parsed
=
urlparse
(
'//{}'
.
format
(
host
))
try
:
try
:
host
=
ipaddress
.
ip_address
(
parsed
.
hostname
)
host
=
str
(
ipaddress
.
ip_address
(
parsed
.
hostname
)
)
except
ValueError
:
except
ValueError
:
# else if both fails, we have a hostname with port
# else if both fails, we have a hostname with port
host
=
parsed
.
hostname
host
=
parsed
.
hostname
...
...
tests/ssh/test_parse_hostport.py
0 → 100644
View file @
9c5f1f5b
from
sshuttle.ssh
import
parse_hostport
def
test_host_only
():
assert
parse_hostport
(
"host"
)
==
(
None
,
None
,
None
,
"host"
)
assert
parse_hostport
(
"1.2.3.4"
)
==
(
None
,
None
,
None
,
"1.2.3.4"
)
assert
parse_hostport
(
"2001::1"
)
==
(
None
,
None
,
None
,
"2001::1"
)
assert
parse_hostport
(
"[2001::1]"
)
==
(
None
,
None
,
None
,
"2001::1"
)
def
test_host_and_port
():
assert
parse_hostport
(
"host:22"
)
==
(
None
,
None
,
22
,
"host"
)
assert
parse_hostport
(
"1.2.3.4:22"
)
==
(
None
,
None
,
22
,
"1.2.3.4"
)
assert
parse_hostport
(
"[2001::1]:22"
)
==
(
None
,
None
,
22
,
"2001::1"
)
def
test_username_and_host
():
assert
parse_hostport
(
"user@host"
)
==
(
"user"
,
None
,
None
,
"host"
)
assert
parse_hostport
(
"user:@host"
)
==
(
"user"
,
None
,
None
,
"host"
)
assert
parse_hostport
(
"user:pass@host"
)
==
(
"user"
,
"pass"
,
None
,
"host"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment