diff options
author | Damien George <damien@micropython.org> | 2023-12-12 17:17:22 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2023-12-12 21:22:10 +1100 |
commit | bba8a673d5ed6ad4404502c32dac003ad9d59bde (patch) | |
tree | 258d603836d05811b328bade1d99c81fb34af9d8 /tests/net_inet/tls_text_errors.py | |
parent | ef996d15b9cbadee591a185f27fb16e90a5d4f5d (diff) |
tests: Update SSL network tests to use SSLContext, and work on CPython.
Changes are:
- use ssl.SSLContext.wrap_socket instead of ssl.wrap_socket
- disable check_hostname and call load_default_certs() where appropriate,
to get CPython to run the tests correctly
- pass socket.AF_INET to getaddrinfo and socket.socket(), to force IPv4
- change tests to use github.com instead of google.com, because certificate
validation was failing with google.com
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tests/net_inet/tls_text_errors.py')
-rw-r--r-- | tests/net_inet/tls_text_errors.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/tests/net_inet/tls_text_errors.py b/tests/net_inet/tls_text_errors.py index 498593bba..034cc8d36 100644 --- a/tests/net_inet/tls_text_errors.py +++ b/tests/net_inet/tls_text_errors.py @@ -1,13 +1,17 @@ # test that modtls produces a text error message -import socket, ssl, sys +import socket, ssl def test(addr): s = socket.socket() s.connect(addr) try: - s = ssl.wrap_socket(s) + ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) + if hasattr(ssl_context, "check_hostname"): + # Disable hostname check on CPython. + ssl_context.check_hostname = False + s = ssl_context.wrap_socket(s) print("wrap: no exception") except OSError as e: # mbedtls produces "mbedtls -0x7200: SSL - An invalid SSL record was received" |