|
8 | 8 | from unittest import mock
|
9 | 9 |
|
10 | 10 | import pytest
|
11 |
| - |
12 | 11 | from requests import compat
|
13 | 12 | from requests._internal_utils import unicode_is_ascii
|
14 | 13 | from requests.cookies import RequestsCookieJar
|
@@ -924,3 +923,33 @@ def test_set_environ_raises_exception():
|
924 | 923 | raise Exception("Expected exception")
|
925 | 924 |
|
926 | 925 | assert "Expected exception" in str(exception.value)
|
| 926 | + |
| 927 | + |
| 928 | +@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows") |
| 929 | +def test_should_bypass_proxies_win_registry_ProxyOverride_value(monkeypatch): |
| 930 | + """Tests for function should_bypass_proxies to check if proxy |
| 931 | + can be bypassed or not with Windows ProxyOverride registry value ending with a semicolon. |
| 932 | + """ |
| 933 | + import winreg |
| 934 | + |
| 935 | + class RegHandle: |
| 936 | + def Close(self): |
| 937 | + pass |
| 938 | + |
| 939 | + ie_settings = RegHandle() |
| 940 | + |
| 941 | + def OpenKey(key, subkey): |
| 942 | + return ie_settings |
| 943 | + |
| 944 | + def QueryValueEx(key, value_name): |
| 945 | + if key is ie_settings: |
| 946 | + if value_name == "ProxyEnable": |
| 947 | + return [1] |
| 948 | + elif value_name == "ProxyOverride": |
| 949 | + return ["192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1;<-loopback>;"] |
| 950 | + |
| 951 | + monkeypatch.setenv("NO_PROXY", "") |
| 952 | + monkeypatch.setenv("no_proxy", "") |
| 953 | + monkeypatch.setattr(winreg, "OpenKey", OpenKey) |
| 954 | + monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx) |
| 955 | + assert should_bypass_proxies("http://example.com/", None) is False |
0 commit comments