Skip to content

Commit dea14f3

Browse files
committed
gh-158907: Shorten the handler comment and drop the tunnel test
A CONNECT 407 never reaches http_error_407, and the tunnel test passed without this change.
1 parent 5780387 commit dea14f3

2 files changed

Lines changed: 1 addition & 31 deletions

File tree

‎Lib/test/test_urllib2.py‎

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,33 +1756,6 @@ def test_proxy_basic_auth_ignores_direct_407(self):
17561756
self.assertFalse(
17571757
http_handler.requests[0].has_header("Proxy-authorization"))
17581758

1759-
def test_proxy_basic_auth_https_tunnel_still_authenticates(self):
1760-
# 407 from the proxy during an HTTPS tunnel must still be answered.
1761-
class MockHTTPSHandlerRedirect(MockHTTPHandlerRedirect):
1762-
def https_open(self, req):
1763-
return self.http_open(req)
1764-
1765-
opener = OpenerDirector()
1766-
opener.add_handler(urllib.request.ProxyHandler(
1767-
dict(https="proxy.example.com:3128")))
1768-
password_manager = urllib.request.HTTPPasswordMgr()
1769-
auth_handler = urllib.request.ProxyBasicAuthHandler(password_manager)
1770-
realm = "ACME Networks"
1771-
http_handler = MockHTTPSHandlerRedirect(
1772-
407, 'Proxy-Authenticate: Basic realm="%s"\r\n\r\n' % realm)
1773-
opener.add_handler(auth_handler)
1774-
opener.add_handler(http_handler)
1775-
1776-
password_manager.add_password(
1777-
realm, "proxy.example.com:3128", "wile", "coyote")
1778-
opener.open("https://acme.example.com/protected")
1779-
1780-
self.assertEqual(len(http_handler.requests), 2)
1781-
self.assertFalse(
1782-
http_handler.requests[0].has_header("Proxy-authorization"))
1783-
self.assertTrue(
1784-
http_handler.requests[1].has_header("Proxy-authorization"))
1785-
17861759
def test_basic_and_digest_auth_handlers(self):
17871760
# HTTPDigestAuthHandler raised an exception if it couldn't handle a 40*
17881761
# response (https://bugs.python.org/issue1479302), where it should instead

‎Lib/urllib/request.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,10 +1048,7 @@ class ProxyBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler):
10481048
auth_header = 'Proxy-authorization'
10491049

10501050
def http_error_407(self, req, fp, code, msg, headers):
1051-
# A direct origin is not a proxy. req.host has no scheme, so a
1052-
# password stored for https://HOST/ would match and be sent in
1053-
# cleartext on the retry (gh-158907). HTTPS tunnels set
1054-
# _tunnel_host instead of making has_proxy() true.
1051+
# gh-158907: a 407 from a direct origin is not a proxy challenge
10551052
if not req.has_proxy() and not req._tunnel_host:
10561053
return None
10571054
# http_error_auth_reqed requires that there is no userinfo component in

0 commit comments

Comments
 (0)