summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2012-05-15 16:03:29 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2012-05-15 16:03:29 (GMT)
commit92a5bf0c0aae607da90bb08a01b7d06c4c8b45fe (patch)
tree17d1d7f72d6cb29dd1bb668f9f4ec6295258b648
parentacfc26acb0dff670f68a59c82762e21e81cc7fb0 (diff)
parent0ea91cb5c6eac161722b3109ac636d5c782bf454 (diff)
downloadcpython-92a5bf0c0aae607da90bb08a01b7d06c4c8b45fe.zip
cpython-92a5bf0c0aae607da90bb08a01b7d06c4c8b45fe.tar.gz
cpython-92a5bf0c0aae607da90bb08a01b7d06c4c8b45fe.tar.bz2
Issue12541 - Add UserWarning for unquoted realms
-rw-r--r--Lib/test/test_urllib2.py11
-rw-r--r--Lib/urllib/request.py3
2 files changed, 9 insertions, 5 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index f9a76a3..b2cec7e 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -1261,11 +1261,12 @@ class HandlerTests(unittest.TestCase):
401, 'WWW-Authenticate: Basic realm=%s\r\n\r\n' % realm)
opener.add_handler(auth_handler)
opener.add_handler(http_handler)
- self._test_basic_auth(opener, auth_handler, "Authorization",
- realm, http_handler, password_manager,
- "http://acme.example.com/protected",
- "http://acme.example.com/protected",
- )
+ with self.assertWarns(UserWarning):
+ self._test_basic_auth(opener, auth_handler, "Authorization",
+ realm, http_handler, password_manager,
+ "http://acme.example.com/protected",
+ "http://acme.example.com/protected",
+ )
def test_proxy_basic_auth(self):
opener = OpenerDirector()
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index 6cc78ed..96bb8d7 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -934,6 +934,9 @@ class AbstractBasicAuthHandler:
mo = AbstractBasicAuthHandler.rx.search(authreq)
if mo:
scheme, quote, realm = mo.groups()
+ if quote not in ['"',"'"]:
+ warnings.warn("Basic Auth Realm was unquoted",
+ UserWarning, 2)
if scheme.lower() == 'basic':
response = self.retry_http_basic_auth(host, req, realm)
if response and response.code != 401: