Skip to content
Myr

test proxy bypass with config from registry

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

authored by schlamar · committed by schlamar · parent 724fd44 · Browse files · 1 file+48 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

1 file+48 added−0 removed

  • tests:+48 added−0 removed

1 file+48 added−0 removed

modified:tests/test_utils.py+48 added
1# -*- coding: utf-8 -*-23import os4from io import BytesIO56import pytest7from requests import compat
591 unmodified lines
599 """600 no_proxy = '192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1'601 # Test 'no_proxy' argument602 assert should_bypass_proxies(url, no_proxy=no_proxy) == expected603604605@pytest.mark.skipif(os.name != 'nt', reason='Test only on Windows')606@pytest.mark.parametrize(607 'url, expected', (608 ('http://192.168.0.1:5000/', True),609 ('http://192.168.0.1/', True),610 ('http://172.16.1.1/', True),611 ('http://172.16.1.1:5000/', True),612 ('http://localhost.localdomain:5000/v1.0/', True),613 ('http://172.16.1.22/', False),614 ('http://172.16.1.22:5000/', False),615 ('http://google.com:5000/v1.0/', False),616 ))617def test_should_bypass_proxies_win_registry(url, expected, monkeypatch):618 """Tests for function should_bypass_proxies to check if proxy619 can be bypassed or not with Windows registry settings620 """621 if compat.is_py3:622 import winreg623 else:624 import _winreg as winreg625626 class RegHandle:627 def Close(self):628 pass629630 ie_settings = RegHandle()631632 def OpenKey(key, subkey):633 return ie_settings634635 def QueryValueEx(key, value_name):636 if key is ie_settings:637 if value_name == 'ProxyEnable':638 return [1]639 elif value_name == 'ProxyOverride':640 return ['192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1']641642 monkeypatch.setenv('http_proxy', '')643 monkeypatch.setenv('https_proxy', '')644 monkeypatch.setenv('ftp_proxy', '')645 monkeypatch.setenv('no_proxy', '')646 monkeypatch.setenv('NO_PROXY', '')647 monkeypatch.setattr(winreg, 'OpenKey', OpenKey)648 monkeypatch.setattr(winreg, 'QueryValueEx', QueryValueEx)649 assert should_bypass_proxies(url, no_proxy=None) == expected