diff options
| author | schlamar <marc.schlaich@gmail.com> | 2017-04-20 15:41:43 +0200 |
|---|---|---|
| committer | schlamar <marc.schlaich@gmail.com> | 2017-05-04 07:46:59 +0200 |
| commit | 4f34446b363d3dec84eedb410df79e5e3773cde9 (patch) | |
| tree | b96f7b4f1c8e9cdc3fd6d4203a25917e8636bc1d /tests/test_utils.py | |
| parent | 724fd44b975c5a078a186e79417656772a3f8ecc (diff) | |
| download | python-requests-4f34446b363d3dec84eedb410df79e5e3773cde9.tar.gz | |
test proxy bypass with config from registry
Diffstat (limited to 'tests/test_utils.py')
| -rw-r--r-- | tests/test_utils.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py index 11ebf617..fa5da071 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import os from io import BytesIO import pytest @@ -599,3 +600,50 @@ def test_should_bypass_proxies_no_proxy( no_proxy = '192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1' # Test 'no_proxy' argument assert should_bypass_proxies(url, no_proxy=no_proxy) == expected + + +@pytest.mark.skipif(os.name != 'nt', reason='Test only on Windows') +@pytest.mark.parametrize( + 'url, expected', ( + ('http://192.168.0.1:5000/', True), + ('http://192.168.0.1/', True), + ('http://172.16.1.1/', True), + ('http://172.16.1.1:5000/', True), + ('http://localhost.localdomain:5000/v1.0/', True), + ('http://172.16.1.22/', False), + ('http://172.16.1.22:5000/', False), + ('http://google.com:5000/v1.0/', False), + )) +def test_should_bypass_proxies_win_registry(url, expected, monkeypatch): + """Tests for function should_bypass_proxies to check if proxy + can be bypassed or not with Windows registry settings + """ + if compat.is_py3: + import winreg + else: + import _winreg as winreg + + class RegHandle: + def Close(self): + pass + + ie_settings = RegHandle() + + def OpenKey(key, subkey): + return ie_settings + + def QueryValueEx(key, value_name): + if key is ie_settings: + if value_name == 'ProxyEnable': + return [1] + elif value_name == 'ProxyOverride': + return ['192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1'] + + monkeypatch.setenv('http_proxy', '') + monkeypatch.setenv('https_proxy', '') + monkeypatch.setenv('ftp_proxy', '') + monkeypatch.setenv('no_proxy', '') + monkeypatch.setenv('NO_PROXY', '') + monkeypatch.setattr(winreg, 'OpenKey', OpenKey) + monkeypatch.setattr(winreg, 'QueryValueEx', QueryValueEx) + assert should_bypass_proxies(url, no_proxy=None) == expected |
