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):