Skip to content
Myr

Merge pull request #3195 from kumarvaradarajulu/no_proxy_fix

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix to check for Plain ip notations in no_proxy settings if not CIDR

authored by Ian Cordasco · committed by Ian Cordasco · parents 4865f0f, b94decc · Browse files · 2 files+25 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+25 added−1 removed

  • tests:+21 added−1 removed
  • other:+4 added−0 removed

2 files+25 added−1 removed

modified:requests/utils.py+4 added
537 unmodified lines
538 for proxy_ip in no_proxy:539 if is_valid_cidr(proxy_ip):540 if address_in_network(ip, proxy_ip):541 return True542 elif ip == proxy_ip:543 # If no_proxy ip was defined in plain IP notation instead of cidr notation &544 # matches the IP of the index545 return True546 else:547 for host in no_proxy:548 if netloc.endswith(host) or netloc.split(':')[0].endswith(host):549 # The URL does match something in no_proxy, so we don't want
183 unmodified lines
modified:tests/test_utils.py+21 added-1 removed
9 unmodified lines
10 get_encodings_from_content, get_environ_proxies,11 guess_filename, guess_json_utf, is_ipv4_address,12 is_valid_cidr, iter_slices, parse_dict_header,13 parse_header_links, prepend_scheme_if_needed,14 requote_uri, select_proxy, super_len,14 requote_uri, select_proxy, should_bypass_proxies, super_len,15 to_key_val_list, to_native_string,16 unquote_header_value, unquote_unreserved,17 urldefragauth)18
408 unmodified lines
427 ('scheme:u:p@example.com/path', 'scheme://example.com/path'),428 ))429def test_urldefragauth(url, expected):430 assert urldefragauth(url) == expected431432433@pytest.mark.parametrize(434 'url, expected', (435 ('http://192.168.0.1:5000/', True),436 ('http://192.168.0.1/', True),437 ('http://172.16.1.1/', True),438 ('http://172.16.1.1:5000/', True),439 ('http://localhost.localdomain:5000/v1.0/', True),440 ('http://172.16.1.12/', False),441 ('http://172.16.1.12:5000/', False),442 ('http://google.com:5000/v1.0/', False),443 ))444def test_should_bypass_proxies(url, expected, monkeypatch):445 """446 Tests for function should_bypass_proxies to check if proxy can be bypassed or not447 """448 monkeypatch.setenv('no_proxy', '192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1')449 monkeypatch.setenv('NO_PROXY', '192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1')450 assert should_bypass_proxies(url) == expected