Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Set python session non-proxy from yaml #1709

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions bzt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,10 @@ def add_proxy_settings(self, proxy_settings):
else:
proxy_uri = "%s://%s" % (scheme, proxy_url.netloc)
self.session.proxies = {"https": proxy_uri, "http": proxy_uri}
self.session.proxies = {"https": proxy_uri, "http": proxy_uri}
non_proxy = proxy_settings.get("nonProxy")
if non_proxy:
os.environ['NO_PROXY'] = self.convert_to_python_no_proxy_string(non_proxy)

if not self.proxy_settings:
self.log.info('Proxy settings not set')
Expand Down Expand Up @@ -1261,6 +1265,19 @@ def convert_to_java_no_proxy_string(no_proxy):
return java_no_proxy_string
return no_proxy

@staticmethod
def convert_to_python_no_proxy_string(no_proxy):
if no_proxy:
java_no_proxy_string = ''
for host in no_proxy.split('|'):
if host.startswith('.'):
host = '*' + host
java_no_proxy_string = java_no_proxy_string + host + ','
if java_no_proxy_string.endswith(','):
java_no_proxy_string = java_no_proxy_string[:-1]
return java_no_proxy_string
return no_proxy

def download_file(self, url, filename, reporthook=None, data=None, timeout=None):
headers = None
try:
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,13 @@ def test_proxy_string_convert(self):
self.assertEqual('*.test.com|*.test2.com', HTTPClient.convert_to_java_no_proxy_string('*.test.com,.test2.com'))
self.assertEqual('*.test.com|*.test2.com', HTTPClient.convert_to_java_no_proxy_string('.test.com,.test2.com'))

def test_proxy_string_convert_to_python(self):
self.assertEqual('', HTTPClient.convert_to_python_no_proxy_string(''))
self.assertEqual('localhost', HTTPClient.convert_to_python_no_proxy_string('localhost'))
self.assertEqual('*.test.com', HTTPClient.convert_to_python_no_proxy_string('.test.com'))
self.assertEqual('*.test.com', HTTPClient.convert_to_python_no_proxy_string('*.test.com'))
self.assertEqual('*.test.com,*.test2.com', HTTPClient.convert_to_python_no_proxy_string('*.test.com,*.test2.com'))
self.assertEqual('*.test.com,*.test2.com', HTTPClient.convert_to_python_no_proxy_string('.test.com|.test2.com'))

def test_download_file(self):
obj = HTTPClient()
Expand Down