-
Notifications
You must be signed in to change notification settings - Fork 794
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved a function into common, since Monkey doesn't have ring as a dep…
…endency Also renamed it and added UTs
- Loading branch information
1 parent
ca87ff1
commit 9ea6718
Showing
5 changed files
with
26 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from urllib.parse import urlparse | ||
|
||
|
||
def get_host_from_network_location(network_location: str) -> str: | ||
""" | ||
URL structure is "<scheme>://<net_loc>/<path>;<params>?<query>#<fragment>" (https://tools.ietf.org/html/rfc1808.html) | ||
And the net_loc is "<user>:<password>@<host>:<port>" (https://tools.ietf.org/html/rfc1738#section-3.1) | ||
:param network_location: server network location | ||
:return: host part of the network location | ||
""" | ||
url = urlparse("http://" + network_location) | ||
return str(url.hostname) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from unittest import TestCase | ||
|
||
from common.network.network_utils import get_host_from_network_location | ||
|
||
|
||
class TestNetworkUtils(TestCase): | ||
def test_remove_port_from_ip_string(self): | ||
assert get_host_from_network_location("127.0.0.1:12345") == "127.0.0.1" | ||
assert get_host_from_network_location("127.0.0.1:12345") == "127.0.0.1" | ||
assert get_host_from_network_location("127.0.0.1") == "127.0.0.1" | ||
assert get_host_from_network_location("www.google.com:8080") == "www.google.com" | ||
assert get_host_from_network_location("user:password@host:8080") == "host" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters