mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
[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 commite57ecf6bbc
) Python 3.12 backport: update also `test_nntplib`. (cherry picked from commitc2d542b42c
) Co-authored-by: Nikita Sobolev <mail@sobolevn.me> Co-authored-by: T. Wouters <thomas@python.org>
This commit is contained in:
parent
4b67878daa
commit
28c6cc1928
42 changed files with 32 additions and 29 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -43,21 +43,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',),
|
||||
|
|
|
@ -327,8 +327,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."""
|
||||
|
|
|
@ -23,11 +23,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 = (
|
||||
|
|
|
@ -26,8 +26,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):
|
||||
|
|
|
@ -2075,7 +2075,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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -32,8 +32,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')
|
||||
|
||||
|
|
|
@ -63,10 +63,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.
|
||||
|
||||
|
@ -675,7 +675,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):
|
||||
|
@ -3557,12 +3557,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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1947,7 +1947,8 @@ TESTSUBDIRS= ctypes/test \
|
|||
lib2to3/tests/data/fixers/myfixes \
|
||||
test \
|
||||
test/audiodata \
|
||||
test/capath \
|
||||
test/certdata \
|
||||
test/certdata/capath \
|
||||
test/cjkencodings \
|
||||
test/crashers \
|
||||
test/data \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue