Kaydet (Commit) 9a4414d7 authored tarafından Collin Winter's avatar Collin Winter

Merged revisions 72777 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r72777 | collin.winter | 2009-05-18 14:35:40 -0700 (Mon, 18 May 2009) | 1 line

  Issue 6032: fix refleaks in test_urllib2_localnet.
........
üst c384b226
...@@ -195,7 +195,11 @@ class FakeProxyHandler(http.server.BaseHTTPRequestHandler): ...@@ -195,7 +195,11 @@ class FakeProxyHandler(http.server.BaseHTTPRequestHandler):
testing. testing.
""" """
digest_auth_handler = DigestAuthHandler() def __init__(self, digest_auth_handler, *args, **kwargs):
# This has to be set before calling our parent's __init__(), which will
# try to call do_GET().
self.digest_auth_handler = digest_auth_handler
http.server.BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
def log_message(self, format, *args): def log_message(self, format, *args):
# Uncomment the next line for debugging. # Uncomment the next line for debugging.
...@@ -225,50 +229,51 @@ class ProxyAuthTests(unittest.TestCase): ...@@ -225,50 +229,51 @@ class ProxyAuthTests(unittest.TestCase):
REALM = "TestRealm" REALM = "TestRealm"
def setUp(self): def setUp(self):
FakeProxyHandler.digest_auth_handler.set_users({ self.digest_auth_handler = DigestAuthHandler()
self.USER : self.PASSWD self.digest_auth_handler.set_users({self.USER: self.PASSWD})
}) self.digest_auth_handler.set_realm(self.REALM)
FakeProxyHandler.digest_auth_handler.set_realm(self.REALM) def create_fake_proxy_handler(*args, **kwargs):
return FakeProxyHandler(self.digest_auth_handler, *args, **kwargs)
self.server = LoopbackHttpServerThread(FakeProxyHandler) self.server = LoopbackHttpServerThread(create_fake_proxy_handler)
self.server.start() self.server.start()
self.server.ready.wait() self.server.ready.wait()
proxy_url = "http://127.0.0.1:%d" % self.server.port proxy_url = "http://127.0.0.1:%d" % self.server.port
handler = urllib.request.ProxyHandler({"http" : proxy_url}) handler = urllib.request.ProxyHandler({"http" : proxy_url})
self._digest_auth_handler = urllib.request.ProxyDigestAuthHandler() self.proxy_digest_handler = urllib.request.ProxyDigestAuthHandler()
self.opener = urllib.request.build_opener( self.opener = urllib.request.build_opener(
handler, self._digest_auth_handler) handler, self.proxy_digest_handler)
def tearDown(self): def tearDown(self):
self.server.stop() self.server.stop()
def test_proxy_with_bad_password_raises_httperror(self): def test_proxy_with_bad_password_raises_httperror(self):
self._digest_auth_handler.add_password(self.REALM, self.URL, self.proxy_digest_handler.add_password(self.REALM, self.URL,
self.USER, self.PASSWD+"bad") self.USER, self.PASSWD+"bad")
FakeProxyHandler.digest_auth_handler.set_qop("auth") self.digest_auth_handler.set_qop("auth")
self.assertRaises(urllib.error.HTTPError, self.assertRaises(urllib.error.HTTPError,
self.opener.open, self.opener.open,
self.URL) self.URL)
def test_proxy_with_no_password_raises_httperror(self): def test_proxy_with_no_password_raises_httperror(self):
FakeProxyHandler.digest_auth_handler.set_qop("auth") self.digest_auth_handler.set_qop("auth")
self.assertRaises(urllib.error.HTTPError, self.assertRaises(urllib.error.HTTPError,
self.opener.open, self.opener.open,
self.URL) self.URL)
def test_proxy_qop_auth_works(self): def test_proxy_qop_auth_works(self):
self._digest_auth_handler.add_password(self.REALM, self.URL, self.proxy_digest_handler.add_password(self.REALM, self.URL,
self.USER, self.PASSWD) self.USER, self.PASSWD)
FakeProxyHandler.digest_auth_handler.set_qop("auth") self.digest_auth_handler.set_qop("auth")
result = self.opener.open(self.URL) result = self.opener.open(self.URL)
while result.read(): while result.read():
pass pass
result.close() result.close()
def test_proxy_qop_auth_int_works_or_throws_urlerror(self): def test_proxy_qop_auth_int_works_or_throws_urlerror(self):
self._digest_auth_handler.add_password(self.REALM, self.URL, self.proxy_digest_handler.add_password(self.REALM, self.URL,
self.USER, self.PASSWD) self.USER, self.PASSWD)
FakeProxyHandler.digest_auth_handler.set_qop("auth-int") self.digest_auth_handler.set_qop("auth-int")
try: try:
result = self.opener.open(self.URL) result = self.opener.open(self.URL)
except urllib.error.URLError: except urllib.error.URLError:
...@@ -474,8 +479,7 @@ class TestUrlopen(unittest.TestCase): ...@@ -474,8 +479,7 @@ class TestUrlopen(unittest.TestCase):
"http://sadflkjsasf.i.nvali.d/") "http://sadflkjsasf.i.nvali.d/")
def test_main(): def test_main():
support.run_unittest(ProxyAuthTests) support.run_unittest(ProxyAuthTests, TestUrlopen)
support.run_unittest(TestUrlopen)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()
...@@ -67,7 +67,7 @@ REFLOG="build/reflog.txt.out" ...@@ -67,7 +67,7 @@ REFLOG="build/reflog.txt.out"
# Note: test_XXX (none currently) really leak, but are disabled # Note: test_XXX (none currently) really leak, but are disabled
# so we don't send spam. Any test which really leaks should only # so we don't send spam. Any test which really leaks should only
# be listed here if there are also test cases under Lib/test/leakers. # be listed here if there are also test cases under Lib/test/leakers.
LEAKY_TESTS="test_(asynchat|cmd_line|docxmlrpc|dumbdbm|file|ftplib|httpservers|imaplib|popen2|socket|smtplib|sys|telnetlib|threadedtempfile|threading|threadsignals|urllib2_localnet|xmlrpc)" LEAKY_TESTS="test_(asynchat|cmd_line|docxmlrpc|dumbdbm|file|ftplib|httpservers|imaplib|popen2|socket|smtplib|sys|telnetlib|threadedtempfile|threading|threadsignals|xmlrpc)"
# These tests always fail, so skip them so we don't get false positives. # These tests always fail, so skip them so we don't get false positives.
_ALWAYS_SKIP="" _ALWAYS_SKIP=""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment