diff options
| author | Ronald Oussoren <ronaldoussoren@mac.com> | 2011-03-14 22:48:31 (GMT) |
|---|---|---|
| committer | Ronald Oussoren <ronaldoussoren@mac.com> | 2011-03-14 22:48:31 (GMT) |
| commit | ba3a978fc1b877bd61602e6997d960a98e474311 (patch) | |
| tree | fa4849c95c66fca4de0ed6076523302457391c6c /Lib/test/test_urllib2.py | |
| parent | 45725727187c7413b2a16f812160244e19787615 (diff) | |
| parent | f2db4de4d82101a900ff3b000e39ee9207ff8bf7 (diff) | |
| download | cpython-ba3a978fc1b877bd61602e6997d960a98e474311.zip cpython-ba3a978fc1b877bd61602e6997d960a98e474311.tar.gz cpython-ba3a978fc1b877bd61602e6997d960a98e474311.tar.bz2 | |
Issue #11500: Fixed a bug in the os x proxy bypass code for fully qualified IP addresses in the proxy exception list.
Diffstat (limited to 'Lib/test/test_urllib2.py')
| -rw-r--r-- | Lib/test/test_urllib2.py | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 4ddbe3f..1d0d98c 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -7,7 +7,9 @@ import socket import array import urllib.request -from urllib.request import Request, OpenerDirector +# The proxy bypass method imported below has logic specific to the OSX +# proxy config data structure but is testable on all platforms. +from urllib.request import Request, OpenerDirector, _proxy_bypass_macosx_sysconf # XXX # Request @@ -1076,6 +1078,17 @@ class HandlerTests(unittest.TestCase): self.assertEqual(req.get_host(), "www.python.org") del os.environ['no_proxy'] + def test_proxy_no_proxy_all(self): + os.environ['no_proxy'] = '*' + o = OpenerDirector() + ph = urllib.request.ProxyHandler(dict(http="proxy.example.com")) + o.add_handler(ph) + req = Request("http://www.python.org") + self.assertEqual(req.get_host(), "www.python.org") + r = o.open(req) + self.assertEqual(req.get_host(), "www.python.org") + del os.environ['no_proxy'] + def test_proxy_https(self): o = OpenerDirector() @@ -1116,6 +1129,26 @@ class HandlerTests(unittest.TestCase): self.assertEqual(req.get_host(), "proxy.example.com:3128") self.assertEqual(req.get_header("Proxy-authorization"),"FooBar") + def test_osx_proxy_bypass(self): + bypass = { + 'exclude_simple': False, + 'exceptions': ['foo.bar', '*.bar.com', '127.0.0.1', '10.10', + '10.0/16'] + } + # Check hosts that should trigger the proxy bypass + for host in ('foo.bar', 'www.bar.com', '127.0.0.1', '10.10.0.1', + '10.0.0.1'): + self.assertTrue(_proxy_bypass_macosx_sysconf(host, bypass), + 'expected bypass of %s to be True' % host) + # Check hosts that should not trigger the proxy bypass + for host in ('abc.foo.bar', 'bar.com', '127.0.0.2', '10.11.0.1', 'test'): + self.assertFalse(_proxy_bypass_macosx_sysconf(host, bypass), + 'expected bypass of %s to be False' % host) + + # Check the exclude_simple flag + bypass = {'exclude_simple': True, 'exceptions': []} + self.assertTrue(_proxy_bypass_macosx_sysconf('test', bypass)) + def test_basic_auth(self, quote_char='"'): opener = OpenerDirector() password_manager = MockPasswordManager() |
