Skip to content
Myr

Merge pull request #6302 from flysee/main

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

Fix the proxy_bypass_registry function all returning true in some cases.

authored by Ian Stapleton Cordasco · committed by GitHub · parents eeafb6a, 13d892b · Browse files · 2 files+34 added−0 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+34 added−0 removed

  • tests:+32 added−0 removed
  • other:+2 added−0 removed

2 files+34 added−0 removed

modified:src/requests/utils.py+2 added
95 unmodified lines
96 # make a check value list from the registry entry: replace the97 # '<local>' string by the localhost entry and the corresponding98 # canonical entry.99 proxyOverride = proxyOverride.split(";")100 # filter out empty strings to avoid re.match return true in the following code.101 proxyOverride = filter(None, proxyOverride)102 # now check if we match one of the registry values.103 for test in proxyOverride:104 if test == "<local>":105 if "." not in host:
991 unmodified lines
modified:tests/test_utils.py+32 added
922 unmodified lines
923 with set_environ("test1", None):924 raise Exception("Expected exception")925926 assert "Expected exception" in str(exception.value)927928929@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")930def test_should_bypass_proxies_win_registry_ProxyOverride_value(monkeypatch):931 """Tests for function should_bypass_proxies to check if proxy932 can be bypassed or not with Windows ProxyOverride registry value ending with a semicolon.933 """934 import winreg935936 class RegHandle:937 def Close(self):938 pass939940 ie_settings = RegHandle()941942 def OpenKey(key, subkey):943 return ie_settings944945 def QueryValueEx(key, value_name):946 if key is ie_settings:947 if value_name == "ProxyEnable":948 return [1]949 elif value_name == "ProxyOverride":950 return [951 "192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1;<-loopback>;"952 ]953954 monkeypatch.setenv("NO_PROXY", "")955 monkeypatch.setenv("no_proxy", "")956 monkeypatch.setattr(winreg, "OpenKey", OpenKey)957 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)958 assert should_bypass_proxies("http://example.com/", None) is False