Skip to content

Commit b0942c8

Browse files
committed
Additional should_bypass_proxies function test cases
1 parent 1604e20 commit b0942c8

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/requests/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def proxy_bypass_registry(host):
9797
# '<local>' string by the localhost entry and the corresponding
9898
# canonical entry.
9999
proxyOverride = proxyOverride.split(";")
100-
# filter out empty strings to avoid re.match all true.
100+
# filter out empty strings to avoid re.match return true in the following code.
101101
proxyOverride = filter(None, proxyOverride)
102102
# now check if we match one of the registry values.
103103
for test in proxyOverride:

tests/test_utils.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,3 +924,33 @@ def test_set_environ_raises_exception():
924924
raise Exception("Expected exception")
925925

926926
assert "Expected exception" in str(exception.value)
927+
928+
929+
@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")
930+
def test_should_bypass_proxies_win_registry_ProxyOverride_value(monkeypatch):
931+
"""Tests for function should_bypass_proxies to check if proxy
932+
can be bypassed or not with Windows ProxyOverride registry value ending with a semicolon.
933+
"""
934+
import winreg
935+
936+
class RegHandle:
937+
def Close(self):
938+
pass
939+
940+
ie_settings = RegHandle()
941+
942+
def OpenKey(key, subkey):
943+
return ie_settings
944+
945+
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 ["192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1;<-loopback>;"]
951+
952+
monkeypatch.setenv("NO_PROXY", "")
953+
monkeypatch.setenv("no_proxy", "")
954+
monkeypatch.setattr(winreg, "OpenKey", OpenKey)
955+
monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)
956+
assert should_bypass_proxies("http://example.com/", None) is False

0 commit comments

Comments
 (0)