diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-04-24 22:04:40 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-04-24 22:04:40 (GMT) |
commit | 40f0874b5556b278526ee9443b83efa2a6f723ca (patch) | |
tree | 24f90858038b2aac9c83f9145de32d5b4730f80d /Lib | |
parent | d3f8ab8bd37d942d64773e9043697003b8502049 (diff) | |
download | cpython-40f0874b5556b278526ee9443b83efa2a6f723ca.zip cpython-40f0874b5556b278526ee9443b83efa2a6f723ca.tar.gz cpython-40f0874b5556b278526ee9443b83efa2a6f723ca.tar.bz2 |
Issue #8524: When creating an SSL socket, the timeout value of the
original socket wasn't retained (instead, a socket with a positive timeout
would be turned into a non-blocking SSL socket).
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/ssl.py | 1 | ||||
-rw-r--r-- | Lib/test/test_ssl.py | 29 |
2 files changed, 19 insertions, 11 deletions
@@ -102,6 +102,7 @@ class SSLSocket(socket): type=sock.type, proto=sock.proto, fileno=_dup(sock.fileno())) + self.settimeout(sock.gettimeout()) sock.close() elif fileno is not None: socket.__init__(self, fileno=fileno) diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py index bd2aed5..3c03b59 100644 --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -151,6 +151,15 @@ class BasicTests(unittest.TestCase): del ss self.assertEqual(wr(), None) + def test_timeout(self): + # Issue #8524: when creating an SSL socket, the timeout of the + # original socket should be retained. + for timeout in (None, 0.0, 5.0): + s = socket.socket(socket.AF_INET) + s.settimeout(timeout) + ss = ssl.wrap_socket(s) + self.assertEqual(timeout, ss.gettimeout()) + class NetworkedTests(unittest.TestCase): @@ -1306,17 +1315,15 @@ else: started.wait() try: - if 0: - # Disabled until #8524 finds a solution - try: - c = socket.socket(socket.AF_INET) - c.settimeout(1.0) - c.connect((host, port)) - # Will attempt handshake and time out - self.assertRaisesRegexp(ssl.SSLError, "timed out", - ssl.wrap_socket, c) - finally: - c.close() + try: + c = socket.socket(socket.AF_INET) + c.settimeout(0.2) + c.connect((host, port)) + # Will attempt handshake and time out + self.assertRaisesRegexp(ssl.SSLError, "timed out", + ssl.wrap_socket, c) + finally: + c.close() try: c = socket.socket(socket.AF_INET) c = ssl.wrap_socket(c) |