From f37c0d7730efd1b5f5eceec3d06e02abf3926929 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Mon, 9 Jan 2023 15:22:16 +0530 Subject: [PATCH] updated check for IPv6 addresses --- splunklib/binding.py | 3 ++- tests/test_binding.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/splunklib/binding.py b/splunklib/binding.py index 370f076cf..85cb8d126 100644 --- a/splunklib/binding.py +++ b/splunklib/binding.py @@ -347,7 +347,8 @@ def _authority(scheme=DEFAULT_SCHEME, host=DEFAULT_HOST, port=DEFAULT_PORT): "http://splunk.utopia.net:471" """ - if ':' in host: + # check if host is an IPv6 address and not enclosed in [ ] + if ':' in host and not (host.startswith('[') and host.endswith(']')): # IPv6 addresses must be enclosed in [ ] in order to be well # formed. host = '[' + host + ']' diff --git a/tests/test_binding.py b/tests/test_binding.py index aa3a13911..2af294cfd 100755 --- a/tests/test_binding.py +++ b/tests/test_binding.py @@ -190,6 +190,12 @@ def test_ipv6_host(self): host="2001:0db8:85a3:0000:0000:8a2e:0370:7334"), "https://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8089") + def test_ipv6_host_enclosed(self): + self.assertEqual( + binding._authority( + host="[2001:0db8:85a3:0000:0000:8a2e:0370:7334]"), + "https://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8089") + def test_all_fields(self): self.assertEqual( binding._authority(