@@ -864,6 +864,39 @@ def QueryValueEx(key, value_name):
864864 assert should_bypass_proxies (url , None ) == expected
865865
866866
867+ @pytest .mark .skipif (os .name != "nt" , reason = "Test only on Windows" )
868+ def test_should_bypass_proxies_win_registry_bad_values (monkeypatch ):
869+ """Tests for function should_bypass_proxies to check if proxy
870+ can be bypassed or not with Windows invalid registry settings.
871+ """
872+ import winreg
873+
874+ class RegHandle :
875+ def Close (self ):
876+ pass
877+
878+ ie_settings = RegHandle ()
879+
880+ def OpenKey (key , subkey ):
881+ return ie_settings
882+
883+ def QueryValueEx (key , value_name ):
884+ if key is ie_settings :
885+ if value_name == "ProxyEnable" :
886+ # Invalid response; Should be an int or int-y value
887+ return ["" ]
888+ elif value_name == "ProxyOverride" :
889+ return ["192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1" ]
890+
891+ monkeypatch .setenv ("http_proxy" , "" )
892+ monkeypatch .setenv ("https_proxy" , "" )
893+ monkeypatch .setenv ("no_proxy" , "" )
894+ monkeypatch .setenv ("NO_PROXY" , "" )
895+ monkeypatch .setattr (winreg , "OpenKey" , OpenKey )
896+ monkeypatch .setattr (winreg , "QueryValueEx" , QueryValueEx )
897+ assert should_bypass_proxies ("http://172.16.1.1/" , None ) is False
898+
899+
867900@pytest .mark .parametrize (
868901 "env_name, value" ,
869902 (
0 commit comments