Skip to content

Commit

Permalink
Avoid capitalization issues in SS hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
jraddaoui committed Aug 20, 2019
1 parent a8395a2 commit 2a8ed82
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 2 additions & 3 deletions scope/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ def ss_hosts_parser(hosts):
# Raise if credentials are not present
if not parts.username or not parts.password:
raise ValueError("Missing credentials for SS host: %s" % host)
url = "%s://%s" % (parts.scheme, parts.hostname)
if parts.port:
url = "%s:%s" % (url, parts.port)
# Use netloc instead of hostname and port to maintain capitalization
url = "%s://%s" % (parts.scheme, parts.netloc.split("@")[1])
parsed_hosts[url] = {"user": parts.username, "secret": parts.password}
return parsed_hosts

Expand Down
2 changes: 2 additions & 0 deletions scope/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ def test_ss_hosts_parser_success(self):
hosts = [
"http://user:secret@localhost:62081",
"https://user:[email protected]",
"https://user:[email protected]:8000",
]
parsed_hosts = helpers.ss_hosts_parser(hosts)
expected_hosts = {
"http://localhost:62081": {"user": "user", "secret": "secret"},
"https://192.168.1.128": {"user": "user", "secret": "secret"},
"https://HOST.com:8000": {"user": "user", "secret": "secret"},
}
self.assertEqual(parsed_hosts, expected_hosts)

Expand Down

0 comments on commit 2a8ed82

Please sign in to comment.