summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMilas Bowman <milas.bowman@docker.com>2022-07-26 11:35:44 -0400
committerGitHub <noreply@github.com>2022-07-26 11:35:44 -0400
commitf16c4e1147c81afd822fe72191f0f720cb0ba637 (patch)
treedefb3f3e7241121eec120039ac51b017c9e0f0ba /tests
parent2933af2ca760cda128f1a48145170a56ba732abd (diff)
downloaddocker-py-f16c4e1147c81afd822fe72191f0f720cb0ba637.tar.gz
utils: fix IPv6 address w/ port parsing (#3006)
This was using a deprecated function (`urllib.splitnport`), ostensibly to work around issues with brackets on IPv6 addresses. Ironically, its usage was broken, and would result in mangled IPv6 addresses if they had a port specified in some instances. Usage of the deprecated function has been eliminated and extra test cases added where missing. All existing cases pass as-is. (The only other change to the test was to improve assertion messages.) Signed-off-by: Milas Bowman <milas.bowman@docker.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/utils_test.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py
index 802d919..12cb7bd 100644
--- a/tests/unit/utils_test.py
+++ b/tests/unit/utils_test.py
@@ -296,17 +296,24 @@ class ParseHostTest(unittest.TestCase):
'[fd12::82d1]:2375/docker/engine': (
'http://[fd12::82d1]:2375/docker/engine'
),
+ 'ssh://[fd12::82d1]': 'ssh://[fd12::82d1]:22',
+ 'ssh://user@[fd12::82d1]:8765': 'ssh://user@[fd12::82d1]:8765',
'ssh://': 'ssh://127.0.0.1:22',
'ssh://user@localhost:22': 'ssh://user@localhost:22',
'ssh://user@remote': 'ssh://user@remote:22',
}
for host in invalid_hosts:
- with pytest.raises(DockerException):
+ msg = f'Should have failed to parse invalid host: {host}'
+ with self.assertRaises(DockerException, msg=msg):
parse_host(host, None)
for host, expected in valid_hosts.items():
- assert parse_host(host, None) == expected
+ self.assertEqual(
+ parse_host(host, None),
+ expected,
+ msg=f'Failed to parse valid host: {host}',
+ )
def test_parse_host_empty_value(self):
unix_socket = 'http+unix:///var/run/docker.sock'