]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-108303: Move all certificates to `Lib/test/certdata/` (GH-109489) (#109682)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 10 Oct 2023 20:38:18 +0000 (22:38 +0200)
committerGitHub <noreply@github.com>
Tue, 10 Oct 2023 20:38:18 +0000 (22:38 +0200)
* gh-108303: Move all certificates to `Lib/test/certdata/` (GH-109489)
(cherry picked from commit e57ecf6bbc59f999d27b125ea51b042c24a07bd9)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Python 3.12 backport: update also `test_nntplib`.

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: T. Wouters <thomas@python.org>
42 files changed:
Lib/test/certdata/allsans.pem [moved from Lib/test/allsans.pem with 100% similarity]
Lib/test/certdata/badcert.pem [moved from Lib/test/badcert.pem with 100% similarity]
Lib/test/certdata/badkey.pem [moved from Lib/test/badkey.pem with 100% similarity]
Lib/test/certdata/capath/4e1295a3.0 [moved from Lib/test/capath/4e1295a3.0 with 100% similarity]
Lib/test/certdata/capath/5ed36f99.0 [moved from Lib/test/capath/5ed36f99.0 with 100% similarity]
Lib/test/certdata/capath/6e88d7b8.0 [moved from Lib/test/capath/6e88d7b8.0 with 100% similarity]
Lib/test/certdata/capath/99d0fa06.0 [moved from Lib/test/capath/99d0fa06.0 with 100% similarity]
Lib/test/certdata/capath/b1930218.0 [moved from Lib/test/capath/b1930218.0 with 100% similarity]
Lib/test/certdata/capath/ceff1710.0 [moved from Lib/test/capath/ceff1710.0 with 100% similarity]
Lib/test/certdata/ffdh3072.pem [moved from Lib/test/ffdh3072.pem with 100% similarity]
Lib/test/certdata/idnsans.pem [moved from Lib/test/idnsans.pem with 100% similarity]
Lib/test/certdata/keycert.passwd.pem [moved from Lib/test/keycert.passwd.pem with 100% similarity]
Lib/test/certdata/keycert.pem [moved from Lib/test/keycert.pem with 100% similarity]
Lib/test/certdata/keycert2.pem [moved from Lib/test/keycert2.pem with 100% similarity]
Lib/test/certdata/keycert3.pem [moved from Lib/test/keycert3.pem with 100% similarity]
Lib/test/certdata/keycert4.pem [moved from Lib/test/keycert4.pem with 100% similarity]
Lib/test/certdata/keycertecc.pem [moved from Lib/test/keycertecc.pem with 100% similarity]
Lib/test/certdata/make_ssl_certs.py [moved from Lib/test/make_ssl_certs.py with 100% similarity]
Lib/test/certdata/nokia.pem [moved from Lib/test/nokia.pem with 100% similarity]
Lib/test/certdata/nosan.pem [moved from Lib/test/nosan.pem with 100% similarity]
Lib/test/certdata/nullbytecert.pem [moved from Lib/test/nullbytecert.pem with 100% similarity]
Lib/test/certdata/nullcert.pem [moved from Lib/test/nullcert.pem with 100% similarity]
Lib/test/certdata/pycacert.pem [moved from Lib/test/pycacert.pem with 100% similarity]
Lib/test/certdata/pycakey.pem [moved from Lib/test/pycakey.pem with 100% similarity]
Lib/test/certdata/revocation.crl [moved from Lib/test/revocation.crl with 100% similarity]
Lib/test/certdata/secp384r1.pem [moved from Lib/test/secp384r1.pem with 100% similarity]
Lib/test/certdata/selfsigned_pythontestdotnet.pem [moved from Lib/test/selfsigned_pythontestdotnet.pem with 100% similarity]
Lib/test/certdata/ssl_cert.pem [moved from Lib/test/ssl_cert.pem with 100% similarity]
Lib/test/certdata/ssl_key.passwd.pem [moved from Lib/test/ssl_key.passwd.pem with 100% similarity]
Lib/test/certdata/ssl_key.pem [moved from Lib/test/ssl_key.pem with 100% similarity]
Lib/test/certdata/talos-2019-0758.pem [moved from Lib/test/talos-2019-0758.pem with 100% similarity]
Lib/test/ssl_servers.py
Lib/test/test_asyncio/utils.py
Lib/test/test_ftplib.py
Lib/test/test_httplib.py
Lib/test/test_imaplib.py
Lib/test/test_logging.py
Lib/test/test_nntplib.py
Lib/test/test_poplib.py
Lib/test/test_ssl.py
Lib/test/test_urllib2_localnet.py
Makefile.pre.in

index a4bd7455d47e76dab1b692dc1e3c491ac2409d89..15b071e04dda1f33629bf7ed6186dc46847cb15c 100644 (file)
@@ -14,7 +14,7 @@ from test.support import socket_helper
 here = os.path.dirname(__file__)
 
 HOST = socket_helper.HOST
-CERTFILE = os.path.join(here, 'keycert.pem')
+CERTFILE = os.path.join(here, 'certdata', 'keycert.pem')
 
 # This one's based on HTTPServer, which is based on socketserver
 
index 870f6fcfc02d30b43575637bd6729ad27b9b7380..71391dd8603a6666ef871f0c4a23c06c0830970b 100644 (file)
@@ -42,21 +42,21 @@ from test.support import threading_helper
 CLOCK_RES = 0.020
 
 
-def data_file(filename):
+def data_file(*filename):
     if hasattr(support, 'TEST_HOME_DIR'):
-        fullname = os.path.join(support.TEST_HOME_DIR, filename)
+        fullname = os.path.join(support.TEST_HOME_DIR, *filename)
         if os.path.isfile(fullname):
             return fullname
-    fullname = os.path.join(os.path.dirname(__file__), '..', filename)
+    fullname = os.path.join(os.path.dirname(__file__), '..', *filename)
     if os.path.isfile(fullname):
         return fullname
-    raise FileNotFoundError(filename)
+    raise FileNotFoundError(os.path.join(filename))
 
 
-ONLYCERT = data_file('ssl_cert.pem')
-ONLYKEY = data_file('ssl_key.pem')
-SIGNED_CERTFILE = data_file('keycert3.pem')
-SIGNING_CA = data_file('pycacert.pem')
+ONLYCERT = data_file('certdata', 'ssl_cert.pem')
+ONLYKEY = data_file('certdata', 'ssl_key.pem')
+SIGNED_CERTFILE = data_file('certdata', 'keycert3.pem')
+SIGNING_CA = data_file('certdata', 'pycacert.pem')
 PEERCERT = {
     'OCSP': ('http://testca.pythontest.net/testca/ocsp/',),
     'caIssuers': ('http://testca.pythontest.net/testca/pycacert.cer',),
index 1ca94393d8569fe0bd347cb706536a5156bd423e..2f191ea7a44c1615123fe2db30f2fb78b0000f8d 100644 (file)
@@ -325,8 +325,8 @@ class DummyFTPServer(asyncore.dispatcher, threading.Thread):
 
 if ssl is not None:
 
-    CERTFILE = os.path.join(os.path.dirname(__file__), "keycert3.pem")
-    CAFILE = os.path.join(os.path.dirname(__file__), "pycacert.pem")
+    CERTFILE = os.path.join(os.path.dirname(__file__), "certdata", "keycert3.pem")
+    CAFILE = os.path.join(os.path.dirname(__file__), "certdata", "pycacert.pem")
 
     class SSLConnection(asyncore.dispatcher):
         """An asyncore.dispatcher subclass supporting TLS/SSL."""
index 676725c46ec694153c0d43b8d907daa74084ec0d..5d5832b62b2f9438e52b0cc983d3524a9d781e7d 100644 (file)
@@ -21,11 +21,13 @@ support.requires_working_socket(module=True)
 
 here = os.path.dirname(__file__)
 # Self-signed cert file for 'localhost'
-CERT_localhost = os.path.join(here, 'keycert.pem')
+CERT_localhost = os.path.join(here, 'certdata', 'keycert.pem')
 # Self-signed cert file for 'fakehostname'
-CERT_fakehostname = os.path.join(here, 'keycert2.pem')
+CERT_fakehostname = os.path.join(here, 'certdata', 'keycert2.pem')
 # Self-signed cert file for self-signed.pythontest.net
-CERT_selfsigned_pythontestdotnet = os.path.join(here, 'selfsigned_pythontestdotnet.pem')
+CERT_selfsigned_pythontestdotnet = os.path.join(
+    here, 'certdata', 'selfsigned_pythontestdotnet.pem',
+)
 
 # constants for testing chunked encoding
 chunked_start = (
index 4b38355c37b329e29e769eefa0b999a2e6826737..def9f45d63789b5e918e659773f92f9766cfcd23 100644 (file)
@@ -23,8 +23,8 @@ except ImportError:
 
 support.requires_working_socket(module=True)
 
-CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "keycert3.pem")
-CAFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "pycacert.pem")
+CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "certdata", "keycert3.pem")
+CAFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "certdata", "pycacert.pem")
 
 
 class TestImaplib(unittest.TestCase):
