diff options
author | Senthil Kumaran <senthil@uthcode.com> | 2014-08-16 17:22:37 (GMT) |
---|---|---|
committer | Senthil Kumaran <senthil@uthcode.com> | 2014-08-16 17:22:37 (GMT) |
commit | 402df0975c1adacdc3673b9308ec759a557f6b4b (patch) | |
tree | d924a828f1a1e96b038f02071de5d2b5c4e48264 /Lib/test | |
parent | 7869a4e03aa8624bdb7636120819a06c84503e60 (diff) | |
download | cpython-402df0975c1adacdc3673b9308ec759a557f6b4b.zip cpython-402df0975c1adacdc3673b9308ec759a557f6b4b.tar.gz cpython-402df0975c1adacdc3673b9308ec759a557f6b4b.tar.bz2 |
backout changeset 3435c5865cfc due to buildbot failures. Ref #8797
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_urllib2_localnet.py | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py index f341cf7..b7513ee 100644 --- a/Lib/test/test_urllib2_localnet.py +++ b/Lib/test/test_urllib2_localnet.py @@ -1,4 +1,3 @@ -import base64 import os import email import urllib.parse @@ -198,48 +197,6 @@ class DigestAuthHandler: return self._return_auth_challenge(request_handler) return True - -class BasicAuthHandler(http.server.SimpleHTTPRequestHandler): - """Handler for performing basic authentication.""" - # Server side values - USER = 'testUser' - PASSWD = 'testPass' - REALM = 'Test' - USER_PASSWD = "%s:%s" % (USER, PASSWD) - ENCODED_AUTH = base64.b64encode(USER_PASSWD.encode('ascii')).decode('ascii') - - def __init__(self, *args, **kwargs): - http.server.SimpleHTTPRequestHandler.__init__(self, *args, **kwargs) - - def log_message(self, format, *args): - # Suppress console log message - pass - - def do_HEAD(self): - self.send_response(200) - self.send_header("Content-type", "text/html") - self.end_headers() - - def do_AUTHHEAD(self): - self.send_response(401) - self.send_header("WWW-Authenticate", "Basic realm=\"%s\"" % self.REALM) - self.send_header("Content-type", "text/html") - self.end_headers() - - def do_GET(self): - if not self.headers.get("Authorization", ""): - self.do_AUTHHEAD() - self.wfile.write(b"No Auth header received") - elif self.headers.get( - "Authorization", "") == "Basic " + self.ENCODED_AUTH: - http.server.SimpleHTTPRequestHandler.do_GET(self) - else: - self.do_AUTHHEAD() - self.wfile.write( - bytes(self.headers.get("Authorization", ""), "ascii")) - self.wfile.write(b"Not Authenticated") - - # Proxy test infrastructure class FakeProxyHandler(http.server.BaseHTTPRequestHandler): @@ -276,45 +233,6 @@ class FakeProxyHandler(http.server.BaseHTTPRequestHandler): # Test cases @unittest.skipUnless(threading, "Threading required for this test.") -class BasicAuthTests(unittest.TestCase): - USER = "testUser" - PASSWD = "testPass" - INCORRECT_PASSWD = "Incorrect" - REALM = "Test" - - def setUp(self): - super(BasicAuthTests, self).setUp() - # With Basic Authentication - def http_server_with_basic_auth_handler(*args, **kwargs): - return BasicAuthHandler(*args, **kwargs) - self.server = LoopbackHttpServerThread(http_server_with_basic_auth_handler) - self.server_url = 'http://127.0.0.1:%s' % self.server.port - self.server.start() - self.server.ready.wait() - - def tearDown(self): - self.server.stop() - super(BasicAuthTests, self).tearDown() - - def test_basic_auth_success(self): - ah = urllib.request.HTTPBasicAuthHandler() - ah.add_password(self.REALM, self.server_url, self.USER, self.PASSWD) - urllib.request.install_opener(urllib.request.build_opener(ah)) - try: - self.assertTrue(urllib.request.urlopen(self.server_url)) - except urllib.error.HTTPError: - self.fail("Basic auth failed for the url: %s", self.server_url) - except Exception as e: - raise e - - def test_basic_auth_httperror(self): - ah = urllib.request.HTTPBasicAuthHandler() - ah.add_password(self.REALM, self.server_url, self.USER, self.INCORRECT_PASSWD) - urllib.request.install_opener(urllib.request.build_opener(ah)) - self.assertRaises(urllib.error.HTTPError, urllib.request.urlopen, self.server_url) - - -@unittest.skipUnless(threading, "Threading required for this test.") class ProxyAuthTests(unittest.TestCase): URL = "http://localhost" @@ -327,7 +245,6 @@ class ProxyAuthTests(unittest.TestCase): self.digest_auth_handler = DigestAuthHandler() self.digest_auth_handler.set_users({self.USER: self.PASSWD}) self.digest_auth_handler.set_realm(self.REALM) - # With Digest Authentication. def create_fake_proxy_handler(*args, **kwargs): return FakeProxyHandler(self.digest_auth_handler, *args, **kwargs) |