summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-11-11 00:27:33 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-11-11 00:27:33 (GMT)
commit73e9bd4d259c3c213347e45d4bb5bf20fb51c7f4 (patch)
tree881f1d149dd48c3ec278834efd0e7d6f08212d8e /Lib/test
parent6d9388faab63343db47e59eb28c926bc3cbe75d1 (diff)
parent5c89b4ec55bc7ebe799da296e01544a5bcdc4250 (diff)
downloadcpython-73e9bd4d259c3c213347e45d4bb5bf20fb51c7f4.zip
cpython-73e9bd4d259c3c213347e45d4bb5bf20fb51c7f4.tar.gz
cpython-73e9bd4d259c3c213347e45d4bb5bf20fb51c7f4.tar.bz2
Issue #16357: fix calling accept() on a SSLSocket created through SSLContext.wrap_socket().
Original patch by Jeff McNeil.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_ssl.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
index 4ce98b6..74abbd2 100644
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -1796,6 +1796,42 @@ else:
t.join()
server.close()
+ def test_server_accept(self):
+ # Issue #16357: accept() on a SSLSocket created through
+ # SSLContext.wrap_socket().
+ context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
+ context.verify_mode = ssl.CERT_REQUIRED
+ context.load_verify_locations(CERTFILE)
+ context.load_cert_chain(CERTFILE)
+ server = socket.socket(socket.AF_INET)
+ host = "127.0.0.1"
+ port = support.bind_port(server)
+ server = context.wrap_socket(server, server_side=True)
+
+ evt = threading.Event()
+ remote = None
+ peer = None
+ def serve():
+ nonlocal remote, peer
+ server.listen(5)
+ # Block on the accept and wait on the connection to close.
+ evt.set()
+ remote, peer = server.accept()
+ remote.recv(1)
+
+ t = threading.Thread(target=serve)
+ t.start()
+ # Client wait until server setup and perform a connect.
+ evt.wait()
+ client = context.wrap_socket(socket.socket())
+ client.connect((host, port))
+ client_addr = client.getsockname()
+ client.close()
+ t.join()
+ # Sanity checks.
+ self.assertIsInstance(remote, ssl.SSLSocket)
+ self.assertEqual(peer, client_addr)
+
def test_default_ciphers(self):
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
try: