Skip to content

Commit 28c6cc1

Browse files
miss-islingtonsobolevnYhg1s
authored
[3.11] [3.12] gh-108303: Move all certificates to Lib/test/certdata/ (GH-109489) (GH-109682) (#110646)
[3.12] gh-108303: Move all certificates to `Lib/test/certdata/` (GH-109489) (GH-109682) * gh-108303: Move all certificates to `Lib/test/certdata/` (GH-109489) (cherry picked from commit e57ecf6) Python 3.12 backport: update also `test_nntplib`. (cherry picked from commit c2d542b) Co-authored-by: Nikita Sobolev <[email protected]> Co-authored-by: T. Wouters <[email protected]>
1 parent 4b67878 commit 28c6cc1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+32
-29
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Lib/test/ssl_servers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
here = os.path.dirname(__file__)
1515

1616
HOST = socket_helper.HOST
17-
CERTFILE = os.path.join(here, 'keycert.pem')
17+
CERTFILE = os.path.join(here, 'certdata', 'keycert.pem')
1818

1919
# This one's based on HTTPServer, which is based on socketserver
2020

Lib/test/test_asyncio/utils.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,21 @@
4343
CLOCK_RES = 0.020
4444

4545

46-
def data_file(filename):
46+
def data_file(*filename):
4747
if hasattr(support, 'TEST_HOME_DIR'):
48-
fullname = os.path.join(support.TEST_HOME_DIR, filename)
48+
fullname = os.path.join(support.TEST_HOME_DIR, *filename)
4949
if os.path.isfile(fullname):
5050
return fullname
51-
fullname = os.path.join(os.path.dirname(__file__), '..', filename)
51+
fullname = os.path.join(os.path.dirname(__file__), '..', *filename)
5252
if os.path.isfile(fullname):
5353
return fullname
54-
raise FileNotFoundError(filename)
54+
raise FileNotFoundError(os.path.join(filename))
5555

5656

57-
ONLYCERT = data_file('ssl_cert.pem')
58-
ONLYKEY = data_file('ssl_key.pem')
59-
SIGNED_CERTFILE = data_file('keycert3.pem')
60-
SIGNING_CA = data_file('pycacert.pem')
57+
ONLYCERT = data_file('certdata', 'ssl_cert.pem')
58+
ONLYKEY = data_file('certdata', 'ssl_key.pem')
59+
SIGNED_CERTFILE = data_file('certdata', 'keycert3.pem')
60+
SIGNING_CA = data_file('certdata', 'pycacert.pem')
6161
PEERCERT = {
6262
'OCSP': ('http://testca.pythontest.net/testca/ocsp/',),
6363
'caIssuers': ('http://testca.pythontest.net/testca/pycacert.cer',),

Lib/test/test_ftplib.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,8 @@ def handle_error(self):
327327

328328
if ssl is not None:
329329

330-
CERTFILE = os.path.join(os.path.dirname(__file__), "keycert3.pem")
331-
CAFILE = os.path.join(os.path.dirname(__file__), "pycacert.pem")
330+
CERTFILE = os.path.join(os.path.dirname(__file__), "certdata", "keycert3.pem")
331+
CAFILE = os.path.join(os.path.dirname(__file__), "certdata", "pycacert.pem")
332332

333333
class SSLConnection(asyncore.dispatcher):
334334
"""An asyncore.dispatcher subclass supporting TLS/SSL."""

Lib/test/test_httplib.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323

2424
here = os.path.dirname(__file__)
2525
# Self-signed cert file for 'localhost'
26-
CERT_localhost = os.path.join(here, 'keycert.pem')
26+
CERT_localhost = os.path.join(here, 'certdata', 'keycert.pem')
2727
# Self-signed cert file for 'fakehostname'
28-
CERT_fakehostname = os.path.join(here, 'keycert2.pem')
28+
CERT_fakehostname = os.path.join(here, 'certdata', 'keycert2.pem')
2929
# Self-signed cert file for self-signed.pythontest.net
30-
CERT_selfsigned_pythontestdotnet = os.path.join(here, 'selfsigned_pythontestdotnet.pem')
30+
CERT_selfsigned_pythontestdotnet = os.path.join(
31+
here, 'certdata', 'selfsigned_pythontestdotnet.pem',
32+
)
3133

3234
# constants for testing chunked encoding
3335
chunked_start = (

Lib/test/test_imaplib.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
support.requires_working_socket(module=True)
2828

29-
CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "keycert3.pem")
30-
CAFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "pycacert.pem")
29+
CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "certdata", "keycert3.pem")
30+
CAFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "certdata", "pycacert.pem")
3131

3232

3333
class TestImaplib(unittest.TestCase):

Lib/test/test_logging.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2075,7 +2075,7 @@ def test_output(self):
20752075
sslctx = None
20762076
else:
20772077
here = os.path.dirname(__file__)
2078-
localhost_cert = os.path.join(here, "keycert.pem")
2078+
localhost_cert = os.path.join(here, "certdata", "keycert.pem")
20792079
sslctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
20802080
sslctx.load_cert_chain(localhost_cert)
20812081

Lib/test/test_nntplib.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
ssl = None
2121

2222

23-
certfile = os.path.join(os.path.dirname(__file__), 'keycert3.pem')
23+
certfile = os.path.join(os.path.dirname(__file__), 'certdata', 'keycert3.pem')
2424

2525
if ssl is not None:
2626
SSLError = ssl.SSLError

Lib/test/test_poplib.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
import ssl
3333

3434
SUPPORTS_SSL = True
35-
CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "keycert3.pem")
36-
CAFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "pycacert.pem")
35+
CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "certdata", "keycert3.pem")
36+
CAFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "certdata", "pycacert.pem")
3737

3838
requires_ssl = skipUnless(SUPPORTS_SSL, 'SSL not supported')
3939

Lib/test/test_ssl.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@
6363
PROTOCOL_TO_TLS_VERSION[proto] = ver
6464

6565
def data_file(*name):
66-
return os.path.join(os.path.dirname(__file__), *name)
66+
return os.path.join(os.path.dirname(__file__), "certdata", *name)
6767

6868
# The custom key and certificate files used in test_ssl are generated
69-
# using Lib/test/make_ssl_certs.py.
69+
# using Lib/test/certdata/make_ssl_certs.py.
7070
# Other certificates are simply fetched from the internet servers they
7171
# are meant to authenticate.
7272

@@ -675,7 +675,7 @@ def test_errors_sslwrap(self):
675675
def bad_cert_test(self, certfile):
676676
"""Check that trying to use the given client certificate fails"""
677677
certfile = os.path.join(os.path.dirname(__file__) or os.curdir,
678-
certfile)
678+
"certdata", certfile)
679679
sock = socket.socket()
680680
self.addCleanup(sock.close)
681681
with self.assertRaises(ssl.SSLError):
@@ -3557,12 +3557,12 @@ def test_socketserver(self):
35573557
# try to connect
35583558
if support.verbose:
35593559
sys.stdout.write('\n')
3560-
with open(CERTFILE, 'rb') as f:
3560+
# Get this test file itself:
3561+
with open(__file__, 'rb') as f:
35613562
d1 = f.read()
35623563
d2 = ''
35633564
# now fetch the same data from the HTTPS server
3564-
url = 'https://localhost:%d/%s' % (
3565-
server.port, os.path.split(CERTFILE)[1])
3565+
url = f'https://localhost:{server.port}/test_ssl.py'
35663566
context = ssl.create_default_context(cafile=SIGNING_CA)
35673567
f = urllib.request.urlopen(url, context=context)
35683568
try:

Lib/test/test_urllib2_localnet.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
here = os.path.dirname(__file__)
2424
# Self-signed cert file for 'localhost'
25-
CERT_localhost = os.path.join(here, 'keycert.pem')
25+
CERT_localhost = os.path.join(here, 'certdata', 'keycert.pem')
2626
# Self-signed cert file for 'fakehostname'
27-
CERT_fakehostname = os.path.join(here, 'keycert2.pem')
27+
CERT_fakehostname = os.path.join(here, 'certdata', 'keycert2.pem')
2828

2929

3030
# Loopback http server infrastructure

Makefile.pre.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -1947,7 +1947,8 @@ TESTSUBDIRS= ctypes/test \
19471947
lib2to3/tests/data/fixers/myfixes \
19481948
test \
19491949
test/audiodata \
1950-
test/capath \
1950+
test/certdata \
1951+
test/certdata/capath \
19511952
test/cjkencodings \
19521953
test/crashers \
19531954
test/data \

0 commit comments

Comments
 (0)