index b7f4c6edf106144aef38c21fcff4f2f4e9c745a1..d2daf93c523f8c9160f78503c92ecc5ba532a16c 100644 (file)
@@ -2170,7 +2170,7 @@ class HTTPHandlerTest(BaseTest):
                     sslctx = None
                 else:
                     here = os.path.dirname(__file__)
-                    localhost_cert = os.path.join(here, "keycert.pem")
+                    localhost_cert = os.path.join(here, "certdata", "keycert.pem")
                     sslctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
                     sslctx.load_cert_chain(localhost_cert)
 
index 31a02f86abb003138ad58931cc4c7d99b27d9449..30ae557978308c4935e32364ed52473ae893c6b8 100644 (file)
@@ -20,7 +20,7 @@ except ImportError:
     ssl = None
 
 
-certfile = os.path.join(os.path.dirname(__file__), 'keycert3.pem')
+certfile = os.path.join(os.path.dirname(__file__), 'certdata', 'keycert3.pem')
 
 if ssl is not None:
     SSLError = ssl.SSLError
index fa41ba0b6e46376b037fddaa583f296a85760522..869f9431b928bb6bdc16e74f8700bc59a42836ee 100644 (file)
@@ -29,8 +29,8 @@ if hasattr(poplib, 'POP3_SSL'):
     import ssl
 
     SUPPORTS_SSL = True
