From 26d855c87ee02d149ed873db08eabd84082e669d Mon Sep 17 00:00:00 2001 From: Sloane Hertel <19572925+s-hertel@users.noreply.github.com> Date: Thu, 20 Jul 2023 16:15:13 -0400 Subject: [PATCH] update ansible-galaxy testserver to use SSLContext.load_cert_chain (#80961) * update ansible-galaxy testserver to use SSLContext.load_cert_chain for Python 3.12 compatibility --- .../ansible-galaxy/files/testserver.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/test/integration/targets/ansible-galaxy/files/testserver.py b/test/integration/targets/ansible-galaxy/files/testserver.py index 135985075ab..8cca6a83998 100644 --- a/test/integration/targets/ansible-galaxy/files/testserver.py +++ b/test/integration/targets/ansible-galaxy/files/testserver.py @@ -1,20 +1,15 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import sys +import http.server +import socketserver import ssl if __name__ == '__main__': - if sys.version_info[0] >= 3: - import http.server - import socketserver - Handler = http.server.SimpleHTTPRequestHandler - httpd = socketserver.TCPServer(("", 4443), Handler) - else: - import BaseHTTPServer - import SimpleHTTPServer - Handler = SimpleHTTPServer.SimpleHTTPRequestHandler - httpd = BaseHTTPServer.HTTPServer(("", 4443), Handler) + Handler = http.server.SimpleHTTPRequestHandler + context = ssl.SSLContext() + context.load_cert_chain(certfile='./cert.pem', keyfile='./key.pem') + httpd = socketserver.TCPServer(("", 4443), Handler) + httpd.socket = context.wrap_socket(httpd.socket, server_side=True) - httpd.socket = ssl.wrap_socket(httpd.socket, certfile='./cert.pem', keyfile='./key.pem', server_side=True) httpd.serve_forever()