Skip to content

Commit 02250e5

Browse files
authored
bpo-35352: test_asyncio uses the certificate set from the test directory (GH-10826) (GH-10832)
Modify asyncio tests to utilize the certificates from the test directory instead of its own set, as they are the same and with each update they had to be updated as well. (cherry picked from commit b062ba7)
1 parent 03b1200 commit 02250e5

7 files changed

Lines changed: 21 additions & 203 deletions

File tree

Lib/asyncio/test_utils.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@
4242
from socket import socketpair # pragma: no cover
4343

4444

45+
def data_file(filename):
46+
if hasattr(support, 'TEST_HOME_DIR'):
47+
fullname = os.path.join(support.TEST_HOME_DIR, filename)
48+
if os.path.isfile(fullname):
49+
return fullname
50+
fullname = os.path.join(os.path.dirname(os.__file__), 'test', filename)
51+
if os.path.isfile(fullname):
52+
return fullname
53+
raise FileNotFoundError(filename)
54+
55+
56+
ONLYCERT = data_file('ssl_cert.pem')
57+
ONLYKEY = data_file('ssl_key.pem')
58+
59+
4560
def dummy_ssl_context():
4661
if ssl is None:
4762
return None
@@ -114,12 +129,8 @@ def finish_request(self, request, client_address):
114129
# contains the ssl key and certificate files) differs
115130
# between the stdlib and stand-alone asyncio.
116131
# Prefer our own if we can find it.
117-
here = os.path.join(os.path.dirname(__file__), '..', 'tests')
118-
if not os.path.isdir(here):
119-
here = os.path.join(os.path.dirname(os.__file__),
120-
'test', 'test_asyncio')
121-
keyfile = os.path.join(here, 'ssl_key.pem')
122-
certfile = os.path.join(here, 'ssl_cert.pem')
132+
keyfile = ONLYKEY
133+
certfile = ONLYCERT
123134
context = ssl.SSLContext()
124135
context.load_cert_chain(certfile, keyfile)
125136

Lib/test/test_asyncio/keycert3.pem

Lines changed: 0 additions & 73 deletions
This file was deleted.

Lib/test/test_asyncio/pycacert.pem

Lines changed: 0 additions & 78 deletions
This file was deleted.

Lib/test/test_asyncio/ssl_cert.pem

Lines changed: 0 additions & 15 deletions
This file was deleted.

Lib/test/test_asyncio/ssl_key.pem

Lines changed: 0 additions & 16 deletions
This file was deleted.

Lib/test/test_asyncio/test_events.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,13 @@
3232
from asyncio import selector_events
3333
from asyncio import sslproto
3434
from asyncio import test_utils
35+
from asyncio.test_utils import ONLYKEY, ONLYCERT, data_file
3536
try:
3637
from test import support
3738
except ImportError:
3839
from asyncio import test_support as support
3940

4041

41-
def data_file(filename):
42-
if hasattr(support, 'TEST_HOME_DIR'):
43-
fullname = os.path.join(support.TEST_HOME_DIR, filename)
44-
if os.path.isfile(fullname):
45-
return fullname
46-
fullname = os.path.join(os.path.dirname(__file__), filename)
47-
if os.path.isfile(fullname):
48-
return fullname
49-
raise FileNotFoundError(filename)
50-
51-
5242
def osx_tiger():
5343
"""Return True if the platform is Mac OS 10.4 or older."""
5444
if sys.platform != 'darwin':
@@ -67,10 +57,8 @@ async def doit():
6757
return loop.run_until_complete(doit())
6858

6959

70-
ONLYCERT = data_file('ssl_cert.pem')
71-
ONLYKEY = data_file('ssl_key.pem')
72-
SIGNED_CERTFILE = data_file('keycert3.pem')
73-
SIGNING_CA = data_file('pycacert.pem')
60+
SIGNED_CERTFILE = test_utils.data_file('keycert3.pem')
61+
SIGNING_CA = test_utils.data_file('pycacert.pem')
7462
PEERCERT = {
7563
'OCSP': ('http://testca.pythontest.net/testca/ocsp/',),
7664
'caIssuers': ('http://testca.pythontest.net/testca/pycacert.cer',),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Modify test_asyncio to use the certificate set from the test directory.

0 commit comments

Comments
 (0)