-    CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "keycert3.pem")
-    CAFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "pycacert.pem")
+    CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "certdata", "keycert3.pem")
+    CAFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "certdata", "pycacert.pem")
 
 requires_ssl = skipUnless(SUPPORTS_SSL, 'SSL not supported')
 
index 2c32fec5104c2348d660e5f71f89a614c59d554a..06304dcb4ec7b853fc6f35c61c7e51679abee7f1 100644 (file)
@@ -60,10 +60,10 @@ for proto, ver in (
     PROTOCOL_TO_TLS_VERSION[proto] = ver
 
 def data_file(*name):
-    return os.path.join(os.path.dirname(__file__), *name)
+    return os.path.join(os.path.dirname(__file__), "certdata", *name)
 
 # The custom key and certificate files used in test_ssl are generated
-# using Lib/test/make_ssl_certs.py.
+# using Lib/test/certdata/make_ssl_certs.py.
 # Other certificates are simply fetched from the internet servers they
 # are meant to authenticate.
 
@@ -641,7 +641,7 @@ class BasicSocketTests(unittest.TestCase):
     def bad_cert_test(self, certfile):
         """Check that trying to use the given client certificate fails"""
         certfile = os.path.join(os.path.dirname(__file__) or os.curdir,
-                                   certfile)
+                                "certdata", certfile)
         sock = socket.socket()
         self.addCleanup(sock.close)
         with self.assertRaises(ssl.SSLError):
@@ -3309,12 +3309,12 @@ class ThreadedTests(unittest.TestCase):
         # try to connect
         if support.verbose:
             sys.stdout.write('\n')
-        with open(CERTFILE, 'rb') as f:
+        # Get this test file itself:
+        with open(__file__, 'rb') as f:
             d1 = f.read()
         d2 = ''
         # now fetch the same data from the HTTPS server
-        url = 'https://localhost:%d/%s' % (
-            server.port, os.path.split(CERTFILE)[1])
+        url = f'https://localhost:{server.port}/test_ssl.py'
         context = ssl.create_default_context(cafile=SIGNING_CA)
         f = urllib.request.urlopen(url, context=context)
         try:
index f4729358557c952eb2f42262b33c777894232c83..96e43970d49fb92cf8c05752e8bd545701ab2f1f 100644 (file)
@@ -22,9 +22,9 @@ support.requires_working_socket(module=True)
 
 here = os.path.dirname(__file__)
 # Self-signed cert file for 'localhost'
-CERT_localhost = os.path.join(here, 'keycert.pem')
+CERT_localhost = os.path.join(here, 'certdata', 'keycert.pem')
 # Self-signed cert file for 'fakehostname'
-CERT_fakehostname = os.path.join(here, 'keycert2.pem')
+CERT_fakehostname = os.path.join(here, 'certdata', 'keycert2.pem')
 
 
 # Loopback http server infrastructure
index f3c2d8bf260de2f8598bd6f8f7861421c160dfd3..aa2ac012affc1857911fd72bfffec2d9446463b6 100644 (file)
@@ -2117,7 +2117,8 @@ LIBSUBDIRS=       asyncio \
 TESTSUBDIRS=   idlelib/idle_test \
                test \
                test/audiodata \
-               test/capath \
+               test/certdata \
+               test/certdata/capath \
                test/cjkencodings \
                test/crashers \
                test/data \