Skip to content

Commit

Permalink
Update tests to be compatible with OpenSSL 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
1st1 committed May 27, 2018
1 parent 0238da4 commit bd17a55
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Lib/test/test_asyncio/test_sslproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import logging
import socket
import time
import unittest
from unittest import mock
Expand Down Expand Up @@ -252,6 +253,8 @@ def serve(sock):
sock.sendall(b'O')
data = sock.recv_all(len(HELLO_MSG))
self.assertEqual(len(data), len(HELLO_MSG))

sock.shutdown(socket.SHUT_RDWR)
sock.close()

class ClientProto(asyncio.Protocol):
Expand Down Expand Up @@ -310,6 +313,8 @@ def serve(sock):
sock.sendall(b'O')
data = sock.recv_all(len(HELLO_MSG))
self.assertEqual(len(data), len(HELLO_MSG))

sock.shutdown(socket.SHUT_RDWR)
sock.close()

class ClientProto(asyncio.BufferedProtocol):
Expand Down Expand Up @@ -361,8 +366,6 @@ def test_start_tls_server_1(self):

server_context = test_utils.simple_server_sslcontext()
client_context = test_utils.simple_client_sslcontext()
# TODO: fix TLSv1.3 support
client_context.options |= ssl.OP_NO_TLSv1_3

def client(sock, addr):
time.sleep(0.5)
Expand All @@ -374,12 +377,15 @@ def client(sock, addr):

sock.start_tls(client_context)
sock.sendall(HELLO_MSG)

sock.shutdown(socket.SHUT_RDWR)
sock.close()

class ServerProto(asyncio.Protocol):
def __init__(self, on_con, on_eof):
def __init__(self, on_con, on_eof, on_con_lost):
self.on_con = on_con
self.on_eof = on_eof
self.on_con_lost = on_con_lost
self.data = b''

def connection_made(self, tr):
Expand All @@ -391,6 +397,12 @@ def data_received(self, data):
def eof_received(self):
self.on_eof.set_result(1)

def connection_lost(self, exc):
if exc is None:
self.on_con_lost.set_result(None)
else:
self.on_con_lost.set_exception(exc)

async def main():
tr = await on_con
tr.write(HELLO_MSG)
Expand All @@ -402,6 +414,7 @@ async def main():
server_side=True)

await on_eof
await on_con_lost
self.assertEqual(proto.data, HELLO_MSG)
new_tr.close()

Expand All @@ -410,7 +423,8 @@ async def main():

on_con = self.loop.create_future()
on_eof = self.loop.create_future()
proto = ServerProto(on_con, on_eof)
on_con_lost = self.loop.create_future()
proto = ServerProto(on_con, on_eof, on_con_lost)

server = self.loop.run_until_complete(
self.loop.create_server(
Expand Down

0 comments on commit bd17a55

Please sign in to comment.