diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-04-24 20:04:58 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-04-24 20:04:58 (GMT) |
commit | fc69af15629389801db4da64ac06b0a0e747e60a (patch) | |
tree | d2144b94112f150a0df14985241d73227ea955e2 /Lib/test/test_poplib.py | |
parent | 4d3e372ff3f611aa76458a48f26ec4701315c128 (diff) | |
download | cpython-fc69af15629389801db4da64ac06b0a0e747e60a.zip cpython-fc69af15629389801db4da64ac06b0a0e747e60a.tar.gz cpython-fc69af15629389801db4da64ac06b0a0e747e60a.tar.bz2 |
Issue #5103: SSL handshake would ignore the socket timeout and block
indefinitely if the other end didn't respond.
Diffstat (limited to 'Lib/test/test_poplib.py')
-rw-r--r-- | Lib/test/test_poplib.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/Lib/test/test_poplib.py b/Lib/test/test_poplib.py index 345a1c75..f75f0b1 100644 --- a/Lib/test/test_poplib.py +++ b/Lib/test/test_poplib.py @@ -10,6 +10,7 @@ import asynchat import socket import os import time +import errno from unittest import TestCase from test import test_support @@ -231,11 +232,37 @@ if hasattr(poplib, 'POP3_SSL'): def __init__(self, conn): asynchat.async_chat.__init__(self, conn) self.socket = ssl.wrap_socket(self.socket, certfile=CERTFILE, - server_side=True) + server_side=True, + do_handshake_on_connect=False) + # Must try handshake before calling push() + self._ssl_accepting = True + self._do_ssl_handshake() self.set_terminator("\r\n") self.in_buffer = [] self.push('+OK dummy pop3 server ready.') + def _do_ssl_handshake(self): + try: + self.socket.do_handshake() + except ssl.SSLError, err: + if err.args[0] in (ssl.SSL_ERROR_WANT_READ, + ssl.SSL_ERROR_WANT_WRITE): + return + elif err.args[0] == ssl.SSL_ERROR_EOF: + return self.handle_close() + raise + except socket.error, err: + if err.args[0] == errno.ECONNABORTED: + return self.handle_close() + else: + self._ssl_accepting = False + + def handle_read(self): + if self._ssl_accepting: + self._do_ssl_handshake() + else: + DummyPOP3Handler.handle_read(self) + class TestPOP3_SSLClass(TestPOP3Class): # repeat previous tests by using poplib.POP3_SSL |