From 6ec665a233aca3da0eca450c2517aa43762cc8c8 Mon Sep 17 00:00:00 2001 From: Mike Kingsbury Date: Wed, 14 Sep 2022 13:25:48 -0400 Subject: [PATCH] Removing extraneous space inserted during refactoring commit 894484a. Code was moved to a new function, and a space was added to the split. bz#2126155 Signed-off-by: Mike Kingsbury --- insights/client/connection.py | 5 ++- .../client/connection/test_init_session.py | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/insights/client/connection.py b/insights/client/connection.py index 1b51a93d75..1f411623e5 100644 --- a/insights/client/connection.py +++ b/insights/client/connection.py @@ -276,7 +276,10 @@ def get_proxy(self, proxy_info, no_proxy_info, environment): if no_proxy_info: insights_service_host = urlparse(self.base_url).hostname logger.debug('Found NO_PROXY set. Checking NO_PROXY %s against base URL %s.', no_proxy_info, insights_service_host) - for no_proxy_host in no_proxy_info.split(', '): + # Split the no_proxy entries on ',', then strip any leading and trailing whitespace. Create a clean list for the + # for loop. + no_proxy_info = [host.strip() for host in no_proxy_info.split(',')] + for no_proxy_host in no_proxy_info: logger.debug('Checking %s against %s', no_proxy_host, insights_service_host) if no_proxy_host == '*': proxies = None diff --git a/insights/tests/client/connection/test_init_session.py b/insights/tests/client/connection/test_init_session.py index 0e8b366113..004b3765c2 100644 --- a/insights/tests/client/connection/test_init_session.py +++ b/insights/tests/client/connection/test_init_session.py @@ -83,6 +83,14 @@ def test_get_no_proxy_env(): connection.get_proxies() assert connection.proxies is None + with patch.dict(os_environ, {"HTTPS_PROXY": "env.proxy.example.com", "NO_PROXY": "redhat.com,example.com"}, clear=True): + connection.get_proxies() + assert connection.proxies is None + + with patch.dict(os_environ, {"HTTPS_PROXY": "env.proxy.example.com", "NO_PROXY": "url.com,example.com"}, clear=True): + connection.get_proxies() + assert connection.proxies == {'https': 'env.proxy.example.com'} + with patch.dict(os_environ, {"HTTPS_PROXY": "env.proxy.example.com", "NO_PROXY": "url.com"}, clear=True): connection.get_proxies() assert connection.proxies == {'https': 'env.proxy.example.com'} @@ -111,6 +119,38 @@ def test_get_no_proxy_rhsm(): connection.get_proxies() assert connection.proxies == {"https": config.proxy} + config.no_proxy = "example.com,url.com" + connection.get_proxies() + assert connection.proxies == {"https": config.proxy} + + config.no_proxy = "example.com, url.com" + connection.get_proxies() + assert connection.proxies == {"https": config.proxy} + + config.no_proxy = "example.com , url.com" + connection.get_proxies() + assert connection.proxies == {"https": config.proxy} + + config.no_proxy = "redhat.com, example.com" + connection.get_proxies() + assert connection.proxies is None + + config.no_proxy = "example.com, redhat.com" + connection.get_proxies() + assert connection.proxies is None + + config.no_proxy = "redhat.com,example.com" + connection.get_proxies() + assert connection.proxies is None + + config.no_proxy = "example.com,redhat.com" + connection.get_proxies() + assert connection.proxies is None + + config.no_proxy = "example.com , redhat.com" + connection.get_proxies() + assert connection.proxies is None + @patch("insights.client.connection.logger.debug") def test_get_rhsm_and_env(logger):