circuitpython/tests/extmod/ssl_sslcontext.py
Damien George b50da3dbd7 tests/extmod: Add tests for ssl.SSLContext.
Signed-off-by: Damien George <damien@micropython.org>
2023-06-26 16:34:41 +10:00

26 lines
699 B
Python

# Very basic test of ssl.SSLContext class.
try:
import socket, ssl
except ImportError:
print("SKIP")
raise SystemExit
# Test constructing with arguments.
ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
# Test printing object.
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
print("SSLContext" in str(ctx))
# Coverage test for destructor, and calling it twice.
if hasattr(ctx, "__del__"):
ctx.__del__()
ctx.__del__()
# Test calling .wrap_socket() method, multiple times.
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ctx.wrap_socket(socket.socket(), do_handshake_on_connect=False)
ctx.wrap_socket(socket.socket(), do_handshake_on_connect=False)