Skip to content

Commit 579f06a

Browse files
committed
add test for SSLKEYLOGFILE
1 parent aee21a5 commit 579f06a

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

pythonbuild/disttests/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,26 @@ def test_ssl(self):
217217

218218
ssl.create_default_context()
219219

220+
@unittest.skipIf(os.name != "nt", "Windows-specific OpenSSL uplink regression")
221+
def test_ssl_with_keylogfile(self):
222+
# Validate that a SSLContext can be created when SSLKEYLOGFILE is set
223+
# https://github.com/astral-sh/python-build-standalone/issues/640
224+
import ssl
225+
226+
with tempfile.TemporaryDirectory() as td:
227+
keylog_path = str(Path(td) / "sslkeylog.log")
228+
original_keylog_path = os.environ.get("SSLKEYLOGFILE")
229+
os.environ["SSLKEYLOGFILE"] = keylog_path
230+
try:
231+
context = ssl.create_default_context()
232+
self.assertEqual(context.keylog_filename, keylog_path)
233+
self.assertGreater(len(context.get_ciphers()), 0)
234+
finally:
235+
if original_keylog_path is None:
236+
os.environ.pop("SSLKEYLOGFILE", None)
237+
else:
238+
os.environ["SSLKEYLOGFILE"] = original_keylog_path
239+
220240
@unittest.skipIf(
221241
sys.version_info[:2] < (3, 13),
222242
"Free-threaded builds are only available in 3.13+",

0 commit comments

Comments
 (0)